Merge M4: runtime adapter seam
Closes #16, closes #17, closes #18, closes #19
This commit is contained in:
@@ -192,4 +192,33 @@ Mission/task layer verified end-to-end. `main` merged with M2 and tagged `missio
|
|||||||
|
|
||||||
Release model and safe updates verified by drills. `main` merged with M3 and tagged `release-model-v1`.
|
Release model and safe updates verified by drills. `main` merged with M3 and tagged `release-model-v1`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 8: Runtime adapter seam (M4)
|
||||||
|
|
||||||
|
### Entry 8.1 — before
|
||||||
|
|
||||||
|
- Timestamp: 2026-09-03
|
||||||
|
- Intended action: Formalize the harness boundary (Gitea milestone M4, issues #16-#19): documented adapter contract under /opt/mosaic/adapters/<name>/adapter.sh; run-agent.sh becomes a dispatcher; pi extracted unchanged; deterministic mock adapter for provider-free seam tests; config gains optional execution.adapter (default pi, configVersion unchanged); mission directives gain their sanctioned injection point via the run snapshot; RELEASE bumps to 0.0.5 with a health-gated activation.
|
||||||
|
- Reason: Future harnesses (Claude, Codex, OpenCode) must be additive — one directory each — and mission content needs a single sanctioned path into the runtime.
|
||||||
|
- Expected result: All suites green including new deterministic seam cases; 0.0.5 activated by health gate; mission-bearing run recorded.
|
||||||
|
|
||||||
|
### Entry 8.2 — after
|
||||||
|
|
||||||
|
- Timestamp: 2026-09-03
|
||||||
|
- Commands run: scripts/test-config.sh; scripts/test-task.sh; scripts/test-release.sh; manual seam drills (mock verbatim, unknown/traversal adapter refusal); mission injection checks; release package + activate for 0.0.5.
|
||||||
|
- Observed result:
|
||||||
|
- Config suite 24/24 (adapter default/validation/env export).
|
||||||
|
- Task suite 24/24 including deterministic mock cases (gate pass, expect-mismatch with reason, unknown adapter fail-closed) and mission injection asserted by prompt content.
|
||||||
|
- Release suite 14/14; image mosaic-poc-agent:0.84.4-r0.0.5 packaged and activated via exact-marker health gate.
|
||||||
|
- Mission directives now flow: task -> run snapshot -> container env -> generated prompt MISSION (runtime) section.
|
||||||
|
- Failure or correction:
|
||||||
|
1. Selection authority settled: load_config always exports MOSAIC_ADAPTER from config; environment overrides for scripts are therefore not a supported selection path (by design).
|
||||||
|
2. Selftest harness: three authoring defects fixed (helpers used before definition; one config file reused across cases leaking adapter state; a static mission fixture asserted against distinctive seam directives; plus an accidentally duplicated live block removed).
|
||||||
|
- Credential check: no credential material in adapters, prompts, run records, or logs.
|
||||||
|
|
||||||
|
## Result (M4)
|
||||||
|
|
||||||
|
Adapter seam verified; harness boundary is now additive by construction. `main` merged with M4 and tagged `adapter-seam-v1`.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -18,11 +18,14 @@ WORKDIR /opt/app
|
|||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
RUN npm ci --ignore-scripts
|
RUN npm ci --ignore-scripts
|
||||||
|
|
||||||
# Immutable contract fixtures (required location) and runtime scripts.
|
# Immutable contract fixtures (required location), runtime scripts, and
|
||||||
|
# runtime adapters.
|
||||||
COPY contracts /opt/mosaic/contracts
|
COPY contracts /opt/mosaic/contracts
|
||||||
COPY src /opt/mosaic/src
|
COPY src /opt/mosaic/src
|
||||||
|
COPY adapters /opt/mosaic/adapters
|
||||||
RUN chmod 0555 /opt/mosaic/contracts /opt/mosaic/contracts/* \
|
RUN chmod 0555 /opt/mosaic/contracts /opt/mosaic/contracts/* \
|
||||||
&& chmod 0555 /opt/mosaic/src /opt/mosaic/src/*.sh
|
&& chmod 0555 /opt/mosaic/src /opt/mosaic/src/*.sh \
|
||||||
|
&& chmod 0555 /opt/mosaic/adapters /opt/mosaic/adapters/*/adapter.sh
|
||||||
|
|
||||||
# Writable state, workspace, and pi agent directory (auth.json is
|
# Writable state, workspace, and pi agent directory (auth.json is
|
||||||
# bind-mounted read-only at runtime; nothing is copied into the image).
|
# bind-mounted read-only at runtime; nothing is copied into the image).
|
||||||
|
|||||||
@@ -101,6 +101,24 @@ scripts/test-release.sh # release selftests
|
|||||||
|
|
||||||
A failed health check never activates; the previously active release remains deployed. Updating the software therefore cannot corrupt the running installation: package beside, gate, then flip. Verified by the update/refusal/rollback drills in BUILD-LOG Phase 7.
|
A failed health check never activates; the previously active release remains deployed. Updating the software therefore cannot corrupt the running installation: package beside, gate, then flip. Verified by the update/refusal/rollback drills in BUILD-LOG Phase 7.
|
||||||
|
|
||||||
|
## Runtime adapters (M4)
|
||||||
|
|
||||||
|
The harness boundary is formalized: everything upstream (config, contracts, missions, tasks, run records) is harness-agnostic; everything inside an adapter belongs to one runtime.
|
||||||
|
|
||||||
|
```text
|
||||||
|
adapters/<name>/adapter.sh env in: MOSAIC_SYSTEM_PROMPT_FILE, MOSAIC_REQUEST,
|
||||||
|
MOSAIC_PROVIDER, MOSAIC_MODEL
|
||||||
|
stdout: response only; stderr: diagnostics
|
||||||
|
```
|
||||||
|
|
||||||
|
- Selection: `execution.adapter` in config.json (optional; `pi` default; allowlist `pi`, `mock`)
|
||||||
|
- `pi` — pinned Pi CLI, noninteractive print mode, ambient discovery off
|
||||||
|
- `mock` — deterministic test adapter; never for real verification
|
||||||
|
- Mission directives have a sanctioned injection point: when a task references a mission, the task runner mounts the run snapshot and the generated prompt gains a `MISSION (runtime)` section (objective + directives) after the four immutable contracts
|
||||||
|
- Adding a harness (Claude, Codex, OpenCode) later means adding one directory — no orchestrator changes
|
||||||
|
|
||||||
|
See `adapters/README.md` for the full contract.
|
||||||
|
|
||||||
See `docs/plans/2026-09-02_atomic-mosaic-foundation.md` for the full plan.
|
See `docs/plans/2026-09-02_atomic-mosaic-foundation.md` for the full plan.
|
||||||
|
|
||||||
Inside the container:
|
Inside the container:
|
||||||
@@ -137,7 +155,7 @@ scripts/verify.sh # full gated test; exit 0 only on exact MOSAIC_HELLO_OK
|
|||||||
scripts/run-task.sh # run a mission/task file (see Missions & tasks)
|
scripts/run-task.sh # run a mission/task file (see Missions & tasks)
|
||||||
scripts/release.sh # package / activate / rollback / status (see Release model)
|
scripts/release.sh # package / activate / rollback / status (see Release model)
|
||||||
scripts/test-config.sh # fast config-layer selftests (no Docker)
|
scripts/test-config.sh # fast config-layer selftests (no Docker)
|
||||||
scripts/test-task.sh # mission/task selftests (schema + live runs)
|
scripts/test-task.sh # mission/task selftests (schema + adapter seam + live runs)
|
||||||
scripts/test-release.sh # release selftests
|
scripts/test-release.sh # release selftests
|
||||||
scripts/reset.sh # delete the configured data root (safety-checked)
|
scripts/reset.sh # delete the configured data root (safety-checked)
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
# Mosaic runtime adapters
|
||||||
|
|
||||||
|
An adapter is the entire harness-specific surface of the system. Everything
|
||||||
|
upstream of an adapter — configuration, contracts, missions, tasks, run
|
||||||
|
records — is harness-agnostic; everything inside an adapter may assume one
|
||||||
|
specific agent runtime.
|
||||||
|
|
||||||
|
## Contract
|
||||||
|
|
||||||
|
An adapter lives at:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/opt/mosaic/adapters/<name>/adapter.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
and must be executable. The dispatcher (`/opt/mosaic/src/run-agent.sh`)
|
||||||
|
selects it via `MOSAIC_ADAPTER` (default: `pi`) and execs it after the
|
||||||
|
system prompt has been generated.
|
||||||
|
|
||||||
|
**Inputs (environment):**
|
||||||
|
|
||||||
|
| Variable | Meaning |
|
||||||
|
|---|---|
|
||||||
|
| `MOSAIC_SYSTEM_PROMPT_FILE` | Absolute path to the generated system prompt (contracts + optional mission section). Read it; do not modify it. |
|
||||||
|
| `MOSAIC_REQUEST` | The exact user request text (may contain newlines). |
|
||||||
|
| `MOSAIC_PROVIDER` | Configured provider name. |
|
||||||
|
| `MOSAIC_MODEL` | Configured model id. |
|
||||||
|
|
||||||
|
Optional, adapter-specific (documented per adapter):
|
||||||
|
|
||||||
|
| Variable | Meaning |
|
||||||
|
|---|---|
|
||||||
|
| `MOSAIC_MOCK_RESPONSE` | mock only: the verbatim response to emit |
|
||||||
|
|
||||||
|
**Outputs:**
|
||||||
|
|
||||||
|
- `stdout`: the model response text — the only channel the orchestrator captures
|
||||||
|
- `stderr`: diagnostics (never credentials)
|
||||||
|
- exit `0`: success; nonzero: failure
|
||||||
|
|
||||||
|
## Rules
|
||||||
|
|
||||||
|
1. Adapters print ONLY the response on stdout. Status lines go to stderr.
|
||||||
|
2. Adapters never read configuration files; the resolved settings arrive via environment.
|
||||||
|
3. Adapters never write outside `/var/lib/mosaic`.
|
||||||
|
4. Adding an adapter requires: a new directory, the contract implementation, and
|
||||||
|
adding the name to the allowlist in `scripts/mosaic-config.mjs`.
|
||||||
|
|
||||||
|
## Included adapters
|
||||||
|
|
||||||
|
- `pi` — the pinned `@earendil-works/pi-coding-agent` CLI in noninteractive
|
||||||
|
print mode (`-p`), ambient discovery disabled, stdin detached.
|
||||||
|
- `mock` — deterministic echo of `MOSAIC_MOCK_RESPONSE`. Test-only: never use
|
||||||
|
it where a real model response is required.
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Mock adapter: deterministic response for seam tests. NEVER use where a
|
||||||
|
# real model response is required.
|
||||||
|
#
|
||||||
|
# Contract: see /opt/mosaic/adapters/README.md.
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
[ -n "${MOSAIC_SYSTEM_PROMPT_FILE:-}" ] || { echo "mock adapter: MOSAIC_SYSTEM_PROMPT_FILE is required" >&2; exit 2; }
|
||||||
|
[ -n "${MOSAIC_REQUEST:-}" ] || { echo "mock adapter: MOSAIC_REQUEST is required" >&2; exit 2; }
|
||||||
|
[ -r "$MOSAIC_SYSTEM_PROMPT_FILE" ] || { echo "mock adapter: system prompt not readable: $MOSAIC_SYSTEM_PROMPT_FILE" >&2; exit 2; }
|
||||||
|
|
||||||
|
echo "mock adapter: responding verbatim from MOSAIC_MOCK_RESPONSE" >&2
|
||||||
|
printf '%s\n' "${MOSAIC_MOCK_RESPONSE:-}"
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Pi adapter: implements the Mosaic adapter contract for the pinned
|
||||||
|
# @earendil-works/pi-coding-agent CLI.
|
||||||
|
#
|
||||||
|
# Contract: see /opt/mosaic/adapters/README.md. stdout = response only.
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
[ -n "${MOSAIC_SYSTEM_PROMPT_FILE:-}" ] || { echo "pi adapter: MOSAIC_SYSTEM_PROMPT_FILE is required" >&2; exit 2; }
|
||||||
|
[ -n "${MOSAIC_REQUEST:-}" ] || { echo "pi adapter: MOSAIC_REQUEST is required" >&2; exit 2; }
|
||||||
|
[ -r "$MOSAIC_SYSTEM_PROMPT_FILE" ] || { echo "pi adapter: system prompt not readable: $MOSAIC_SYSTEM_PROMPT_FILE" >&2; exit 2; }
|
||||||
|
|
||||||
|
: "${PI_PROVIDER:?pi adapter: PI_PROVIDER is required}"
|
||||||
|
: "${PI_MODEL:?pi adapter: PI_MODEL is required}"
|
||||||
|
|
||||||
|
# All flags documented in the pi package README (CLI Reference):
|
||||||
|
# -p/--print noninteractive: print the response and exit
|
||||||
|
# --system-prompt replace the default prompt with the generated one
|
||||||
|
# --no-* no ambient context/skills/extensions/templates/themes
|
||||||
|
# --no-session ephemeral; --no-tools this runtime needs no tools
|
||||||
|
# --offline no startup network operations (update checks/telemetry)
|
||||||
|
exec pi \
|
||||||
|
--offline \
|
||||||
|
--no-session \
|
||||||
|
--no-extensions \
|
||||||
|
--no-skills \
|
||||||
|
--no-prompt-templates \
|
||||||
|
--no-themes \
|
||||||
|
--no-context-files \
|
||||||
|
--no-tools \
|
||||||
|
--provider "$PI_PROVIDER" \
|
||||||
|
--model "$PI_MODEL" \
|
||||||
|
--system-prompt "$(cat "$MOSAIC_SYSTEM_PROMPT_FILE")" \
|
||||||
|
-p "$MOSAIC_REQUEST"
|
||||||
@@ -10,6 +10,13 @@ services:
|
|||||||
# Required: compose fails fast when the launcher did not supply them.
|
# Required: compose fails fast when the launcher did not supply them.
|
||||||
PI_PROVIDER: ${MOSAIC_PROVIDER:?MOSAIC_PROVIDER must be set by scripts/load_config (run via scripts/*.sh)}
|
PI_PROVIDER: ${MOSAIC_PROVIDER:?MOSAIC_PROVIDER must be set by scripts/load_config (run via scripts/*.sh)}
|
||||||
PI_MODEL: ${MOSAIC_MODEL:?MOSAIC_MODEL must be set by scripts/load_config (run via scripts/*.sh)}
|
PI_MODEL: ${MOSAIC_MODEL:?MOSAIC_MODEL must be set by scripts/load_config (run via scripts/*.sh)}
|
||||||
|
# Adapter selection (resolved from config execution.adapter; default pi)
|
||||||
|
MOSAIC_ADAPTER: ${MOSAIC_ADAPTER:-pi}
|
||||||
|
# Mission directives injection point (set by the task runner when the
|
||||||
|
# task references a mission; container path of the run snapshot)
|
||||||
|
MOSAIC_MISSION_FILE: ${MOSAIC_MISSION_FILE:-}
|
||||||
|
# mock adapter only: verbatim response for deterministic seam tests
|
||||||
|
MOSAIC_MOCK_RESPONSE: ${MOSAIC_MOCK_RESPONSE:-}
|
||||||
# Documented container auth alternative: provider API key via
|
# Documented container auth alternative: provider API key via
|
||||||
# runtime environment variable. Empty by default; when empty Pi
|
# runtime environment variable. Empty by default; when empty Pi
|
||||||
# falls back to the read-only mounted auth.json credential file.
|
# falls back to the read-only mounted auth.json credential file.
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ load_config() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
eval "$config_env"
|
eval "$config_env"
|
||||||
export MOSAIC_DATA_ROOT MOSAIC_PROVIDER MOSAIC_MODEL
|
export MOSAIC_DATA_ROOT MOSAIC_PROVIDER MOSAIC_MODEL MOSAIC_ADAPTER
|
||||||
MOSAIC_DEV_DIR="$MOSAIC_DATA_ROOT"
|
MOSAIC_DEV_DIR="$MOSAIC_DATA_ROOT"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import process from "node:process";
|
|||||||
const SUPPORTED_CONFIG_VERSION = 1;
|
const SUPPORTED_CONFIG_VERSION = 1;
|
||||||
const SUPPORTED_ENVIRONMENTS = new Set(["development", "production"]);
|
const SUPPORTED_ENVIRONMENTS = new Set(["development", "production"]);
|
||||||
const SUPPORTED_BACKENDS = new Set(["docker"]);
|
const SUPPORTED_BACKENDS = new Set(["docker"]);
|
||||||
|
const SUPPORTED_ADAPTERS = new Set(["pi", "mock"]); // mock: test-only, see adapters/README.md
|
||||||
const NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,199}$/;
|
const NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,199}$/;
|
||||||
|
|
||||||
function fail(exitCode, message) {
|
function fail(exitCode, message) {
|
||||||
@@ -127,7 +128,7 @@ function validate(document, file) {
|
|||||||
if (!isPlainObject(document.execution)) {
|
if (!isPlainObject(document.execution)) {
|
||||||
fail(2, '"execution" must be a JSON object');
|
fail(2, '"execution" must be a JSON object');
|
||||||
}
|
}
|
||||||
rejectUnknownKeys(document.execution, ["backend", "provider", "model"], '"execution"');
|
rejectUnknownKeys(document.execution, ["backend", "provider", "model", "adapter"], '"execution"');
|
||||||
if (!SUPPORTED_BACKENDS.has(document.execution.backend)) {
|
if (!SUPPORTED_BACKENDS.has(document.execution.backend)) {
|
||||||
fail(2, `unsupported execution.backend: ${JSON.stringify(document.execution.backend)} (supported: ${[...SUPPORTED_BACKENDS].join(", ")})`);
|
fail(2, `unsupported execution.backend: ${JSON.stringify(document.execution.backend)} (supported: ${[...SUPPORTED_BACKENDS].join(", ")})`);
|
||||||
}
|
}
|
||||||
@@ -138,6 +139,13 @@ function validate(document, file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const adapter = document.execution.adapter === undefined || document.execution.adapter === null
|
||||||
|
? "pi"
|
||||||
|
: document.execution.adapter;
|
||||||
|
if (typeof adapter !== "string" || !SUPPORTED_ADAPTERS.has(adapter)) {
|
||||||
|
fail(2, `unsupported execution.adapter: ${JSON.stringify(adapter)} (supported: ${[...SUPPORTED_ADAPTERS].join(", ")})`);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
configVersion: document.configVersion,
|
configVersion: document.configVersion,
|
||||||
environment: document.environment,
|
environment: document.environment,
|
||||||
@@ -146,6 +154,7 @@ function validate(document, file) {
|
|||||||
backend: document.execution.backend,
|
backend: document.execution.backend,
|
||||||
provider: document.execution.provider,
|
provider: document.execution.provider,
|
||||||
model: document.execution.model,
|
model: document.execution.model,
|
||||||
|
adapter,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -222,6 +231,7 @@ switch (operation) {
|
|||||||
`MOSAIC_DATA_ROOT=${shellQuote(resolved.dataRoot)}`,
|
`MOSAIC_DATA_ROOT=${shellQuote(resolved.dataRoot)}`,
|
||||||
`MOSAIC_PROVIDER=${shellQuote(resolved.execution.provider)}`,
|
`MOSAIC_PROVIDER=${shellQuote(resolved.execution.provider)}`,
|
||||||
`MOSAIC_MODEL=${shellQuote(resolved.execution.model)}`,
|
`MOSAIC_MODEL=${shellQuote(resolved.execution.model)}`,
|
||||||
|
`MOSAIC_ADAPTER=${shellQuote(resolved.execution.adapter)}`,
|
||||||
"",
|
"",
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
);
|
);
|
||||||
|
|||||||
+14
-1
@@ -210,12 +210,25 @@ function runTask(taskFile) {
|
|||||||
|
|
||||||
const startedAt = new Date();
|
const startedAt = new Date();
|
||||||
const stderrFile = path.join(runDir, "stderr.txt");
|
const stderrFile = path.join(runDir, "stderr.txt");
|
||||||
|
|
||||||
|
// Sanctioned mission injection: point the container at the run snapshot's
|
||||||
|
// CONTAINER path (dataRoot maps to /var/lib/mosaic in the image).
|
||||||
|
const spawnEnv = { ...process.env };
|
||||||
|
spawnEnv.MOSAIC_ADAPTER = resolved.execution.adapter;
|
||||||
|
if (task.missionSnapshot) {
|
||||||
|
const relative = path.relative(resolved.dataRoot, runDir);
|
||||||
|
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
||||||
|
fail(4, `run directory is outside the configured dataRoot: ${runDir}`);
|
||||||
|
}
|
||||||
|
spawnEnv.MOSAIC_MISSION_FILE = `/var/lib/mosaic/${relative.split(path.sep).join("/")}/mission.json`;
|
||||||
|
}
|
||||||
|
|
||||||
const proc = spawnSync(
|
const proc = spawnSync(
|
||||||
"docker",
|
"docker",
|
||||||
["compose", "run", "--rm", "-T", "mosaic-agent", task.prompt],
|
["compose", "run", "--rm", "-T", "mosaic-agent", task.prompt],
|
||||||
{
|
{
|
||||||
cwd: PROJECT_ROOT,
|
cwd: PROJECT_ROOT,
|
||||||
env: process.env, // MOSAIC_DATA_ROOT / MOSAIC_PROVIDER / MOSAIC_MODEL resolved by run-task.sh
|
env: spawnEnv,
|
||||||
input: "", // stdin detached: print mode must never wait on a terminal (see issue #5)
|
input: "", // stdin detached: print mode must never wait on a terminal (see issue #5)
|
||||||
encoding: "utf8",
|
encoding: "utf8",
|
||||||
maxBuffer: 16 * 1024 * 1024,
|
maxBuffer: 16 * 1024 * 1024,
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ trap 'rm -rf "$SANDBOX"' EXIT
|
|||||||
PASS=0
|
PASS=0
|
||||||
FAIL=0
|
FAIL=0
|
||||||
|
|
||||||
|
check() {
|
||||||
|
if [ "$2" = "0" ]; then PASS=$((PASS+1)); echo "ok $1"; else FAIL=$((FAIL+1)); echo "FAIL $1"; fi
|
||||||
|
}
|
||||||
|
|
||||||
# expect_exit NAME EXPECTED_RC -- command...
|
# expect_exit NAME EXPECTED_RC -- command...
|
||||||
expect_exit() {
|
expect_exit() {
|
||||||
local name="$1" expected="$2"
|
local name="$1" expected="$2"
|
||||||
@@ -40,6 +44,20 @@ cfg() { printf '%s' "$2" > "$SANDBOX/$1"; }
|
|||||||
|
|
||||||
DATA_ROOT="$SANDBOX/data"
|
DATA_ROOT="$SANDBOX/data"
|
||||||
|
|
||||||
|
# --- adapter selection (M4) ---
|
||||||
|
cfg default-adapter.json '{"configVersion":1,"environment":"development","dataRoot":"'$DATA_ROOT'","execution":{"backend":"docker","provider":"zai","model":"m"}}'
|
||||||
|
MOSAIC_CONFIG="$SANDBOX/default-adapter.json" $CONFIG_OP validate | grep -q '"adapter": "pi"'
|
||||||
|
check "absent adapter defaults to pi" $?
|
||||||
|
|
||||||
|
cfg mock-adapter.json '{"configVersion":1,"environment":"development","dataRoot":"'$DATA_ROOT'","execution":{"backend":"docker","provider":"zai","model":"m","adapter":"mock"}}'
|
||||||
|
expect_exit "adapter mock validates" 0 -- env MOSAIC_CONFIG="$SANDBOX/mock-adapter.json" $CONFIG_OP validate
|
||||||
|
|
||||||
|
cfg bad-adapter.json '{"configVersion":1,"environment":"development","dataRoot":"'$DATA_ROOT'","execution":{"backend":"docker","provider":"zai","model":"m","adapter":"claude"}}'
|
||||||
|
expect_exit "unsupported adapter exits 2" 2 -- env MOSAIC_CONFIG="$SANDBOX/bad-adapter.json" $CONFIG_OP validate
|
||||||
|
|
||||||
|
MOSAIC_CONFIG="$SANDBOX/mock-adapter.json" $CONFIG_OP env | grep -q "MOSAIC_ADAPTER='mock'"
|
||||||
|
check "env exports adapter" $?
|
||||||
|
|
||||||
# --- bootstrap ---
|
# --- bootstrap ---
|
||||||
rm -f "$SANDBOX/config.json"
|
rm -f "$SANDBOX/config.json"
|
||||||
expect_exit "bootstrap creates default when absent" 0 -- \
|
expect_exit "bootstrap creates default when absent" 0 -- \
|
||||||
|
|||||||
+57
-2
@@ -30,6 +30,16 @@ check() {
|
|||||||
if [ "$2" = "0" ]; then PASS=$((PASS+1)); echo "ok $1"; else FAIL=$((FAIL+1)); echo "FAIL $1"; fi
|
if [ "$2" = "0" ]; then PASS=$((PASS+1)); echo "ok $1"; else FAIL=$((FAIL+1)); echo "FAIL $1"; fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
latest_reason() {
|
||||||
|
local latest
|
||||||
|
latest="$(ls -dt "$SANDBOX/data/runs"/r-* 2>/dev/null | head -1)"
|
||||||
|
[ -n "$latest" ] && node -e 'try{const r=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8"));console.log(r.reason??"")}catch{console.log("")}' "$latest/result.json" 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
check() {
|
||||||
|
if [ "$2" = "0" ]; then PASS=$((PASS+1)); echo "ok $1"; else FAIL=$((FAIL+1)); echo "FAIL $1"; fi
|
||||||
|
}
|
||||||
|
|
||||||
CONFIG="$SANDBOX/config.json"
|
CONFIG="$SANDBOX/config.json"
|
||||||
DATA_ROOT="$SANDBOX/data"
|
DATA_ROOT="$SANDBOX/data"
|
||||||
mkdir -p "$DATA_ROOT"
|
mkdir -p "$DATA_ROOT"
|
||||||
@@ -92,6 +102,50 @@ $TASK validate "$SANDBOX/ok.json" >/dev/null 2>&1
|
|||||||
M2=$(stat -c %Y "$SANDBOX/ok.json")
|
M2=$(stat -c %Y "$SANDBOX/ok.json")
|
||||||
[ "$M1" = "$M2" ] && check "validation does not modify the task file" 0 || check "validation does not modify the task file" 1
|
[ "$M1" = "$M2" ] && check "validation does not modify the task file" 0 || check "validation does not modify the task file" 1
|
||||||
|
|
||||||
|
# ---------- adapter seam: deterministic mock cases (Docker, no provider) ----------
|
||||||
|
if docker info >/dev/null 2>&1; then
|
||||||
|
good_task "$SANDBOX/ok.json"
|
||||||
|
mock_config() { # file adapter
|
||||||
|
cat > "$SANDBOX/$1" <<EOF
|
||||||
|
{"configVersion":1,"environment":"development","dataRoot":"$SANDBOX/data","execution":{"backend":"docker","provider":"zai","model":"m","adapter":"$2"}}
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
mock_config mock-adapters.json mock
|
||||||
|
expect_exit "mock adapter: gate passes on matching mock response" 0 -- \
|
||||||
|
env MOSAIC_CONFIG="$SANDBOX/mock-adapters.json" MOSAIC_MOCK_RESPONSE=MOSAIC_HELLO_OK \
|
||||||
|
scripts/run-task.sh run "$SANDBOX/ok.json"
|
||||||
|
|
||||||
|
expect_exit "mock adapter: expect-mismatch recorded" 1 -- \
|
||||||
|
env MOSAIC_CONFIG="$SANDBOX/mock-adapters.json" MOSAIC_MOCK_RESPONSE=SOMETHING_ELSE \
|
||||||
|
scripts/run-task.sh run "$SANDBOX/ok.json"
|
||||||
|
[ "$(latest_reason)" = "expect-mismatch" ] \
|
||||||
|
&& check "mismatch reason recorded" 0 || check "mismatch reason recorded" 1
|
||||||
|
|
||||||
|
mock_config bad-adapter.json nonexistent
|
||||||
|
# The config layer rejects unknown adapters first, so run-task.sh fails
|
||||||
|
# closed (exit 1) before any container or run record exists.
|
||||||
|
expect_exit "unknown adapter fails closed" 1 -- \
|
||||||
|
env MOSAIC_CONFIG="$SANDBOX/bad-adapter.json" scripts/run-task.sh run "$SANDBOX/ok.json"
|
||||||
|
|
||||||
|
good_mission "$SANDBOX/m-ok.json"
|
||||||
|
printf '{"taskVersion":1,"id":"t-mission","prompt":"ignored by mock","mission":"m-ok.json"}' > "$SANDBOX/mission-task.json"
|
||||||
|
# Dedicated mission with distinctive directives for the injection assertion.
|
||||||
|
cat > "$SANDBOX/m-seam.json" <<'EOF'
|
||||||
|
{"missionVersion":1,"id":"m-seam","objective":"Prove the mission injection point.","directives":["Seam directive A.","Seam directive B."]}
|
||||||
|
EOF
|
||||||
|
printf '{"taskVersion":1,"id":"t-mission-seam","prompt":"ignored by mock","mission":"m-seam.json"}' > "$SANDBOX/seam-task.json"
|
||||||
|
expect_exit "mission task runs via mock adapter" 0 -- \
|
||||||
|
env MOSAIC_CONFIG="$SANDBOX/mock-adapters.json" MOSAIC_MOCK_RESPONSE=MOCKED \
|
||||||
|
scripts/run-task.sh run "$SANDBOX/seam-task.json"
|
||||||
|
grep -q 'MISSION (runtime)' "$SANDBOX/data/system-prompt.md" \
|
||||||
|
&& grep -q 'Seam directive A.' "$SANDBOX/data/system-prompt.md" \
|
||||||
|
&& check "mission section injected into generated prompt" 0 \
|
||||||
|
|| check "mission section injected into generated prompt" 1
|
||||||
|
else
|
||||||
|
echo "skip adapter seam cases (docker daemon unavailable)"
|
||||||
|
fi
|
||||||
|
|
||||||
# ---------- live: real runs (Docker + credentials required) ----------
|
# ---------- live: real runs (Docker + credentials required) ----------
|
||||||
# On failure, surface the run record + agent stderr BEFORE the sandbox
|
# On failure, surface the run record + agent stderr BEFORE the sandbox
|
||||||
# cleanup destroys them. Never let a wrong-exit mask the real reason.
|
# cleanup destroys them. Never let a wrong-exit mask the real reason.
|
||||||
@@ -115,14 +169,15 @@ latest_reason() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if docker info >/dev/null 2>&1; then
|
if docker info >/dev/null 2>&1; then
|
||||||
|
RUNS1=$(ls "$DATA_ROOT/runs" 2>/dev/null | wc -l)
|
||||||
if scripts/run-task.sh run "$SANDBOX/ok.json" >/dev/null 2>&1; then
|
if scripts/run-task.sh run "$SANDBOX/ok.json" >/dev/null 2>&1; then
|
||||||
PASS=$((PASS+1)); echo "ok live hello task succeeds with exact marker"
|
PASS=$((PASS+1)); echo "ok live hello task succeeds with exact marker"
|
||||||
else
|
else
|
||||||
FAIL=$((FAIL+1)); echo "FAIL live hello task succeeds with exact marker" >&2
|
FAIL=$((FAIL+1)); echo "FAIL live hello task succeeds with exact marker" >&2
|
||||||
dump_latest_run
|
dump_latest_run
|
||||||
fi
|
fi
|
||||||
[ -f "$DATA_ROOT/runs" ] && RUNS1=$(ls "$DATA_ROOT/runs" | wc -l)
|
|
||||||
R1="$(ls "$DATA_ROOT/runs" | head -1)"
|
R1="$(ls -t "$DATA_ROOT/runs" | head -1)" # newest = the live run above
|
||||||
[ -f "$DATA_ROOT/runs/$R1/result.json" ] && check "result.json written in run dir" 0 || check "result.json written in run dir" 1
|
[ -f "$DATA_ROOT/runs/$R1/result.json" ] && check "result.json written in run dir" 0 || check "result.json written in run dir" 1
|
||||||
node -e '
|
node -e '
|
||||||
const r = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"));
|
const r = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"));
|
||||||
|
|||||||
@@ -33,5 +33,23 @@ for f in $FILES; do
|
|||||||
printf '\n' >> "$TEMP"
|
printf '\n' >> "$TEMP"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Sanctioned mission injection point (M4): when the task runner provides a
|
||||||
|
# mission snapshot, its objective and directives are appended AFTER the
|
||||||
|
# immutable contracts. Runtime data; never part of the contract fixtures.
|
||||||
|
if [ -n "${MOSAIC_MISSION_FILE:-}" ]; then
|
||||||
|
if [ ! -r "$MOSAIC_MISSION_FILE" ]; then
|
||||||
|
echo "load-contracts: MOSAIC_MISSION_FILE set but not readable: $MOSAIC_MISSION_FILE" >&2
|
||||||
|
rm -f "$TEMP"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
printf '===== MISSION (runtime) =====\n' >> "$TEMP"
|
||||||
|
node -e '
|
||||||
|
const m = JSON.parse(require("fs").readFileSync(process.env.MOSAIC_MISSION_FILE, "utf8"));
|
||||||
|
process.stdout.write("Objective: " + m.objective + "\n");
|
||||||
|
for (const d of m.directives ?? []) process.stdout.write("- " + d + "\n");
|
||||||
|
' >> "$TEMP"
|
||||||
|
printf '\n' >> "$TEMP"
|
||||||
|
fi
|
||||||
|
|
||||||
mv "$TEMP" "$OUT"
|
mv "$TEMP" "$OUT"
|
||||||
echo "load-contracts: wrote $OUT from $CONTRACT_DIR" >&2
|
echo "load-contracts: wrote $OUT from $CONTRACT_DIR" >&2
|
||||||
|
|||||||
+26
-31
@@ -1,38 +1,33 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# One-shot Pi agent runner inside the container.
|
# One-shot agent dispatcher inside the container.
|
||||||
# Loads the contract-generated system prompt, then sends exactly one
|
#
|
||||||
# user request through Pi's documented noninteractive mode and prints
|
# 1. Loads the contract-generated system prompt (contracts + optional
|
||||||
# the model response on stdout.
|
# mission section from MOSAIC_MISSION_FILE).
|
||||||
|
# 2. Dispatches to /opt/mosaic/adapters/<MOSAIC_ADAPTER>/adapter.sh per
|
||||||
|
# the contract in /opt/mosaic/adapters/README.md.
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
: "${PI_PROVIDER:=zai}"
|
|
||||||
: "${PI_MODEL:=glm-5.3-flash}"
|
|
||||||
export PI_PROVIDER PI_MODEL
|
|
||||||
|
|
||||||
REQUEST="${*:-Return your startup marker and nothing else.}"
|
REQUEST="${*:-Return your startup marker and nothing else.}"
|
||||||
|
|
||||||
|
ADAPTER="${MOSAIC_ADAPTER:-pi}"
|
||||||
|
case "$ADAPTER" in
|
||||||
|
# Allowlist mirrors scripts/mosaic-config.mjs; pattern check first so a
|
||||||
|
# crafted name cannot escape the adapters directory.
|
||||||
|
*[!A-Za-z0-9._-]*|'')
|
||||||
|
echo "run-agent: invalid adapter name: '$ADAPTER'" >&2
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
ADAPTER_SCRIPT="/opt/mosaic/adapters/$ADAPTER/adapter.sh"
|
||||||
|
if [ ! -x "$ADAPTER_SCRIPT" ]; then
|
||||||
|
echo "run-agent: unknown or non-executable adapter: $ADAPTER" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
/opt/mosaic/src/load-contracts.sh /opt/mosaic/contracts /var/lib/mosaic/system-prompt.md
|
/opt/mosaic/src/load-contracts.sh /opt/mosaic/contracts /var/lib/mosaic/system-prompt.md
|
||||||
|
|
||||||
# All flags are documented in the package README (CLI Reference):
|
export MOSAIC_SYSTEM_PROMPT_FILE="/var/lib/mosaic/system-prompt.md"
|
||||||
# -p / --print noninteractive: print the response and exit
|
export MOSAIC_REQUEST="$REQUEST"
|
||||||
# --system-prompt replace the default system prompt with the
|
|
||||||
# contract-generated prompt
|
exec "$ADAPTER_SCRIPT"
|
||||||
# --no-* switches prevent ambient context files, skills, extensions,
|
|
||||||
# prompt templates, and themes from being appended
|
|
||||||
# --no-session ephemeral: no persistent agent session
|
|
||||||
# --no-tools the startup request needs no tool execution
|
|
||||||
# --offline disable startup network operations (update checks,
|
|
||||||
# package update checks, install/update telemetry)
|
|
||||||
exec pi \
|
|
||||||
--offline \
|
|
||||||
--no-session \
|
|
||||||
--no-extensions \
|
|
||||||
--no-skills \
|
|
||||||
--no-prompt-templates \
|
|
||||||
--no-themes \
|
|
||||||
--no-context-files \
|
|
||||||
--no-tools \
|
|
||||||
--provider "$PI_PROVIDER" \
|
|
||||||
--model "$PI_MODEL" \
|
|
||||||
--system-prompt "$(cat /var/lib/mosaic/system-prompt.md)" \
|
|
||||||
-p "$REQUEST"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user