Compare commits

..

4 Commits

Author SHA1 Message Date
Jarvis
10d65c4a10 feat(fleet): auto-enable units on install + drift recognizes wrapped runtimes
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
- mosaic fleet install now enables mosaic-tmux-holder.service and
  mosaic-agent@<name>.service via systemctl --user enable after copying
  unit files; enabling is non-fatal (warns and continues on failure)
- best-effort loginctl enable-linger for logout survival
- --no-enable flag opts out of auto-enable
- detectDrift updated to use RUNTIME_ACCEPTABLE_COMMANDS map:
  pi/codex/opencode/claude accept 'node' (mosaic yolo wrapper);
  dogfood accepts python3/python; canary-pi (runtime=pi, pane=python3)
  still correctly flags DRIFT

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RMoEx7hfdFGjUiCHuN1RRi
2026-06-21 14:40:33 -05:00
c2c0b5fe8d chore(release): bump @mosaicstack/mosaic 0.0.34 -> 0.0.35 (#582)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/push/publish Pipeline was successful
2026-06-21 18:59:39 +00:00
c9cfe36204 docs(framework): P3.1 fast-follow — governance wording + gate scope + bare-launch note (#577)
Some checks failed
ci/woodpecker/push/ci Pipeline was canceled
ci/woodpecker/push/publish Pipeline was canceled
Co-authored-by: Jason Woltje <jason@diversecanvas.com>
Co-committed-by: Jason Woltje <jason@diversecanvas.com>
2026-06-21 18:56:50 +00:00
fc90c89913 fix(fleet): durable runtime PATH for detached agent launch (#581)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/push/publish Pipeline was successful
2026-06-21 17:30:40 +00:00
6 changed files with 251 additions and 22 deletions

View File

@@ -70,6 +70,9 @@ Skills, hooks, MCP, and plugins are force multipliers you MUST use when applicab
## Missing core file
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

View File

@@ -2,8 +2,11 @@
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. To change
behavior, add a `.local.md` overlay or a `policy/` file (tighten-only; see `constitution/LAYER-MODEL.md`).
**Framework-owned.** This file is overwritten verbatim on every upgrade — do not edit it. There is
**no `CONSTITUTION.local.md`**: hard gates are not locally overridable. A lower layer may only make
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
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/,
# because worked example overlays/personas legitimately show placeholder paths.
#
# File types: *.md, *.sh, *.ps1, *.json, and the extensionless CLI scripts under
# File types: *.md, *.sh, *.ps1, *.json, *.yml/*.yaml, *.toml, *.env, *.service, and the CLI scripts under
# tools/_scripts/. Excludes node_modules/ and this gate file.
#
# 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).
_files_identity() {
find . -type f \
\( -name '*.md' -o -name '*.sh' -o -name '*.ps1' -o -name '*.json' -o -path '*/tools/_scripts/*' \) \
\( -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/*' \) \
-not -path '*/node_modules/*' -not -path "./$SELF_REL" -print0
}
# Structural scope = shipped scripts, examples/ EXCLUDED.

View File

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

View File

@@ -10,11 +10,14 @@ import {
buildAgentWatchCreateViewerCommand,
buildAgentWatchKillViewerCommand,
buildAgentVerifyAcceptedCommand,
buildEnableLingerCommand,
buildFleetServiceCommand,
buildSystemdEnableCommand,
buildSystemdShowCommand,
buildTmuxListPanesCommand,
classifySendResult,
detectDrift,
enableFleetUnits,
generateAgentEnv,
getDefaultOperatorSourceLabel,
getDefaultTenantAndHost,
@@ -28,10 +31,12 @@ import {
parseTmuxListPanes,
registerFleetCommand,
resolveFleetPaths,
RUNTIME_ACCEPTABLE_COMMANDS,
VERIFY_DEFAULT_TIMEOUT_MS,
VERIFY_POLL_INTERVAL_MS,
type AgentPsRow,
type CommandRunner,
type FleetRoster,
type InteractiveRunner,
type SleepFn,
} from './fleet.js';
@@ -909,6 +914,118 @@ describe('fleet ps — drift detection', () => {
it('does NOT flag drift when pane command is null (pane dead)', () => {
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', () => {

View File

@@ -210,6 +210,93 @@ export function buildFleetServiceCommand(action: FleetServiceAction, agentName?:
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(
paths: FleetPaths,
agentName: string,
@@ -437,32 +524,41 @@ export function parseTmuxListPanes(
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
* is actually running something from a different runtime. We detect this by
* checking if the pane command doesn't match a known canonical command for the
* checking if the pane command doesn't match a known acceptable command for the
* roster's declared runtime.
*
* Known canonical commands per runtime:
* claude → claude
* codex → codex
* opencode → opencode
* pi → pi
* Known acceptable commands per runtime (see RUNTIME_ACCEPTABLE_COMMANDS):
* claude → claude, node (node covers mosaic yolo wrapper)
* codex → codex, node
* opencode → opencode, node
* pi → pi, node (python3 still flags drift for canary-pi dogfood stub)
* dogfood → python3, python
*
* 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.
*/
export function detectDrift(rosterRuntime: string, paneCommand: string | null): boolean {
if (!paneCommand) return false;
const knownCommands: Record<string, string[]> = {
claude: ['claude'],
codex: ['codex'],
opencode: ['opencode'],
pi: ['pi'],
};
const expected = knownCommands[rosterRuntime];
if (!expected) return false;
return !expected.includes(paneCommand);
const acceptable = RUNTIME_ACCEPTABLE_COMMANDS[rosterRuntime];
if (!acceptable) return false;
return !acceptable.includes(paneCommand);
}
/**
@@ -706,12 +802,22 @@ export function registerFleetCommand(program: Command, deps: FleetCommandDeps =
cmd
.command('install')
.description('Install local fleet tools and user systemd units')
.action(async () => installFleet(cmd, frameworkRoot));
.option('--no-enable', 'Skip enabling units for boot-survival')
.action(async (opts: { enable?: boolean }) => {
await installFleet(cmd, frameworkRoot);
const roster = await loadRosterForCommand(cmd);
await enableFleetUnits(runner, roster, opts);
});
cmd
.command('install-systemd')
.description('Install local fleet tools and user systemd units')
.action(async () => installFleet(cmd, frameworkRoot));
.option('--no-enable', 'Skip enabling units for boot-survival')
.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) {
cmd