@junghanacs/entwurf 0.12.9 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +135 -248
- package/BASELINE.md +46 -7
- package/CHANGELOG.md +35 -0
- package/CONTRIBUTING.md +4 -2
- package/DELIVERY.md +5 -4
- package/README.md +46 -18
- package/VERIFY.md +10 -6
- package/demo/demo.sh +7 -1
- package/docs/setup-clean-host.md +10 -4
- package/mcp/entwurf-bridge/dist/mcp/entwurf-bridge/src/index.js +159 -66
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/backend-adapter.js +148 -5
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/config.js +16 -4
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/models.js +66 -7
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/overlay.js +190 -3
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/tool-surface.js +12 -4
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-core.js +26 -9
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-deliverability.js +10 -6
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-fact-provider.js +15 -17
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-facts.js +13 -13
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-resume-args.js +31 -41
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-self-address.js +8 -9
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-v2-contract.js +32 -25
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-v2-decider.js +4 -4
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-v2-lock.js +5 -4
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-v2-production.js +9 -11
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-v2-spawn-production.js +3 -1
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/meta-session.js +17 -20
- package/mcp/entwurf-bridge/src/index.ts +190 -82
- package/package.json +7 -3
- package/pi/settings.reference.json +1 -1
- package/pi-extensions/acp-provider.ts +20 -10
- package/pi-extensions/entwurf-control.ts +69 -27
- package/pi-extensions/lib/acp/augment.ts +60 -2
- package/pi-extensions/lib/acp/backend-adapter.ts +183 -8
- package/pi-extensions/lib/acp/backend.ts +5 -1
- package/pi-extensions/lib/acp/config.ts +19 -5
- package/pi-extensions/lib/acp/engraving.ts +3 -1
- package/pi-extensions/lib/acp/event-mapper.ts +10 -3
- package/pi-extensions/lib/acp/models.ts +69 -7
- package/pi-extensions/lib/acp/overlay.ts +234 -3
- package/pi-extensions/lib/acp/tool-surface.ts +12 -4
- package/pi-extensions/lib/entwurf-core.ts +26 -9
- package/pi-extensions/lib/entwurf-deliverability.ts +10 -6
- package/pi-extensions/lib/entwurf-fact-provider.ts +15 -17
- package/pi-extensions/lib/entwurf-facts.ts +13 -13
- package/pi-extensions/lib/entwurf-resume-args.ts +40 -46
- package/pi-extensions/lib/entwurf-self-address.ts +8 -9
- package/pi-extensions/lib/entwurf-v2-contract-schema.ts +7 -2
- package/pi-extensions/lib/entwurf-v2-contract.ts +32 -25
- package/pi-extensions/lib/entwurf-v2-decider.ts +8 -8
- package/pi-extensions/lib/entwurf-v2-lock.ts +5 -4
- package/pi-extensions/lib/entwurf-v2-production.ts +14 -11
- package/pi-extensions/lib/entwurf-v2-spawn-production.ts +3 -1
- package/pi-extensions/lib/meta-session.ts +17 -20
- package/run.sh +200 -62
- package/scripts/agy-bridge-config.py +249 -49
- package/scripts/agy-bridge.sh +59 -14
- package/scripts/check-acp-carrier-augment.ts +34 -2
- package/scripts/check-acp-cortex.ts +668 -0
- package/scripts/check-acp-provider-surface.ts +50 -6
- package/scripts/check-acp-sdk-surface.ts +22 -11
- package/scripts/check-acp-session-reuse.ts +64 -1
- package/scripts/check-agy-permission-matrix.py +655 -0
- package/scripts/check-entwurf-deliverability.ts +9 -6
- package/scripts/check-entwurf-fact-provider.ts +7 -7
- package/scripts/check-entwurf-facts.ts +12 -12
- package/scripts/check-entwurf-resume-args.ts +22 -60
- package/scripts/check-entwurf-self-address.ts +187 -4
- package/scripts/check-entwurf-v2-contract.ts +2 -2
- package/scripts/check-entwurf-v2-production.ts +5 -5
- package/scripts/check-entwurf-v2-spawn-production.ts +6 -2
- package/scripts/check-entwurf-v2-surface.ts +327 -14
- package/scripts/check-gate-qualification.ts +787 -0
- package/scripts/check-meta-identity-consumers.ts +1 -1
- package/scripts/check-probe-cli-shim.ts +879 -0
- package/scripts/check-probe-ordering.ts +2450 -0
- package/scripts/check-shell-quote.ts +5 -4
- package/scripts/fixtures/probe-cli-shim +20 -0
- package/scripts/fixtures/probe-mcp-server.ts +168 -12
- package/scripts/lib/mutation-qualify.ts +794 -0
- package/scripts/lib/probe-acp-turn.ts +207 -0
- package/scripts/lib/probe-cli-shim.ts +464 -0
- package/scripts/lib/probe-cli-target.ts +165 -0
- package/scripts/lib/probe-event-log.ts +383 -0
- package/scripts/lib/probe-verdict.ts +1213 -0
- package/scripts/mutants/acp-augment.json +30 -0
- package/scripts/mutants/acp-cortex.json +196 -0
- package/scripts/mutants/agy-permission.json +144 -0
- package/scripts/mutants/meta-identity.json +17 -0
- package/scripts/mutants/probe-ordering.json +1032 -0
- package/scripts/mutants/self-address.json +59 -0
- package/scripts/mutants/v2-surface.json +87 -0
- package/scripts/smoke-acp-cortex-live.ts +392 -0
- package/scripts/smoke-acp-ordering-probe-live.ts +848 -0
- package/scripts/smoke-acp-raw-turn-live.ts +1 -1
- package/scripts/smoke-acp-v2-send-live.ts +33 -18
- package/scripts/smoke-agy-install-state.sh +205 -20
- package/scripts/smoke-entwurf-v2-matrix-live.ts +3 -2
- package/pi-extensions/lib/entwurf-mailbox-guard.ts +0 -100
- package/scripts/check-entwurf-mailbox-guard.ts +0 -266
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"lane": "self-address",
|
|
4
|
+
"mutants": [
|
|
5
|
+
{
|
|
6
|
+
"claim": "SELFADDR-RAIL-RENDER",
|
|
7
|
+
"title": "entwurf_self reverts to an empty self-fetch guard + unconditional mailbox render (ordering-not-containment)",
|
|
8
|
+
"subject": "mcp/entwurf-bridge/src/index.ts",
|
|
9
|
+
"find": [
|
|
10
|
+
"\t\t\t\tif (rail === \"self-fetch\") {",
|
|
11
|
+
"\t\t\t\t\tconst mailboxPath = path.join(defaultMetaMailboxDir(), sender.sessionId);",
|
|
12
|
+
"\t\t\t\t\textra.mailboxPath = mailboxPath;",
|
|
13
|
+
"\t\t\t\t\tlines.push(`mailboxPath: ${mailboxPath}`);",
|
|
14
|
+
"\t\t\t\t} else if (rail === \"native-push\") {"
|
|
15
|
+
],
|
|
16
|
+
"replace": [
|
|
17
|
+
"\t\t\t\tif (rail === \"self-fetch\") {",
|
|
18
|
+
"\t\t\t\t}",
|
|
19
|
+
"\t\t\t\tconst mailboxPath = path.join(defaultMetaMailboxDir(), sender.sessionId);",
|
|
20
|
+
"\t\t\t\textra.mailboxPath = mailboxPath;",
|
|
21
|
+
"\t\t\t\tlines.push(`mailboxPath: ${mailboxPath}`);",
|
|
22
|
+
"\t\t\t\tif (rail === \"native-push\") {"
|
|
23
|
+
],
|
|
24
|
+
"gate": ["bash", "run.sh", "check-entwurf-self-address"],
|
|
25
|
+
"timeoutSeconds": 60,
|
|
26
|
+
"signature": "[QK:SELFADDR-RAIL-RENDER]",
|
|
27
|
+
"signatureSource": "scripts/check-entwurf-self-address.ts"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"claim": "SELFADDR-NO-HARDCODED-REPLYABLE",
|
|
31
|
+
"title": "buildStrictPiSenderEnvelope hardcodes replyable: true again (env presence read as reachability)",
|
|
32
|
+
"subject": "mcp/entwurf-bridge/src/index.ts",
|
|
33
|
+
"find": ["\t\torigin: \"pi-session\",", "\t\treplyable: self.replyable,", "\t};", "}"],
|
|
34
|
+
"replace": ["\t\torigin: \"pi-session\",", "\t\treplyable: true,", "\t};", "}"],
|
|
35
|
+
"gate": ["bash", "run.sh", "check-entwurf-self-address"],
|
|
36
|
+
"timeoutSeconds": 60,
|
|
37
|
+
"signature": "[QK:SELFADDR-NO-HARDCODED-REPLYABLE]",
|
|
38
|
+
"signatureSource": "scripts/check-entwurf-self-address.ts"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"claim": "SELFADDR-RAIL-FACT-LEAK",
|
|
42
|
+
"title": "the native-push predicate lets a mailbox fact (watchArmed) buy replyability — behavioral, not text",
|
|
43
|
+
"subject": "pi-extensions/lib/entwurf-self-address.ts",
|
|
44
|
+
"find": [
|
|
45
|
+
"\t\t\t\t\tconst push = nativePushDeliverable({ recordBacked: facts.recordBacked, probeAlive: facts.probeAlive });"
|
|
46
|
+
],
|
|
47
|
+
"replace": [
|
|
48
|
+
"\t\t\t\t\tconst push = nativePushDeliverable({",
|
|
49
|
+
"\t\t\t\t\t\trecordBacked: facts.recordBacked,",
|
|
50
|
+
"\t\t\t\t\t\tprobeAlive: facts.probeAlive === true || facts.watchArmed === true,",
|
|
51
|
+
"\t\t\t\t\t});"
|
|
52
|
+
],
|
|
53
|
+
"gate": ["bash", "run.sh", "check-entwurf-self-address"],
|
|
54
|
+
"timeoutSeconds": 60,
|
|
55
|
+
"signature": "[QK:SELFADDR-RAIL-FACT-LEAK]",
|
|
56
|
+
"signatureSource": "scripts/check-entwurf-self-address.ts"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"lane": "v2-surface",
|
|
4
|
+
"mutants": [
|
|
5
|
+
{
|
|
6
|
+
"claim": "V2SURF-MCP-LOCK-DOMAIN",
|
|
7
|
+
"title": "MCP long description reverts to the false \"socket paths take a per-target lock\" claim",
|
|
8
|
+
"subject": "mcp/entwurf-bridge/src/index.ts",
|
|
9
|
+
"find": [
|
|
10
|
+
"\t\t\"(delivered / rejected / lock-retained / delivered-but-lock-dirty). LOCK POLICY (do not \" +",
|
|
11
|
+
"\t\t\"over-generalize it): the per-target lock is taken for a control-socket-DOMAIN dispatch, which is \" +",
|
|
12
|
+
"\t\t\"both the live send AND the dormant cell's spawn-bg resume — spawn-bg is a separate relaunch \" +",
|
|
13
|
+
"\t\t\"transport yet it still runs under that domain's lock. The mailbox and native-push rails are \" +",
|
|
14
|
+
"\t\t\"lock-free: the mailbox is guarded instead by active-receiver deliverability, and native-push by \" +",
|
|
15
|
+
"\t\t\"its adapter probe. The decider — not the \" +"
|
|
16
|
+
],
|
|
17
|
+
"replace": [
|
|
18
|
+
"\t\t\"(delivered / rejected / lock-retained / delivered-but-lock-dirty). LOCK POLICY: socket paths \" +",
|
|
19
|
+
"\t\t\"take a per-target lock; the mailbox path does not. The decider — not the \" +"
|
|
20
|
+
],
|
|
21
|
+
"gate": ["bash", "run.sh", "check-entwurf-v2-surface"],
|
|
22
|
+
"timeoutSeconds": 60,
|
|
23
|
+
"signature": "[QK:V2SURF-MCP-LOCK-DOMAIN]",
|
|
24
|
+
"signatureSource": "scripts/check-entwurf-v2-surface.ts"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"claim": "V2SURF-PI-MODE-SCOPE",
|
|
28
|
+
"title": "pi-native mode param reverts to \"Delivery mode for a live send\" (false for native-push)",
|
|
29
|
+
"subject": "pi-extensions/entwurf-control.ts",
|
|
30
|
+
"find": [
|
|
31
|
+
"\t\t\t\tdescription:",
|
|
32
|
+
"\t\t\t\t\t\"Injection style for a CONTROL-SOCKET send only: steer (immediate) or follow_up (after task). \" +",
|
|
33
|
+
"\t\t\t\t\t\"The mailbox, native-push, and spawn-bg plans carry no mode, so it has no effect on those rails.\","
|
|
34
|
+
],
|
|
35
|
+
"replace": [
|
|
36
|
+
"\t\t\t\tdescription:",
|
|
37
|
+
"\t\t\t\t\t\"Delivery mode for a live send: steer (immediate, interrupt the current turn) or follow_up \" +",
|
|
38
|
+
"\t\t\t\t\t\"(queued after the current task finishes running to completion).\","
|
|
39
|
+
],
|
|
40
|
+
"gate": ["bash", "run.sh", "check-entwurf-v2-surface"],
|
|
41
|
+
"timeoutSeconds": 60,
|
|
42
|
+
"signature": "[QK:V2SURF-PI-MODE-SCOPE]",
|
|
43
|
+
"signatureSource": "scripts/check-entwurf-v2-surface.ts"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"claim": "V2SURF-INBOX-SCOPE-HONESTY",
|
|
47
|
+
"title": "entwurf_inbox_read reverts to the false \"drains your own inbox\" access claim (SCOPE paragraph gone)",
|
|
48
|
+
"subject": "mcp/entwurf-bridge/src/index.ts",
|
|
49
|
+
"find": [
|
|
50
|
+
"\t\t\"doorbell is only a wake attempt, not a read. An empty inbox mutates nothing. \" +",
|
|
51
|
+
"\t\t\"SCOPE — read this literally: the garden id is CALLER-SUPPLIED and is NOT verified against \" +",
|
|
52
|
+
"\t\t\"your own identity (a host with no garden record of its own can call this too). So passing \" +",
|
|
53
|
+
"\t\t\"another citizen's garden id drains THEIR mail and stamps THEIR receipt, and they will never \" +",
|
|
54
|
+
"\t\t\"see those messages. Pass only the id from your own doorbell notice or your own meta-record; \" +",
|
|
55
|
+
"\t\t\"use entwurf_self if you need to confirm which id that is. \" +"
|
|
56
|
+
],
|
|
57
|
+
"replace": [
|
|
58
|
+
"\t\t\"doorbell is only a wake attempt, not a read. An empty inbox mutates nothing. \" +",
|
|
59
|
+
"\t\t\"This tool drains your own meta-bridge inbox and stamps the read receipt on your meta-record. \" +"
|
|
60
|
+
],
|
|
61
|
+
"gate": ["bash", "run.sh", "check-entwurf-v2-surface"],
|
|
62
|
+
"timeoutSeconds": 60,
|
|
63
|
+
"signature": "[QK:V2SURF-INBOX-SCOPE-HONESTY]",
|
|
64
|
+
"signatureSource": "scripts/check-entwurf-v2-surface.ts"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"claim": "V2SURF-MERGED-REJECT",
|
|
68
|
+
"title": "MCP long description merges the two owned rejects back under backend-liveness-unsupported",
|
|
69
|
+
"subject": "mcp/entwurf-bridge/src/index.ts",
|
|
70
|
+
"find": [
|
|
71
|
+
"\t\t\"owned-outcome is ONLY for waking a DORMANT socket-domain citizen (spawn-bg resume, currently \" +",
|
|
72
|
+
"\t\t\"backend pi); on a live target it is rejected as owned-live-no-autosend. Neither self-fetch nor \" +",
|
|
73
|
+
"\t\t\"native-push has resume authority, but they reject under DIFFERENT reasons — self-fetch as \" +",
|
|
74
|
+
"\t\t\"backend-liveness-unsupported, native-push as native-push-no-resume-authority. \" +"
|
|
75
|
+
],
|
|
76
|
+
"replace": [
|
|
77
|
+
"\t\t\"owned-outcome is ONLY for waking a DORMANT socket-domain citizen (spawn-bg resume, currently \" +",
|
|
78
|
+
"\t\t\"backend pi); on a live target it is rejected as owned-live-no-autosend, and on self-fetch and \" +",
|
|
79
|
+
"\t\t\"native-push alike it is rejected as backend-liveness-unsupported. \" +"
|
|
80
|
+
],
|
|
81
|
+
"gate": ["bash", "run.sh", "check-entwurf-v2-surface"],
|
|
82
|
+
"timeoutSeconds": 60,
|
|
83
|
+
"signature": "[QK:V2SURF-MERGED-REJECT]",
|
|
84
|
+
"signatureSource": "scripts/check-entwurf-v2-surface.ts"
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
// CP2 LIVE — the cortex ACP citizen path, end to end: a REAL `cortex acp serve`
|
|
2
|
+
// child behind the entwurf provider carries a model to outbound sibling
|
|
3
|
+
// dispatch, under the dual-HOME overlay, and is reclaimed by process-group
|
|
4
|
+
// teardown afterwards.
|
|
5
|
+
//
|
|
6
|
+
// LIVE=1 ENTWURF_ACP_CORTEX_CONNECTION=<conn> ./run.sh smoke-acp-cortex-live
|
|
7
|
+
//
|
|
8
|
+
// WHY this exact axis. The CP0 audit (docs/acp-backend-rail.md §11-8) measured
|
|
9
|
+
// three things no offline gate can prove:
|
|
10
|
+
// - D9/D10: cortex ignores the wire `mcpServers` param, so the bundled
|
|
11
|
+
// entwurf-bridge reaches a cortex session ONLY through the overlay-private
|
|
12
|
+
// mcp.json projection — and only the dual-HOME env restore keeps the bridge
|
|
13
|
+
// child's garden store real (an isolated-HOME bridge saw "(none)" citizens).
|
|
14
|
+
// The CP0 LIVE run proved tool exposure + entwurf_peers; the outbound
|
|
15
|
+
// `entwurf_v2` send was DELIBERATELY not exercised there ("흉내내지 않았다")
|
|
16
|
+
// and is owed to THIS smoke.
|
|
17
|
+
// - CP0-M: set-model is accepted live, but "the prompt actually runs on the
|
|
18
|
+
// selected model" needed a model turn — this smoke drives one.
|
|
19
|
+
// - teardown: an MCP-configured cortex child does NOT exit on stdin EOF
|
|
20
|
+
// (measured twice); only process-group signalling reclaims it. This smoke
|
|
21
|
+
// asserts the reclaim actually happens after the resident dies.
|
|
22
|
+
//
|
|
23
|
+
// METHOD — mirrors smoke-acp-v2-send-live: seed an isolated garden world (store
|
|
24
|
+
// + mailbox + receivers) with ONE armed self-fetch receiver, launch a real
|
|
25
|
+
// `pi --entwurf-control --mode rpc` resident on entwurf/cortex-claude-sonnet-5
|
|
26
|
+
// with that world in env, drive one turn telling the model to call
|
|
27
|
+
// `mcp__entwurf-bridge__entwurf_v2` at the seeded receiver with a nonce, then
|
|
28
|
+
// assert ON DISK: the landed .msg, the envelope naming the resident's own gid +
|
|
29
|
+
// entwurf/<cortex model>, the overlay scope dir + its mcp.json projection, and
|
|
30
|
+
// (after teardown) that no process still lives inside this run's overlay.
|
|
31
|
+
//
|
|
32
|
+
// LIVE-only and OUTSIDE the claude-only AGGREGATE release floor (capability
|
|
33
|
+
// dignity): a host that runs no cortex must not redden a claude release. That is
|
|
34
|
+
// a wiring decision — shipping cortex still owes a deliberate run of this smoke,
|
|
35
|
+
// and the aggregate gate's silence is not a pass (rail §11-8 tail).
|
|
36
|
+
// Honest skip when LIVE!=1, when `cortex` is not on PATH, or when
|
|
37
|
+
// ENTWURF_ACP_CORTEX_CONNECTION is unset — the overlay denies the operator's
|
|
38
|
+
// cortex settings.json (where a default connection would live), so the
|
|
39
|
+
// connection must arrive through the adapter's own env/settings seam, and
|
|
40
|
+
// running without one would measure a config hole, not the rail. This gate
|
|
41
|
+
// touches the real host exactly where LIVE gates may: the operator's real
|
|
42
|
+
// cortex auth (read-only through symlinks) and ~/.pi/agent/cortex-overlays.
|
|
43
|
+
//
|
|
44
|
+
// Model override: ENTWURF_ACP_CORTEX_MODEL (default cortex-claude-sonnet-5).
|
|
45
|
+
|
|
46
|
+
import { type ChildProcess, spawn } from "node:child_process";
|
|
47
|
+
import * as crypto from "node:crypto";
|
|
48
|
+
import { existsSync } from "node:fs";
|
|
49
|
+
import * as fsp from "node:fs/promises";
|
|
50
|
+
import * as os from "node:os";
|
|
51
|
+
import * as path from "node:path";
|
|
52
|
+
import * as readline from "node:readline";
|
|
53
|
+
import { fileURLToPath } from "node:url";
|
|
54
|
+
import { upsertMetaSession, writeMetaReceiverMarker } from "../pi-extensions/lib/meta-session.ts";
|
|
55
|
+
import { terminateChild } from "./lib/acp-child-cleanup.ts";
|
|
56
|
+
import { waitForPiRecord } from "./lib/pi-record-discovery.ts";
|
|
57
|
+
|
|
58
|
+
const ACP_PROVIDER = "entwurf";
|
|
59
|
+
const ACP_MODEL = process.env.ENTWURF_ACP_CORTEX_MODEL?.trim() || "cortex-claude-sonnet-5";
|
|
60
|
+
|
|
61
|
+
const REAL_CONTROL_DIR = path.join(os.homedir(), ".pi", "entwurf-control");
|
|
62
|
+
const CORTEX_OVERLAYS_ROOT = path.join(os.homedir(), ".pi", "agent", "cortex-overlays");
|
|
63
|
+
const SOCKET_SUFFIX = ".sock";
|
|
64
|
+
const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
65
|
+
// Load ONLY this checkout's extensions so the resident registers THIS acp-provider.ts.
|
|
66
|
+
const REPO_EXTENSION_ARGS = ["--no-extensions", "-e", REPO_ROOT] as const;
|
|
67
|
+
|
|
68
|
+
const BOOT_TIMEOUT_MS = 30_000;
|
|
69
|
+
// The cortex CLI self-extracts on first launch and its newSession alone is
|
|
70
|
+
// ~2.5 s; keep the generous default of the sibling smoke.
|
|
71
|
+
const TURN_TIMEOUT_MS = Number(process.env.ENTWURF_ACP_CORTEX_TIMEOUT_MS) || 300_000;
|
|
72
|
+
const RECLAIM_TIMEOUT_MS = 20_000;
|
|
73
|
+
const POLL_MS = 100;
|
|
74
|
+
|
|
75
|
+
let passed = 0;
|
|
76
|
+
function ok(label: string, cond: boolean): void {
|
|
77
|
+
if (!cond) throw new Error(`SMOKE FAIL: ${label}`);
|
|
78
|
+
console.log(` ok ${label}`);
|
|
79
|
+
passed++;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function writeFailureArtifact(cap: { stream: string } | null, stderrTail: string, err: unknown): Promise<void> {
|
|
83
|
+
try {
|
|
84
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
85
|
+
const file = path.join(os.tmpdir(), `entwurf-smoke-acp-cortex-live-FAIL-${stamp}.log`);
|
|
86
|
+
await fsp.writeFile(
|
|
87
|
+
file,
|
|
88
|
+
`# smoke-acp-cortex-live FAILURE\n# ${err instanceof Error ? err.message : String(err)}\n` +
|
|
89
|
+
`# model: ${ACP_PROVIDER}/${ACP_MODEL}\n\n` +
|
|
90
|
+
`## event stream\n${cap?.stream ?? "(no turn captured)"}\n\n` +
|
|
91
|
+
`## resident stderr tail\n${stderrTail || "(empty)"}\n`,
|
|
92
|
+
"utf8",
|
|
93
|
+
);
|
|
94
|
+
console.error(`[smoke-acp-cortex-live] FAILURE transcript: ${file}`);
|
|
95
|
+
} catch {
|
|
96
|
+
console.error("[smoke-acp-cortex-live] could not write the failure transcript (reporting the original error)");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function sleep(ms: number): Promise<void> {
|
|
101
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function waitForSocket(sockPath: string, timeoutMs: number): Promise<boolean> {
|
|
105
|
+
const deadline = Date.now() + timeoutMs;
|
|
106
|
+
while (Date.now() < deadline) {
|
|
107
|
+
if (existsSync(sockPath)) return true;
|
|
108
|
+
await sleep(POLL_MS);
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** pids (other than ours) whose environ carries `needle` — the overlay scope
|
|
114
|
+
* path is unique per run, so this finds exactly the cortex child + its
|
|
115
|
+
* grandchildren, never an unrelated operator cortex. Foreign-user /proc
|
|
116
|
+
* entries EACCES-skip (they cannot be our children). */
|
|
117
|
+
async function pidsWithEnvNeedle(needle: string): Promise<number[]> {
|
|
118
|
+
const hits: number[] = [];
|
|
119
|
+
const entries = await fsp.readdir("/proc").catch(() => [] as string[]);
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
if (!/^\d+$/.test(entry)) continue;
|
|
122
|
+
const pid = Number(entry);
|
|
123
|
+
if (pid === process.pid) continue;
|
|
124
|
+
try {
|
|
125
|
+
const environ = await fsp.readFile(path.join("/proc", entry, "environ"), "utf8");
|
|
126
|
+
if (environ.includes(needle)) hits.push(pid);
|
|
127
|
+
} catch {
|
|
128
|
+
// gone or not ours — either way not a leak we own
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return hits;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
interface TurnCapture {
|
|
135
|
+
agentStartSeen: boolean;
|
|
136
|
+
agentEndSeen: boolean;
|
|
137
|
+
extensionErrors: Array<{ path: unknown; event: unknown; error: unknown }>;
|
|
138
|
+
promptAccepted: boolean;
|
|
139
|
+
stream: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Drive exactly one model turn over the resident's stdin RPC and capture the
|
|
143
|
+
// stdout event stream until `agent_end` (or the hard turn timeout).
|
|
144
|
+
function driveTurn(child: ChildProcess, prompt: string): Promise<TurnCapture> {
|
|
145
|
+
return new Promise((resolve) => {
|
|
146
|
+
const cap: TurnCapture = {
|
|
147
|
+
agentStartSeen: false,
|
|
148
|
+
agentEndSeen: false,
|
|
149
|
+
extensionErrors: [],
|
|
150
|
+
promptAccepted: false,
|
|
151
|
+
stream: "",
|
|
152
|
+
};
|
|
153
|
+
let settled = false;
|
|
154
|
+
const finish = (): void => {
|
|
155
|
+
if (settled) return;
|
|
156
|
+
settled = true;
|
|
157
|
+
clearTimeout(timer);
|
|
158
|
+
rl.close();
|
|
159
|
+
resolve(cap);
|
|
160
|
+
};
|
|
161
|
+
const timer = setTimeout(finish, TURN_TIMEOUT_MS);
|
|
162
|
+
child.once("exit", finish);
|
|
163
|
+
|
|
164
|
+
const rl = readline.createInterface({ input: child.stdout! });
|
|
165
|
+
rl.on("line", (line: string) => {
|
|
166
|
+
const trimmed = line.trim();
|
|
167
|
+
if (!trimmed) return;
|
|
168
|
+
cap.stream += `${trimmed}\n`;
|
|
169
|
+
let evt: Record<string, unknown>;
|
|
170
|
+
try {
|
|
171
|
+
evt = JSON.parse(trimmed) as Record<string, unknown>;
|
|
172
|
+
} catch {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (evt.type === "agent_start") cap.agentStartSeen = true;
|
|
176
|
+
if (evt.type === "extension_error") {
|
|
177
|
+
cap.extensionErrors.push({ path: evt.extensionPath, event: evt.event, error: evt.error });
|
|
178
|
+
}
|
|
179
|
+
if (evt.type === "response" && evt.command === "prompt") cap.promptAccepted = evt.success === true;
|
|
180
|
+
if (evt.type === "agent_end") {
|
|
181
|
+
cap.agentEndSeen = true;
|
|
182
|
+
finish();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
child.stdin?.write(`${JSON.stringify({ type: "prompt", message: prompt, id: "cortexv2" })}\n`);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function main(): Promise<void> {
|
|
191
|
+
if (process.env.LIVE !== "1") {
|
|
192
|
+
console.log(
|
|
193
|
+
"[smoke-acp-cortex-live] skipped — set LIVE=1 to run (spawns a real cortex ACP resident + one model turn).",
|
|
194
|
+
);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const connection = process.env.ENTWURF_ACP_CORTEX_CONNECTION?.trim();
|
|
198
|
+
if (!connection) {
|
|
199
|
+
console.log(
|
|
200
|
+
"[smoke-acp-cortex-live] skipped — set ENTWURF_ACP_CORTEX_CONNECTION=<snowflake connection> (the dual-HOME " +
|
|
201
|
+
"overlay denies the operator cortex settings.json, so the connection must ride the adapter's own seam).",
|
|
202
|
+
);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if ("CORTEX_HOME" in process.env) {
|
|
206
|
+
console.log(
|
|
207
|
+
"[smoke-acp-cortex-live] skipped — unset CORTEX_HOME first (the adapter refuses its presence, CP0 D3).",
|
|
208
|
+
);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// One temp root holding the whole garden this smoke can see: store, mailbox
|
|
213
|
+
// and receiver markers. Only these move — the operator's real cortex auth
|
|
214
|
+
// (via overlay symlinks) and the control dir stay real.
|
|
215
|
+
const world = await fsp.mkdtemp(path.join(os.tmpdir(), "acp-cortex-"));
|
|
216
|
+
const sessionsDir = path.join(world, "sessions");
|
|
217
|
+
const mailboxDir = path.join(world, "mailbox");
|
|
218
|
+
const receiversDir = path.join(world, "receivers");
|
|
219
|
+
for (const d of [sessionsDir, mailboxDir, receiversDir]) await fsp.mkdir(d, { recursive: true });
|
|
220
|
+
|
|
221
|
+
const nonce = `CORTEXV2-${crypto.randomBytes(5).toString("hex").toUpperCase()}`;
|
|
222
|
+
|
|
223
|
+
console.error(`[smoke-acp-cortex-live] repo: ${REPO_ROOT}`);
|
|
224
|
+
console.error(`[smoke-acp-cortex-live] model: ${ACP_PROVIDER}/${ACP_MODEL} (connection ${connection})`);
|
|
225
|
+
console.error(`[smoke-acp-cortex-live] world: ${world}`);
|
|
226
|
+
|
|
227
|
+
// ── the peer: an armed self-fetch citizen, deliverable by the mailbox rail ──
|
|
228
|
+
const receiver = upsertMetaSession({
|
|
229
|
+
input: { backend: "claude-code", nativeSessionId: `acp-cortex-${process.pid}`, cwd: world },
|
|
230
|
+
dir: sessionsDir,
|
|
231
|
+
});
|
|
232
|
+
const receiverGid = receiver.record.gardenId;
|
|
233
|
+
writeMetaReceiverMarker({
|
|
234
|
+
gardenId: receiverGid,
|
|
235
|
+
backend: "claude-code",
|
|
236
|
+
nativeSessionId: receiver.record.nativeSessionId,
|
|
237
|
+
ownerPid: process.pid,
|
|
238
|
+
armProvenance: "session-start",
|
|
239
|
+
receiversDir,
|
|
240
|
+
});
|
|
241
|
+
console.error(`[smoke-acp-cortex-live] peer: ${receiverGid} (armed mailbox receiver)`);
|
|
242
|
+
|
|
243
|
+
let senderGid = "";
|
|
244
|
+
let stderrTail = "";
|
|
245
|
+
let resident: ChildProcess | null = null;
|
|
246
|
+
let cap: TurnCapture | null = null;
|
|
247
|
+
let overlayScopeDir = "";
|
|
248
|
+
try {
|
|
249
|
+
resident = spawn(
|
|
250
|
+
"pi",
|
|
251
|
+
[...REPO_EXTENSION_ARGS, "--entwurf-control", "--provider", ACP_PROVIDER, "--model", ACP_MODEL, "--mode", "rpc"],
|
|
252
|
+
{
|
|
253
|
+
cwd: world,
|
|
254
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
255
|
+
detached: false,
|
|
256
|
+
env: {
|
|
257
|
+
...process.env,
|
|
258
|
+
ENTWURF_META_SESSIONS_DIR: sessionsDir,
|
|
259
|
+
ENTWURF_META_MAILBOX_DIR: mailboxDir,
|
|
260
|
+
ENTWURF_META_RECEIVERS_DIR: receiversDir,
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
);
|
|
264
|
+
resident.stderr?.on("data", (b: Buffer) => {
|
|
265
|
+
stderrTail = (stderrTail + b.toString()).slice(-4000);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const bornGid = await waitForPiRecord(sessionsDir, BOOT_TIMEOUT_MS);
|
|
269
|
+
ok(`cortex-model resident birthed its own V3 record (${ACP_PROVIDER}/${ACP_MODEL})`, bornGid !== null);
|
|
270
|
+
senderGid = bornGid as string;
|
|
271
|
+
console.error(`[smoke-acp-cortex-live] sender:${senderGid} (never told to the model)`);
|
|
272
|
+
ok("sender and receiver are distinct citizens", senderGid !== receiverGid);
|
|
273
|
+
const sockPath = path.join(REAL_CONTROL_DIR, `${senderGid}${SOCKET_SUFFIX}`);
|
|
274
|
+
ok(
|
|
275
|
+
"resident stood up a control socket keyed on its record gardenId",
|
|
276
|
+
await waitForSocket(sockPath, BOOT_TIMEOUT_MS),
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
// The prompt names the TARGET but never the sender's own gid — that can
|
|
280
|
+
// only reach the mailbox via the real envelope the projection carried.
|
|
281
|
+
const prompt =
|
|
282
|
+
`Call the mcp__entwurf-bridge__entwurf_v2 tool exactly once with these arguments: ` +
|
|
283
|
+
`target="${receiverGid}", intent="fire-and-forget", message="${nonce}". ` +
|
|
284
|
+
`Then reply with ONLY the tool's outcome line.`;
|
|
285
|
+
cap = await driveTurn(resident, prompt);
|
|
286
|
+
|
|
287
|
+
ok("the prompt RPC command was accepted", cap.promptAccepted);
|
|
288
|
+
ok("a real model turn ran over the stdin RPC (agent_start)", cap.agentStartSeen);
|
|
289
|
+
ok("the turn completed cleanly over RPC (agent_end — no hang)", cap.agentEndSeen);
|
|
290
|
+
ok("no extension_error during the turn", cap.extensionErrors.length === 0);
|
|
291
|
+
|
|
292
|
+
// ── the dual-HOME overlay is a disk fact, not an implementation detail ──
|
|
293
|
+
// scope id = `<resident pid>-<hash>` (the resident hosts the ACP spawn).
|
|
294
|
+
const scopeEntries = (await fsp.readdir(CORTEX_OVERLAYS_ROOT).catch(() => [] as string[])).filter((e) =>
|
|
295
|
+
e.startsWith(`${resident?.pid}-`),
|
|
296
|
+
);
|
|
297
|
+
ok(
|
|
298
|
+
`the resident materialized exactly one overlay scope dir (got ${scopeEntries.length})`,
|
|
299
|
+
scopeEntries.length === 1,
|
|
300
|
+
);
|
|
301
|
+
overlayScopeDir = path.join(CORTEX_OVERLAYS_ROOT, scopeEntries[0] as string);
|
|
302
|
+
const ovlCortex = path.join(overlayScopeDir, "home", ".snowflake", "cortex");
|
|
303
|
+
const ovlSettings = JSON.parse(await fsp.readFile(path.join(ovlCortex, "settings.json"), "utf8"));
|
|
304
|
+
ok("the overlay pinned autoUpdate:false (D4)", ovlSettings.autoUpdate === false);
|
|
305
|
+
const ovlMcp = JSON.parse(await fsp.readFile(path.join(ovlCortex, "mcp.json"), "utf8"));
|
|
306
|
+
const bridge = ovlMcp.mcpServers?.["entwurf-bridge"];
|
|
307
|
+
ok("the overlay mcp.json projected the entwurf-bridge entry (D9)", Boolean(bridge));
|
|
308
|
+
ok("the projected bridge entry restored the REAL operator HOME (D10 dual-HOME)", bridge.env?.HOME === os.homedir());
|
|
309
|
+
ok(
|
|
310
|
+
"the projected bridge entry carries the live PI_SESSION_ID envelope",
|
|
311
|
+
typeof bridge.env?.PI_SESSION_ID === "string" && bridge.env.PI_SESSION_ID.length > 0,
|
|
312
|
+
);
|
|
313
|
+
ok(
|
|
314
|
+
`the projected bridge entry carries PI_AGENT_ID=entwurf/${ACP_MODEL}`,
|
|
315
|
+
bridge.env?.PI_AGENT_ID === `${ACP_PROVIDER}/${ACP_MODEL}`,
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
// ── the outbound proof is on disk, not in the transcript ──
|
|
319
|
+
const boxDir = path.join(mailboxDir, receiverGid);
|
|
320
|
+
const entries = await fsp.readdir(boxDir).catch(() => [] as string[]);
|
|
321
|
+
const msgs = entries.filter((f) => f.endsWith(".msg"));
|
|
322
|
+
ok(`the model's entwurf_v2 call enqueued exactly one .msg to the peer (got ${msgs.length})`, msgs.length === 1);
|
|
323
|
+
ok("the doorbell inbox.signal was poked", existsSync(path.join(boxDir, "inbox.signal")));
|
|
324
|
+
|
|
325
|
+
const body = await fsp.readFile(path.join(boxDir, msgs[0] as string), "utf8");
|
|
326
|
+
const SEPARATOR = "────────────────────────────────────────";
|
|
327
|
+
const sepAt = body.indexOf(`\n${SEPARATOR}\n`);
|
|
328
|
+
ok("the delivered body carries the rendered envelope separator", sepAt !== -1);
|
|
329
|
+
const header = body.slice(0, sepAt + 1);
|
|
330
|
+
const payload = body.slice(sepAt + 1 + SEPARATOR.length + 1);
|
|
331
|
+
|
|
332
|
+
const rx = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
333
|
+
ok("the payload is EXACTLY the nonce (no envelope text folded into it)", payload === `${nonce}\n`);
|
|
334
|
+
ok(
|
|
335
|
+
"the landed sender agentId is the cortex ACP model (anchored envelope line)",
|
|
336
|
+
new RegExp(`^ {2}from: {8}${rx(ACP_PROVIDER)}/${rx(ACP_MODEL)} @ \\S`, "m").test(header),
|
|
337
|
+
);
|
|
338
|
+
ok(
|
|
339
|
+
"the landed sender session IS the resident's own garden id, replyable (anchored envelope line)",
|
|
340
|
+
new RegExp(
|
|
341
|
+
`^ {2}session: {5}${rx(senderGid)} \\(replyable — reply via entwurf_v2 to this sessionId, intent=fire-and-forget\\)$`,
|
|
342
|
+
"m",
|
|
343
|
+
).test(header),
|
|
344
|
+
);
|
|
345
|
+
ok("the sender gid appears ONLY in the envelope, never in the payload", !payload.includes(senderGid));
|
|
346
|
+
ok("the landed sender renders as a pi-session, not a meta-session", !header.includes("(meta-session"));
|
|
347
|
+
|
|
348
|
+
// ── process-group reclaim (CP0 teardown finding) ──
|
|
349
|
+
// While the resident lives, its retained cortex child inhabits this run's
|
|
350
|
+
// overlay (SNOWFLAKE_HOME env is unique per scope). An MCP-configured
|
|
351
|
+
// cortex child ignores stdin EOF, so only the resident's process-group
|
|
352
|
+
// teardown can reclaim it — kill the resident and require extinction.
|
|
353
|
+
const liveBefore = await pidsWithEnvNeedle(overlayScopeDir);
|
|
354
|
+
ok(
|
|
355
|
+
`the cortex child (group) is alive inside this run's overlay pre-teardown (got ${liveBefore.length})`,
|
|
356
|
+
liveBefore.length > 0,
|
|
357
|
+
);
|
|
358
|
+
await terminateChild(resident);
|
|
359
|
+
resident = null;
|
|
360
|
+
let leaked: number[] = [];
|
|
361
|
+
const deadline = Date.now() + RECLAIM_TIMEOUT_MS;
|
|
362
|
+
for (;;) {
|
|
363
|
+
leaked = await pidsWithEnvNeedle(overlayScopeDir);
|
|
364
|
+
if (leaked.length === 0 || Date.now() > deadline) break;
|
|
365
|
+
await sleep(250);
|
|
366
|
+
}
|
|
367
|
+
ok(
|
|
368
|
+
`process-group teardown reclaimed every process in this run's overlay (leaked: ${leaked.join(",") || "none"})`,
|
|
369
|
+
leaked.length === 0,
|
|
370
|
+
);
|
|
371
|
+
} catch (err) {
|
|
372
|
+
await writeFailureArtifact(cap, stderrTail, err);
|
|
373
|
+
throw err;
|
|
374
|
+
} finally {
|
|
375
|
+
if (resident) await terminateChild(resident);
|
|
376
|
+
if (overlayScopeDir) await fsp.rm(overlayScopeDir, { recursive: true, force: true }).catch(() => {});
|
|
377
|
+
if (process.env.ENTWURF_KEEP_SMOKE_WORLD === "1") {
|
|
378
|
+
console.error(`[smoke-acp-cortex-live] kept world: ${world}`);
|
|
379
|
+
} else {
|
|
380
|
+
await fsp.rm(world, { recursive: true, force: true }).catch(() => {});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (stderrTail && process.env.ENTWURF_SMOKE_VERBOSE === "1") {
|
|
385
|
+
console.error(`[smoke-acp-cortex-live] resident stderr tail:\n${stderrTail}`);
|
|
386
|
+
}
|
|
387
|
+
console.log(
|
|
388
|
+
`smoke-acp-cortex-live: PASS (${passed} assertions) — a cortex ACP model delivered to a peer as itself and was reclaimed`,
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
await main();
|