Compare commits

..

3 Commits

Author SHA1 Message Date
Jarvis
a2b11118e3 fix(fleet): always bake runtime-bin into pane PATH (ignore launcher PATH)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
The previous `_build_runtime_bin_prefix()` skipped candidate dirs that
were already present in the LAUNCHER process's \$PATH.  This is wrong:
the tmux pane inherits the tmux SERVER environment, not the launcher's
env.  A dir on the launcher's \$PATH may be absent from the server env,
so the prefix could come back empty and the pane would fail with
'command not found'.

Remove the `case ":${PATH}:"` check that tested against the live launcher
PATH.  Keep the existence check (`[ -d "$dir" ]`) and the dedup-within-
the-constructed-prefix guard.  The pane command's `export PATH="<prefix>:${PATH}"`
harmlessly absorbs any overlap with the server PATH.

Add test 5 to test-start-agent-session.sh: sets FAKE_RUNTIME_BIN5 on the
launcher's \$PATH and asserts it still appears in the generated pane PATH
export — directly guarding this regression.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RMoEx7hfdFGjUiCHuN1RRi
2026-06-21 12:13:20 -05:00
Jarvis
1908dab373 docs(fleet): record durable-launch findings + runtime-default policy
Some checks failed
ci/woodpecker/push/ci Pipeline was canceled
ci/woodpecker/pr/ci Pipeline was canceled
Correct the launch-path finding (PATH, not TTY), record the validated durable
real-agent recipe (pi on openai-codex/gpt-5.5), the Codex-default/Claude-reserved
policy, and the fleet-init boot-survival automation TODO.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RMoEx7hfdFGjUiCHuN1RRi
2026-06-21 12:08:39 -05:00
Jarvis
32efc13d99 fix(fleet): resolve runtime PATH for durable detached agent launch
Derive a runtime-bin PATH prefix (MOSAIC_RUNTIME_BIN override, then
npm-prefix/bin, then ~/.npm-global/bin / ~/.local/bin) and bake it
into the tmux pane command as `export PATH="<prefix>:${PATH}"; exec
<cmd>` so the runtime binary (mosaic/pi/codex) is always found in a
login+non-interactive pane shell that does not source ~/.bashrc.
Using `exec` makes the runtime the pane foreground process, eliminating
the DRIFT false-positive in `mosaic fleet ps`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RMoEx7hfdFGjUiCHuN1RRi
2026-06-21 12:05:09 -05:00
6 changed files with 22 additions and 251 deletions

View File

@@ -70,9 +70,6 @@ Skills, hooks, MCP, and plugins are force multipliers you MUST use when applicab
## Missing core file ## Missing core file
If `CONSTITUTION.md`, `AGENTS.md`, `SOUL.md`, or the runtime contract is missing, stop and report it. If `CONSTITUTION.md`, `AGENTS.md`, `SOUL.md`, or the runtime contract is missing, stop and report it.
This agent-facing strictness is intentional and stricter than the launcher: the launcher injects
`CONSTITUTION.md` tolerantly (skipping it if absent so pre-upgrade hosts keep working), but once a host
is re-seeded a genuinely missing core file is a stop-and-report condition — not something to proceed past.
## Session Closure ## Session Closure

View File

@@ -2,11 +2,8 @@
The irreducible, non-negotiable law for every Mosaic agent on every harness. The irreducible, non-negotiable law for every Mosaic agent on every harness.
**Framework-owned.** This file is overwritten verbatim on every upgrade — do not edit it. There is **Framework-owned.** This file is overwritten verbatim on every upgrade — do not edit it. To change
**no `CONSTITUTION.local.md`**: hard gates are not locally overridable. A lower layer may only make behavior, add a `.local.md` overlay or a `policy/` file (tighten-only; see `constitution/LAYER-MODEL.md`).
behavior _stricter_, never relax or override a gate (see Precedence). Operator customization lives in
other layers — `SOUL.md` / `USER.md` and the tighten-only overlays `STANDARDS.local.md` /
`SOUL.local.md` / `USER.local.md` / `policy/*.md` (see `constitution/LAYER-MODEL.md`).
Authored in **capability verbs**: where a gate names a capability ("structured reasoning", "queue Authored in **capability verbs**: where a gate names a capability ("structured reasoning", "queue
guard"), the runtime adapter binds it to a concrete tool and states whether absence is a hard stop. guard"), the runtime adapter binds it to a concrete tool and states whether absence is a hard stop.

View File

@@ -12,7 +12,7 @@
# 2. STRUCTURAL (private $HOME default in *.sh) — scanned everywhere EXCEPT examples/, # 2. STRUCTURAL (private $HOME default in *.sh) — scanned everywhere EXCEPT examples/,
# because worked example overlays/personas legitimately show placeholder paths. # because worked example overlays/personas legitimately show placeholder paths.
# #
# File types: *.md, *.sh, *.ps1, *.json, *.yml/*.yaml, *.toml, *.env, *.service, and the CLI scripts under # File types: *.md, *.sh, *.ps1, *.json, and the extensionless CLI scripts under
# tools/_scripts/. Excludes node_modules/ and this gate file. # tools/_scripts/. Excludes node_modules/ and this gate file.
# #
# NOTE: '\bPDA\b' intentionally matches "PDA-friendly" (the contamination removed in P2); # NOTE: '\bPDA\b' intentionally matches "PDA-friendly" (the contamination removed in P2);
@@ -39,7 +39,7 @@ cd "$FRAMEWORK_ROOT" || { echo "FRAMEWORK_ROOT not found: $FRAMEWORK_ROOT" >&2;
# Identity scope = ALL shipped text files (examples/ INCLUDED). # Identity scope = ALL shipped text files (examples/ INCLUDED).
_files_identity() { _files_identity() {
find . -type f \ find . -type f \
\( -name '*.md' -o -name '*.sh' -o -name '*.ps1' -o -name '*.json' -o -name '*.yml' -o -name '*.yaml' -o -name '*.toml' -o -name '*.env' -o -name '*.service' -o -path '*/tools/_scripts/*' \) \ \( -name '*.md' -o -name '*.sh' -o -name '*.ps1' -o -name '*.json' -o -path '*/tools/_scripts/*' \) \
-not -path '*/node_modules/*' -not -path "./$SELF_REL" -print0 -not -path '*/node_modules/*' -not -path "./$SELF_REL" -print0
} }
# Structural scope = shipped scripts, examples/ EXCLUDED. # Structural scope = shipped scripts, examples/ EXCLUDED.

View File

@@ -1,6 +1,6 @@
{ {
"name": "@mosaicstack/mosaic", "name": "@mosaicstack/mosaic",
"version": "0.0.35", "version": "0.0.34",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://git.mosaicstack.dev/mosaicstack/stack.git", "url": "https://git.mosaicstack.dev/mosaicstack/stack.git",

View File

@@ -10,14 +10,11 @@ import {
buildAgentWatchCreateViewerCommand, buildAgentWatchCreateViewerCommand,
buildAgentWatchKillViewerCommand, buildAgentWatchKillViewerCommand,
buildAgentVerifyAcceptedCommand, buildAgentVerifyAcceptedCommand,
buildEnableLingerCommand,
buildFleetServiceCommand, buildFleetServiceCommand,
buildSystemdEnableCommand,
buildSystemdShowCommand, buildSystemdShowCommand,
buildTmuxListPanesCommand, buildTmuxListPanesCommand,
classifySendResult, classifySendResult,
detectDrift, detectDrift,
enableFleetUnits,
generateAgentEnv, generateAgentEnv,
getDefaultOperatorSourceLabel, getDefaultOperatorSourceLabel,
getDefaultTenantAndHost, getDefaultTenantAndHost,
@@ -31,12 +28,10 @@ import {
parseTmuxListPanes, parseTmuxListPanes,
registerFleetCommand, registerFleetCommand,
resolveFleetPaths, resolveFleetPaths,
RUNTIME_ACCEPTABLE_COMMANDS,
VERIFY_DEFAULT_TIMEOUT_MS, VERIFY_DEFAULT_TIMEOUT_MS,
VERIFY_POLL_INTERVAL_MS, VERIFY_POLL_INTERVAL_MS,
type AgentPsRow, type AgentPsRow,
type CommandRunner, type CommandRunner,
type FleetRoster,
type InteractiveRunner, type InteractiveRunner,
type SleepFn, type SleepFn,
} from './fleet.js'; } from './fleet.js';
@@ -914,118 +909,6 @@ describe('fleet ps — drift detection', () => {
it('does NOT flag drift when pane command is null (pane dead)', () => { it('does NOT flag drift when pane command is null (pane dead)', () => {
expect(detectDrift('pi', null)).toBe(false); expect(detectDrift('pi', null)).toBe(false);
}); });
it('does NOT flag drift when pane=node for wrapped pi agent (mosaic yolo pi)', () => {
expect(detectDrift('pi', 'node')).toBe(false);
});
it('does NOT flag drift when pane=node for wrapped codex agent (mosaic yolo codex)', () => {
expect(detectDrift('codex', 'node')).toBe(false);
});
it('flags drift when pane=python3 for pi runtime (canary-pi dogfood regression guard)', () => {
expect(detectDrift('pi', 'python3')).toBe(true);
});
it('does NOT flag drift when pane=python3 for dogfood runtime', () => {
expect(detectDrift('dogfood', 'python3')).toBe(false);
});
it('flags drift for unknown pane command on known runtime', () => {
expect(detectDrift('claude', 'bash')).toBe(true);
});
it('RUNTIME_ACCEPTABLE_COMMANDS is exported and contains expected entries', () => {
expect(RUNTIME_ACCEPTABLE_COMMANDS['pi']).toContain('node');
expect(RUNTIME_ACCEPTABLE_COMMANDS['pi']).not.toContain('python3');
expect(RUNTIME_ACCEPTABLE_COMMANDS['dogfood']).toContain('python3');
expect(RUNTIME_ACCEPTABLE_COMMANDS['codex']).toContain('node');
});
});
describe('fleet install — auto-enable units for boot-survival', () => {
it('buildSystemdEnableCommand and buildEnableLingerCommand return correct command arrays', () => {
expect(buildSystemdEnableCommand('mosaic-tmux-holder.service')).toEqual([
'systemctl',
'--user',
'enable',
'mosaic-tmux-holder.service',
]);
expect(buildEnableLingerCommand('testuser')).toEqual(['loginctl', 'enable-linger', 'testuser']);
});
it('enables holder and each agent unit via injected runner after install', async () => {
const minimalRoster: FleetRoster = {
version: 1,
transport: 'tmux',
tmux: { socketName: 'mosaic-factory', holderSession: '_holder' },
defaults: { workingDirectory: '~/src' },
runtimes: { codex: { resetCommand: '/clear' } },
agents: [{ name: 'coder0', runtime: 'codex', className: 'worker' }],
};
const calls: string[][] = [];
const runner: CommandRunner = async (command, args) => {
calls.push([command, ...args]);
return { stdout: '', stderr: '', exitCode: 0 };
};
await enableFleetUnits(runner, minimalRoster, {});
expect(calls).toContainEqual(['systemctl', '--user', 'enable', 'mosaic-tmux-holder.service']);
expect(calls).toContainEqual(['systemctl', '--user', 'enable', 'mosaic-agent@coder0.service']);
});
it('install still succeeds when systemctl enable returns non-zero (non-fatal)', async () => {
const minimalRoster: FleetRoster = {
version: 1,
transport: 'tmux',
tmux: { socketName: 'mosaic-factory', holderSession: '_holder' },
defaults: { workingDirectory: '~/src' },
runtimes: { codex: { resetCommand: '/clear' } },
agents: [{ name: 'coder0', runtime: 'codex', className: 'worker' }],
};
const calls: string[][] = [];
const runner: CommandRunner = async (command, args) => {
calls.push([command, ...args]);
// Simulate systemctl enable failure
if (command === 'systemctl' && args.includes('enable')) {
return { stdout: '', stderr: 'Unit not found', exitCode: 1 };
}
return { stdout: '', stderr: '', exitCode: 0 };
};
// Must NOT reject/throw even when enable calls fail
await expect(enableFleetUnits(runner, minimalRoster, {})).resolves.toBeUndefined();
// The enable attempt must have been made
expect(calls.some((c) => c.includes('enable'))).toBe(true);
});
it('--no-enable skips all systemctl enable and loginctl linger calls', async () => {
const minimalRoster: FleetRoster = {
version: 1,
transport: 'tmux',
tmux: { socketName: 'mosaic-factory', holderSession: '_holder' },
defaults: { workingDirectory: '~/src' },
runtimes: { codex: { resetCommand: '/clear' } },
agents: [{ name: 'coder0', runtime: 'codex', className: 'worker' }],
};
const calls: string[][] = [];
const runner: CommandRunner = async (command, args) => {
calls.push([command, ...args]);
return { stdout: '', stderr: '', exitCode: 0 };
};
await enableFleetUnits(runner, minimalRoster, { enable: false });
// No calls should include 'enable'
expect(calls.every((c) => !c.includes('enable'))).toBe(true);
// No loginctl calls at all
expect(calls.every((c) => c[0] !== 'loginctl')).toBe(true);
});
}); });
describe('fleet ps — tenant and host', () => { describe('fleet ps — tenant and host', () => {

View File

@@ -210,93 +210,6 @@ export function buildFleetServiceCommand(action: FleetServiceAction, agentName?:
return ['systemctl', '--user', action, service]; return ['systemctl', '--user', action, service];
} }
/**
* Returns the systemctl --user enable command for a given unit.
* Used by the install auto-enable step to persist units across reboots.
*/
export function buildSystemdEnableCommand(unit: string): string[] {
return ['systemctl', '--user', 'enable', unit];
}
/**
* Returns the loginctl enable-linger command for a given user.
* Linger allows user systemd services to survive logout.
*/
export function buildEnableLingerCommand(user: string): string[] {
return ['loginctl', 'enable-linger', user];
}
/**
* Enable fleet units for boot-survival after install.
* Non-fatal: if systemctl enable returns non-zero, a warning is printed and we continue.
* If opts.enable === false (--no-enable flag), the whole step is skipped.
*/
export async function enableFleetUnits(
runner: CommandRunner,
roster: FleetRoster,
opts: { enable?: boolean },
): Promise<void> {
if (opts.enable === false) {
return;
}
try {
let succeeded = 0;
let failed = 0;
const holderResult = await runner(
...splitCommand(buildSystemdEnableCommand('mosaic-tmux-holder.service')),
);
if (holderResult.exitCode === 0) {
succeeded++;
} else {
failed++;
process.stderr.write(
`Warning: could not enable mosaic-tmux-holder.service: ${holderResult.stderr || holderResult.stdout || 'non-zero exit'}\n`,
);
}
for (const agent of roster.agents) {
const unit = `mosaic-agent@${agent.name}.service`;
const result = await runner(...splitCommand(buildSystemdEnableCommand(unit)));
if (result.exitCode === 0) {
succeeded++;
} else {
failed++;
process.stderr.write(
`Warning: could not enable ${unit}: ${result.stderr || result.stdout || 'non-zero exit'}\n`,
);
}
}
if (succeeded > 0) {
console.log(`Enabled ${succeeded} unit(s) for boot-survival.`);
}
if (failed > 0) {
process.stderr.write(
`Warning: ${failed} unit(s) could not be enabled (systemctl unavailable?). Run manually if needed.\n`,
);
}
// Best-effort linger
let username: string;
try {
username = userInfo().username;
} catch {
username = process.env['USER'] ?? process.env['LOGNAME'] ?? 'unknown';
}
const lingerResult = await runner(...splitCommand(buildEnableLingerCommand(username)));
if (lingerResult.exitCode !== 0) {
process.stderr.write(
`Hint: run 'loginctl enable-linger ${username}' as root to survive logout.\n`,
);
}
} catch (err) {
process.stderr.write(
`Warning: auto-enable step failed unexpectedly: ${err instanceof Error ? err.message : String(err)}\n`,
);
}
}
export function buildAgentSendCommand( export function buildAgentSendCommand(
paths: FleetPaths, paths: FleetPaths,
agentName: string, agentName: string,
@@ -524,41 +437,32 @@ export function parseTmuxListPanes(
return { pid, command, dead, idleSeconds }; return { pid, command, dead, idleSeconds };
} }
/**
* Maps each known runtime to the set of acceptable pane commands.
* A pane running any of these commands for the given runtime is NOT considered drifted.
* Runtimes launched via `mosaic yolo` wrap in node, so 'node' is acceptable for most.
* The dogfood runtime accepts python3/python (the canary-pi dogfood stub).
*/
export const RUNTIME_ACCEPTABLE_COMMANDS: Record<string, readonly string[]> = {
claude: ['claude', 'node'],
codex: ['codex', 'node'],
opencode: ['opencode', 'node'],
pi: ['pi', 'node'],
dogfood: ['python3', 'python'],
};
/** /**
* Determine if there is a runtime drift: roster says one runtime but the pane * Determine if there is a runtime drift: roster says one runtime but the pane
* is actually running something from a different runtime. We detect this by * is actually running something from a different runtime. We detect this by
* checking if the pane command doesn't match a known acceptable command for the * checking if the pane command doesn't match a known canonical command for the
* roster's declared runtime. * roster's declared runtime.
* *
* Known acceptable commands per runtime (see RUNTIME_ACCEPTABLE_COMMANDS): * Known canonical commands per runtime:
* claude → claude, node (node covers mosaic yolo wrapper) * claude → claude
* codex → codex, node * codex → codex
* opencode → opencode, node * opencode → opencode
* pi → pi, node (python3 still flags drift for canary-pi dogfood stub) * pi → pi
* dogfood → python3, python
* *
* If the pane is running something else (e.g., python3/dogfood-agent.py) for * If the pane is running something else (e.g., python3/dogfood-agent.py) for
* an agent whose roster runtime is "pi", that's a drift. * an agent whose roster runtime is "pi", that's a drift.
*/ */
export function detectDrift(rosterRuntime: string, paneCommand: string | null): boolean { export function detectDrift(rosterRuntime: string, paneCommand: string | null): boolean {
if (!paneCommand) return false; if (!paneCommand) return false;
const acceptable = RUNTIME_ACCEPTABLE_COMMANDS[rosterRuntime]; const knownCommands: Record<string, string[]> = {
if (!acceptable) return false; claude: ['claude'],
return !acceptable.includes(paneCommand); codex: ['codex'],
opencode: ['opencode'],
pi: ['pi'],
};
const expected = knownCommands[rosterRuntime];
if (!expected) return false;
return !expected.includes(paneCommand);
} }
/** /**
@@ -802,22 +706,12 @@ export function registerFleetCommand(program: Command, deps: FleetCommandDeps =
cmd cmd
.command('install') .command('install')
.description('Install local fleet tools and user systemd units') .description('Install local fleet tools and user systemd units')
.option('--no-enable', 'Skip enabling units for boot-survival') .action(async () => installFleet(cmd, frameworkRoot));
.action(async (opts: { enable?: boolean }) => {
await installFleet(cmd, frameworkRoot);
const roster = await loadRosterForCommand(cmd);
await enableFleetUnits(runner, roster, opts);
});
cmd cmd
.command('install-systemd') .command('install-systemd')
.description('Install local fleet tools and user systemd units') .description('Install local fleet tools and user systemd units')
.option('--no-enable', 'Skip enabling units for boot-survival') .action(async () => installFleet(cmd, frameworkRoot));
.action(async (opts: { enable?: boolean }) => {
await installFleet(cmd, frameworkRoot);
const roster = await loadRosterForCommand(cmd);
await enableFleetUnits(runner, roster, opts);
});
for (const action of ['start', 'stop', 'restart'] as const) { for (const action of ['start', 'stop', 'restart'] as const) {
cmd cmd