@junghanacs/entwurf 0.30.0 → 0.31.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 +1 -0
- package/CHANGELOG.md +229 -0
- package/DELIVERY.md +1 -0
- package/README.md +49 -4
- package/VERIFY.md +23 -4
- package/demo/README.md +1 -1
- package/docs/acp-backend-rail.md +111 -18
- package/docs/setup-clean-host.md +104 -4
- package/mcp/entwurf-bridge/dist/mcp/entwurf-bridge/src/index.js +7 -7
- package/mcp/entwurf-bridge/dist/pi-extensions/entwurf-capabilities.json +1 -0
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/acp/backend-adapter.js +43 -0
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/entwurf-deliverability.js +7 -1
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/fresh-call-composition.js +34 -3
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/meta-sender-identity.js +7 -1
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/meta-session.js +28 -2
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/mux-fresh-call.js +30 -2
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/pi-durable-fresh-preflight.js +92 -0
- package/mcp/entwurf-bridge/dist/pi-extensions/lib/pi-durable-runtime.js +288 -0
- package/mcp/entwurf-bridge/dist/pi-extensions/meta-bridge-pi-durable.js +744 -0
- package/mcp/entwurf-bridge/src/index.ts +7 -7
- package/mcp/entwurf-bridge/tsconfig.build.json +8 -1
- package/package.json +15 -12
- package/pi/entwurf-capabilities.json +1 -0
- package/pi/pi-durable/bootstrap.mjs +281 -0
- package/pi/pi-durable/overlay/runtime-contacts.patch +91 -0
- package/pi/pi-durable/overlay/upstream-pin.json +16 -0
- package/pi-extensions/lib/acp/backend-adapter.ts +68 -0
- package/pi-extensions/lib/acp/backend.ts +41 -5
- package/pi-extensions/lib/entwurf-deliverability.ts +7 -1
- package/pi-extensions/lib/fresh-call-composition.ts +42 -7
- package/pi-extensions/lib/meta-sender-identity.ts +7 -1
- package/pi-extensions/lib/meta-session.ts +28 -2
- package/pi-extensions/lib/mux-fresh-call.ts +34 -2
- package/pi-extensions/lib/pi-durable-fresh-preflight.ts +113 -0
- package/pi-extensions/lib/pi-durable-runtime.ts +384 -0
- package/pi-extensions/meta-bridge-pi-durable.ts +1020 -0
- package/run.sh +214 -36
- package/scripts/check-fresh-call-dispatch.ts +18 -0
- package/scripts/check-gate-qualification.ts +4 -2
- package/scripts/check-herdr-plugin-build.ts +159 -57
- package/scripts/check-pi-durable-contact.ts +834 -0
- package/scripts/check-pi-durable-receive.ts +1116 -0
- package/scripts/check-pi-durable-send.ts +1661 -0
- package/scripts/fixtures/herdr-supply.json +8 -8
- package/scripts/lib/pi-durable-fresh-live-receipts.ts +139 -0
- package/scripts/lib/pi-durable-r1.ts +100 -0
- package/scripts/lib/pi-durable-reap.ts +27 -0
- package/scripts/lib/pi-durable-receive.ts +137 -0
- package/scripts/mutants/acp-prompt-lifecycle.json +2 -2
- package/scripts/mutants/acp-vendor-rejection.json +62 -0
- package/scripts/mutants/control-send-receipt.json +1 -1
- package/scripts/mutants/copilot-birth.json +2 -2
- package/scripts/mutants/herdr-plugin-build.json +11 -0
- package/scripts/mutants/herdr-supply.json +3 -3
- package/scripts/mutants/meta-hook-session-switch.json +4 -2
- package/scripts/mutants/mux-fresh-call.json +69 -3
- package/scripts/mutants/omp-birth.json +2 -2
- package/scripts/mutants/omp-fresh.json +6 -4
- package/scripts/mutants/pack-install.json +3 -3
- package/scripts/mutants/pi-durable.json +390 -0
- package/scripts/mutants/pi-floor.json +2 -2
- package/scripts/pi-durable-contact-host.mjs +105 -0
- package/scripts/pi-durable-receive-host.mjs +127 -0
- package/scripts/pi-durable-send-host.mjs +213 -0
- package/scripts/smoke-acp-raw-turn-live.ts +1 -1
- package/scripts/smoke-herdr-fresh-call-live.ts +21 -7
- package/scripts/smoke-pi-durable-fresh-live.ts +624 -0
- package/scripts/smoke-setup-verdict.sh +21 -2
- package/scripts/tsconfig.json +1 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// G-contact host half (#129 L-identity). Runs AS the durable host, under the pinned overlay
|
|
2
|
+
// checkout's source resolver, and is spawned only by scripts/check-pi-durable-contact.ts:
|
|
3
|
+
//
|
|
4
|
+
// node --import <checkout>/packages/coding-agent/src/experimental/source-resolver.ts \
|
|
5
|
+
// scripts/pi-durable-contact-host.mjs <bridge entry> new|continue \
|
|
6
|
+
// [<sessions dir> <senders dir> <mailbox dir> <receivers dir>]
|
|
7
|
+
//
|
|
8
|
+
// The four optional directories are explicit garden roots handed to the contact, all or none;
|
|
9
|
+
// without them the contact uses the shared roots its environment selects.
|
|
10
|
+
//
|
|
11
|
+
// With ENTWURF_PI_DURABLE_CONTACT_FAULT=malformed-report (set only by the gate's control) the report
|
|
12
|
+
// line is deliberately not JSON.
|
|
13
|
+
//
|
|
14
|
+
// It opens the durable app through the production bootstrap composition (`openDurableCitizen`),
|
|
15
|
+
// then executes the contact's registered tools DIRECTLY — adapter-direct, harness-bypassed: no
|
|
16
|
+
// model turn and no ToolTask, so this proves the adapter's bridge contact, not the harness
|
|
17
|
+
// selecting or validating the tool. The report carries the contact's own `receiver()` state, never
|
|
18
|
+
// the path the attachment returned. It prints one JSON report line, holds the host and its
|
|
19
|
+
// bridge child alive until the orchestrator writes `close` (so /proc can be read from outside),
|
|
20
|
+
// closes, prints `{"closed":true}` and exits.
|
|
21
|
+
//
|
|
22
|
+
// The bridge's environment is observed at the SDK connector boundary only: the contact's existing
|
|
23
|
+
// `connect` injection wraps the COMPILED production `connectStdioBridge`, records the spawn spec's
|
|
24
|
+
// command/args/cwd, whether each of the four poisoned identity carrier NAMES is present, and the
|
|
25
|
+
// four root carrier VALUES — nothing else of the env — and forwards the spec unchanged to that real
|
|
26
|
+
// connector. It is the spec the adapter hands the SDK, not the kernel child environment; no
|
|
27
|
+
// /proc/<pid>/environ is read anywhere.
|
|
28
|
+
import { createInterface } from "node:readline";
|
|
29
|
+
import { connectStdioBridge } from "../mcp/entwurf-bridge/dist/pi-extensions/meta-bridge-pi-durable.js";
|
|
30
|
+
import { openDurableCitizen } from "../plugins/pi-durable/bootstrap.mjs";
|
|
31
|
+
|
|
32
|
+
const IDENTITY_CARRIERS = ["PI_SESSION_ID", "PI_AGENT_ID", "ENTWURF_META_SENDER_MARKER", "ENTWURF_BRIDGE_NATIVE_HOST"];
|
|
33
|
+
const ROOT_CARRIERS = [
|
|
34
|
+
"ENTWURF_META_SESSIONS_DIR",
|
|
35
|
+
"ENTWURF_META_SENDERS_DIR",
|
|
36
|
+
"ENTWURF_META_MAILBOX_DIR",
|
|
37
|
+
"ENTWURF_META_RECEIVERS_DIR",
|
|
38
|
+
];
|
|
39
|
+
const bridgeSpecs = [];
|
|
40
|
+
const connect = async (spec) => {
|
|
41
|
+
bridgeSpecs.push({
|
|
42
|
+
command: spec.command,
|
|
43
|
+
args: [...spec.args],
|
|
44
|
+
cwd: spec.cwd,
|
|
45
|
+
identityCarrierPresent: Object.fromEntries(IDENTITY_CARRIERS.map((name) => [name, Object.hasOwn(spec.env, name)])),
|
|
46
|
+
rootCarriers: Object.fromEntries(ROOT_CARRIERS.map((name) => [name, spec.env[name] ?? null])),
|
|
47
|
+
});
|
|
48
|
+
return connectStdioBridge(spec);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const [bridgeEntry, mode, ...rootArgs] = process.argv.slice(2);
|
|
52
|
+
if (bridgeEntry === undefined || (mode !== "new" && mode !== "continue") || ![0, 4].includes(rootArgs.length)) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
"usage: pi-durable-contact-host.mjs <bridge entry> new|continue [<sessions dir> <senders dir> <mailbox dir> <receivers dir>]",
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
const [sessionsDir, sendersDir, mailboxDir, receiversDir] = rootArgs;
|
|
58
|
+
|
|
59
|
+
const citizen = await openDurableCitizen({
|
|
60
|
+
bridgeEntry,
|
|
61
|
+
continueSession: mode === "continue",
|
|
62
|
+
cwd: process.cwd(),
|
|
63
|
+
contact: rootArgs.length === 0 ? { connect } : { sessionsDir, sendersDir, mailboxDir, receiversDir, connect },
|
|
64
|
+
});
|
|
65
|
+
let code = 0;
|
|
66
|
+
try {
|
|
67
|
+
const run = async (name) => {
|
|
68
|
+
const tool = citizen.contact.extension.tools.find((t) => t.name === name);
|
|
69
|
+
if (tool === undefined) throw new Error(`the contact registers no ${name}`);
|
|
70
|
+
const result = await tool.execute({}, undefined, {});
|
|
71
|
+
return result.content.map((block) => block.text).join("\n");
|
|
72
|
+
};
|
|
73
|
+
const view = citizen.durable.view.current();
|
|
74
|
+
const report = {
|
|
75
|
+
hostPid: process.pid,
|
|
76
|
+
session: view.session,
|
|
77
|
+
attachment: citizen.attachment,
|
|
78
|
+
receiver: citizen.contact.receiver(),
|
|
79
|
+
toolNames: citizen.contact.extension.tools.map((t) => t.name),
|
|
80
|
+
bridgeSpecs,
|
|
81
|
+
self: await run("entwurf_self"),
|
|
82
|
+
peers: await run("entwurf_peers"),
|
|
83
|
+
notices: view.notices.map((n) => `${n.level}: ${n.message}`),
|
|
84
|
+
};
|
|
85
|
+
// The gate's malformed-report control: the report line is deliberately not JSON.
|
|
86
|
+
if (process.env.ENTWURF_PI_DURABLE_CONTACT_FAULT === "malformed-report") {
|
|
87
|
+
process.stdout.write(`{"malformed report line\n`);
|
|
88
|
+
} else {
|
|
89
|
+
process.stdout.write(`${JSON.stringify(report)}\n`);
|
|
90
|
+
}
|
|
91
|
+
const lines = createInterface({ input: process.stdin });
|
|
92
|
+
for await (const line of lines) if (line.trim() === "close") break;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
code = 1;
|
|
95
|
+
// The failure report keeps its cause first and carries, beside it, only the host pid and the same
|
|
96
|
+
// connector-boundary record the success report has — so the gate can judge the scrub/root QKs before
|
|
97
|
+
// it throws this error. It is never a success: no attachment, self, peers or session is reported.
|
|
98
|
+
process.stdout.write(
|
|
99
|
+
`${JSON.stringify({ error: error instanceof Error ? error.message : String(error), hostPid: process.pid, bridgeSpecs })}\n`,
|
|
100
|
+
);
|
|
101
|
+
} finally {
|
|
102
|
+
await citizen.close();
|
|
103
|
+
}
|
|
104
|
+
process.stdout.write(`${JSON.stringify({ closed: true })}\n`);
|
|
105
|
+
process.exit(code);
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// G-receive host half (#129 L-receive). Runs AS the durable host, under the pinned overlay checkout's
|
|
2
|
+
// source resolver, and is spawned only by scripts/check-pi-durable-receive.ts:
|
|
3
|
+
//
|
|
4
|
+
// node --import <checkout>/packages/coding-agent/src/experimental/source-resolver.ts \
|
|
5
|
+
// scripts/pi-durable-receive-host.mjs <bridge entry>
|
|
6
|
+
//
|
|
7
|
+
// It opens the durable app through the production bootstrap composition — which arms the contact's
|
|
8
|
+
// doorbell on the root conversation — reports `born`, and then gives the app NO input: no controller
|
|
9
|
+
// call, no tool call, no bridge call, no native state of its own. Whatever runs afterwards was
|
|
10
|
+
// started by the doorbell's root admission. The driver only watches the native view and the
|
|
11
|
+
// contact's own `receiver()` state (never the path the attachment returned, which a later retire
|
|
12
|
+
// can make stale), and reports once:
|
|
13
|
+
//
|
|
14
|
+
// - the receiver has made an admission, the view holds an assistant entry after the newest user
|
|
15
|
+
// entry that calls no tool, and the conversation is no longer busy; or
|
|
16
|
+
// - the receiver is no longer armed; or
|
|
17
|
+
// - the app raised an error notice.
|
|
18
|
+
//
|
|
19
|
+
// Then it holds the host alive until the gate writes `close`, closes, prints `{"closed":true}` and
|
|
20
|
+
// exits.
|
|
21
|
+
import { createInterface } from "node:readline";
|
|
22
|
+
import { openDurableCitizen } from "../plugins/pi-durable/bootstrap.mjs";
|
|
23
|
+
|
|
24
|
+
const USAGE = "usage: pi-durable-receive-host.mjs <bridge entry>";
|
|
25
|
+
const [bridgeEntry, ...extra] = process.argv.slice(2);
|
|
26
|
+
if (bridgeEntry === undefined || extra.length > 0) throw new Error(USAGE);
|
|
27
|
+
|
|
28
|
+
const stdinLines = createInterface({ input: process.stdin })[Symbol.asyncIterator]();
|
|
29
|
+
/** Wait for one exact line from the gate; the gate closing stdin first is a failure. */
|
|
30
|
+
async function waitFor(word) {
|
|
31
|
+
for (;;) {
|
|
32
|
+
const next = await stdinLines.next();
|
|
33
|
+
if (next.done) throw new Error(`stdin closed before "${word}"`);
|
|
34
|
+
if (next.value.trim() === word) return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One entry of the native view, reduced to what the gate compares (the send driver's reduction). */
|
|
39
|
+
function summarize(entry) {
|
|
40
|
+
const message = entry.model?.[0];
|
|
41
|
+
const blocks = Array.isArray(message?.content) ? message.content : [];
|
|
42
|
+
const text = (typeof message?.content === "string" ? [message.content] : [])
|
|
43
|
+
.concat(blocks.flatMap((b) => (b.type === "text" ? [b.text] : [])))
|
|
44
|
+
.join("\n");
|
|
45
|
+
return {
|
|
46
|
+
id: entry.id,
|
|
47
|
+
kind: entry.kind,
|
|
48
|
+
role: message?.role,
|
|
49
|
+
toolCalls: blocks
|
|
50
|
+
.filter((b) => b.type === "toolCall")
|
|
51
|
+
.map((b) => ({ id: b.id, name: b.name, arguments: b.arguments })),
|
|
52
|
+
...(message?.role === "toolResult"
|
|
53
|
+
? {
|
|
54
|
+
toolCallId: message.toolCallId,
|
|
55
|
+
toolName: message.toolName,
|
|
56
|
+
isError: message.isError === true,
|
|
57
|
+
diagnostics: Array.isArray(entry.data?.diagnostics) ? entry.data.diagnostics : [],
|
|
58
|
+
}
|
|
59
|
+
: {}),
|
|
60
|
+
text,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const citizen = await openDurableCitizen({ bridgeEntry, cwd: process.cwd() });
|
|
65
|
+
|
|
66
|
+
function reportOf(view, why) {
|
|
67
|
+
return {
|
|
68
|
+
settled: why,
|
|
69
|
+
hostPid: process.pid,
|
|
70
|
+
session: view.session,
|
|
71
|
+
conversationId: view.conversation.conversation.id,
|
|
72
|
+
receiver: citizen.contact.receiver(),
|
|
73
|
+
entries: view.conversation.entries.filter((e) => e.kind.startsWith("pi.")).map(summarize),
|
|
74
|
+
busy: view.conversation.docs["pi.live"]?.run !== undefined,
|
|
75
|
+
notices: view.notices.map((n) => `${n.level}: ${n.message}`),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let code = 0;
|
|
80
|
+
try {
|
|
81
|
+
const { durable } = citizen;
|
|
82
|
+
const born = durable.view.current();
|
|
83
|
+
const noticesBefore = born.notices.length;
|
|
84
|
+
process.stdout.write(
|
|
85
|
+
`${JSON.stringify({
|
|
86
|
+
born: true,
|
|
87
|
+
hostPid: process.pid,
|
|
88
|
+
session: born.session,
|
|
89
|
+
conversationId: born.conversation.conversation.id,
|
|
90
|
+
attachment: citizen.attachment,
|
|
91
|
+
receiver: citizen.contact.receiver(),
|
|
92
|
+
})}\n`,
|
|
93
|
+
);
|
|
94
|
+
const why = await new Promise((resolve) => {
|
|
95
|
+
let done = false;
|
|
96
|
+
const check = () => {
|
|
97
|
+
if (done) return;
|
|
98
|
+
const view = durable.view.current();
|
|
99
|
+
const receiver = citizen.contact.receiver();
|
|
100
|
+
const entries = view.conversation.entries;
|
|
101
|
+
const lastUser = entries.findLastIndex((e) => e.kind === "pi.user");
|
|
102
|
+
const lastAnswer =
|
|
103
|
+
lastUser < 0 ? undefined : entries.slice(lastUser + 1).findLast((e) => e.kind === "pi.assistant");
|
|
104
|
+
const answered = lastAnswer !== undefined && summarize(lastAnswer).toolCalls.length === 0;
|
|
105
|
+
const busy = view.conversation.docs["pi.live"]?.run !== undefined;
|
|
106
|
+
let outcome;
|
|
107
|
+
if (receiver.status !== "armed") outcome = "receiver-not-armed";
|
|
108
|
+
else if (view.notices.slice(noticesBefore).some((n) => n.level === "error")) outcome = "error-notice";
|
|
109
|
+
else if (receiver.admissions.length > 0 && answered && !busy) outcome = "answered";
|
|
110
|
+
if (outcome === undefined) return;
|
|
111
|
+
done = true;
|
|
112
|
+
unsubscribe();
|
|
113
|
+
resolve(outcome);
|
|
114
|
+
};
|
|
115
|
+
const unsubscribe = durable.view.subscribe(check);
|
|
116
|
+
check();
|
|
117
|
+
});
|
|
118
|
+
process.stdout.write(`${JSON.stringify(reportOf(durable.view.current(), why))}\n`);
|
|
119
|
+
await waitFor("close");
|
|
120
|
+
} catch (error) {
|
|
121
|
+
code = 1;
|
|
122
|
+
process.stdout.write(`${JSON.stringify({ error: error instanceof Error ? error.message : String(error) })}\n`);
|
|
123
|
+
} finally {
|
|
124
|
+
await citizen.close();
|
|
125
|
+
}
|
|
126
|
+
process.stdout.write(`${JSON.stringify({ closed: true })}\n`);
|
|
127
|
+
process.exit(code);
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// G-send host half (#129 L-send first cell). Runs AS the durable host, under the pinned overlay
|
|
2
|
+
// checkout's source resolver, and is spawned only by scripts/check-pi-durable-send.ts:
|
|
3
|
+
//
|
|
4
|
+
// node --import <checkout>/packages/coding-agent/src/experimental/source-resolver.ts \
|
|
5
|
+
// scripts/pi-durable-send-host.mjs <bridge entry> <prompt>
|
|
6
|
+
//
|
|
7
|
+
// It opens the durable app through the production bootstrap composition, then gives the app ONE
|
|
8
|
+
// user input through its native controller — the call its TUI makes when the operator presses
|
|
9
|
+
// enter — and watches only the native view. Everything after that input is the app's own: the
|
|
10
|
+
// model request, the GenerationTask, the ToolTask, the adapter's bridge call. This driver never
|
|
11
|
+
// calls a tool or the bridge itself.
|
|
12
|
+
//
|
|
13
|
+
// `controller.submit` settling is NOT the turn completing: the controller queues the command and
|
|
14
|
+
// turns its failures into notices (runtime.ts:229-252). The driver waits on the view instead —
|
|
15
|
+
// the run document is present exactly while the conversation is busy — and reports what the view
|
|
16
|
+
// holds. It prints one JSON report line, holds the host alive until the gate writes `close`,
|
|
17
|
+
// closes, prints `{"closed":true}` and exits. With ENTWURF_PI_DURABLE_SEND_FAULT=malformed-report
|
|
18
|
+
// (the gate's control) it gives the app no input and sends a non-JSON report line instead.
|
|
19
|
+
import { createInterface } from "node:readline";
|
|
20
|
+
import { openDurableCitizen } from "../plugins/pi-durable/bootstrap.mjs";
|
|
21
|
+
|
|
22
|
+
const USAGE =
|
|
23
|
+
"usage: pi-durable-send-host.mjs <bridge entry> <prompt> [--await-go] [--report-intent <callId> | --recover <callId>]";
|
|
24
|
+
const [bridgeEntry, prompt, ...flags] = process.argv.slice(2);
|
|
25
|
+
if (bridgeEntry === undefined || prompt === undefined) throw new Error(USAGE);
|
|
26
|
+
// --await-go: report `born` once the citizen exists, and give the app its one input only after the
|
|
27
|
+
// gate writes `go` — test-driver sequencing so the gate can read the bridge's counters first. It is
|
|
28
|
+
// not a second input and not another controller.
|
|
29
|
+
// --report-intent <callId>: after the input, watch the native view and report ONCE the frame in
|
|
30
|
+
// which the task graph shows a `pi.tool` node running in phase `execute` and the live slot with the
|
|
31
|
+
// same taskId is that call, running. The phase is the task's committed checkpoint (task-graph.ts
|
|
32
|
+
// 210-221), written in the same commit as the slot (tool.ts 84-90). Then do nothing: the gate kills
|
|
33
|
+
// this process.
|
|
34
|
+
// --recover <callId>: continue the newest session, give the app NO input, and report once the view
|
|
35
|
+
// holds that call's settled result and the conversation is idle.
|
|
36
|
+
let awaitGo = false;
|
|
37
|
+
let reportIntent;
|
|
38
|
+
let recoverCall;
|
|
39
|
+
for (let i = 0; i < flags.length; i++) {
|
|
40
|
+
if (flags[i] === "--await-go") awaitGo = true;
|
|
41
|
+
else if (flags[i] === "--report-intent" && flags[i + 1] !== undefined) reportIntent = flags[++i];
|
|
42
|
+
else if (flags[i] === "--recover" && flags[i + 1] !== undefined) recoverCall = flags[++i];
|
|
43
|
+
else throw new Error(USAGE);
|
|
44
|
+
}
|
|
45
|
+
if (reportIntent !== undefined && recoverCall !== undefined) throw new Error(USAGE);
|
|
46
|
+
|
|
47
|
+
const stdinLines = createInterface({ input: process.stdin })[Symbol.asyncIterator]();
|
|
48
|
+
/** Wait for one exact line from the gate; the gate closing stdin first is a failure. */
|
|
49
|
+
async function waitFor(word) {
|
|
50
|
+
for (;;) {
|
|
51
|
+
const next = await stdinLines.next();
|
|
52
|
+
if (next.done) throw new Error(`stdin closed before "${word}"`);
|
|
53
|
+
if (next.value.trim() === word) return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** One entry of the native view, reduced to what the gate compares. */
|
|
58
|
+
function summarize(entry) {
|
|
59
|
+
const message = entry.model?.[0];
|
|
60
|
+
const blocks = Array.isArray(message?.content) ? message.content : [];
|
|
61
|
+
const text = (typeof message?.content === "string" ? [message.content] : [])
|
|
62
|
+
.concat(blocks.flatMap((b) => (b.type === "text" ? [b.text] : [])))
|
|
63
|
+
.join("\n");
|
|
64
|
+
return {
|
|
65
|
+
kind: entry.kind,
|
|
66
|
+
role: message?.role,
|
|
67
|
+
toolCalls: blocks
|
|
68
|
+
.filter((b) => b.type === "toolCall")
|
|
69
|
+
.map((b) => ({ id: b.id, name: b.name, arguments: b.arguments })),
|
|
70
|
+
...(message?.role === "toolResult"
|
|
71
|
+
? {
|
|
72
|
+
toolCallId: message.toolCallId,
|
|
73
|
+
toolName: message.toolName,
|
|
74
|
+
isError: message.isError === true,
|
|
75
|
+
// The entry's own diagnostics (`data.diagnostics`), copied as they are.
|
|
76
|
+
diagnostics: Array.isArray(entry.data?.diagnostics) ? entry.data.diagnostics : [],
|
|
77
|
+
}
|
|
78
|
+
: {}),
|
|
79
|
+
text,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const citizen = await openDurableCitizen({
|
|
84
|
+
bridgeEntry,
|
|
85
|
+
cwd: process.cwd(),
|
|
86
|
+
continueSession: recoverCall !== undefined,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/** The frame the gate needs: graph node + same-task live slot, as the native view holds them. */
|
|
90
|
+
function intentFrame(view, callId) {
|
|
91
|
+
const nodes = Object.values(view.tasks?.tasks ?? {});
|
|
92
|
+
const slots = view.conversation.docs["pi.live"]?.tools ?? [];
|
|
93
|
+
for (const node of nodes) {
|
|
94
|
+
if (node.kind !== "pi.tool" || node.conversationId !== 1) continue;
|
|
95
|
+
if (node.state?.status !== "running" || node.state?.phase !== "execute") continue;
|
|
96
|
+
const slot = slots.find((s) => s.taskId === node.id);
|
|
97
|
+
if (slot && slot.name === "entwurf_v2" && slot.callId === callId && slot.status === "running") {
|
|
98
|
+
return { node, slot, nodes, slots };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function reportOf(view, before) {
|
|
105
|
+
return {
|
|
106
|
+
hostPid: process.pid,
|
|
107
|
+
session: view.session,
|
|
108
|
+
attachment: citizen.attachment,
|
|
109
|
+
conversationIdBefore: before.conversation.conversation.id,
|
|
110
|
+
conversationIdAfter: view.conversation.conversation.id,
|
|
111
|
+
entries: view.conversation.entries.filter((e) => e.kind.startsWith("pi.")).map(summarize),
|
|
112
|
+
busy: view.conversation.docs["pi.live"]?.run !== undefined,
|
|
113
|
+
notices: view.notices.map((n) => `${n.level}: ${n.message}`),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
let code = 0;
|
|
117
|
+
try {
|
|
118
|
+
if (process.env.ENTWURF_PI_DURABLE_SEND_FAULT === "malformed-report") {
|
|
119
|
+
// The gate's before-valid-report cleanup control: born, no input given to the app, a report
|
|
120
|
+
// line that is deliberately not JSON, then alive until told to close.
|
|
121
|
+
process.stdout.write(`{"malformed send report line\n`);
|
|
122
|
+
await waitFor("close");
|
|
123
|
+
throw new Error("malformed-report control closed");
|
|
124
|
+
}
|
|
125
|
+
const { durable } = citizen;
|
|
126
|
+
if (recoverCall !== undefined) {
|
|
127
|
+
// Recovery may already have run inside openDurable (resume precedes attach): check the current
|
|
128
|
+
// view as well as every later one, so a settled outcome is never missed.
|
|
129
|
+
const before = durable.view.current();
|
|
130
|
+
await new Promise((resolve) => {
|
|
131
|
+
let done = false;
|
|
132
|
+
const check = () => {
|
|
133
|
+
if (done) return;
|
|
134
|
+
const view = durable.view.current();
|
|
135
|
+
const entries = view.conversation.entries;
|
|
136
|
+
const resultAt = entries.findIndex(
|
|
137
|
+
(e) => e.kind === "pi.tool-result" && e.model?.[0]?.toolCallId === recoverCall,
|
|
138
|
+
);
|
|
139
|
+
const answeredAfter = resultAt >= 0 && entries.slice(resultAt + 1).some((e) => e.kind === "pi.assistant");
|
|
140
|
+
const busy = view.conversation.docs["pi.live"]?.run !== undefined;
|
|
141
|
+
const failed = view.notices.some((n) => n.level === "error");
|
|
142
|
+
if ((answeredAfter && !busy) || failed) {
|
|
143
|
+
done = true;
|
|
144
|
+
unsubscribe();
|
|
145
|
+
resolve();
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const unsubscribe = durable.view.subscribe(check);
|
|
149
|
+
check();
|
|
150
|
+
});
|
|
151
|
+
process.stdout.write(`${JSON.stringify({ recovered: true, ...reportOf(durable.view.current(), before) })}\n`);
|
|
152
|
+
await waitFor("close");
|
|
153
|
+
throw new Error("__closed__");
|
|
154
|
+
}
|
|
155
|
+
if (awaitGo) {
|
|
156
|
+
process.stdout.write(
|
|
157
|
+
`${JSON.stringify({ born: true, hostPid: process.pid, attachment: citizen.attachment, session: durable.view.current().session })}\n`,
|
|
158
|
+
);
|
|
159
|
+
await waitFor("go");
|
|
160
|
+
}
|
|
161
|
+
if (reportIntent !== undefined) {
|
|
162
|
+
let reported = false;
|
|
163
|
+
const check = () => {
|
|
164
|
+
if (reported) return;
|
|
165
|
+
const view = durable.view.current();
|
|
166
|
+
const frame = intentFrame(view, reportIntent);
|
|
167
|
+
if (frame === undefined) return;
|
|
168
|
+
reported = true;
|
|
169
|
+
process.stdout.write(
|
|
170
|
+
`${JSON.stringify({ intent: true, hostPid: process.pid, session: view.session, frame, entries: view.conversation.entries.filter((e) => e.kind.startsWith("pi.")).map(summarize) })}\n`,
|
|
171
|
+
);
|
|
172
|
+
};
|
|
173
|
+
durable.view.subscribe(check);
|
|
174
|
+
durable.controller.submit(prompt, "followUp").then(check);
|
|
175
|
+
check();
|
|
176
|
+
// The gate kills this process after the frame; nothing else happens here.
|
|
177
|
+
await waitFor("close");
|
|
178
|
+
throw new Error("report-intent host was asked to close instead of being killed");
|
|
179
|
+
}
|
|
180
|
+
const before = durable.view.current();
|
|
181
|
+
const noticesBefore = before.notices.length;
|
|
182
|
+
let submitted = false;
|
|
183
|
+
const settled = new Promise((resolve) => {
|
|
184
|
+
const check = () => {
|
|
185
|
+
if (!submitted) return;
|
|
186
|
+
const view = durable.view.current();
|
|
187
|
+
const busy = view.conversation.docs["pi.live"]?.run !== undefined;
|
|
188
|
+
const answered = view.conversation.entries.some((e) => e.kind === "pi.assistant");
|
|
189
|
+
const failed = view.notices.slice(noticesBefore).some((n) => n.level === "error");
|
|
190
|
+
if ((!busy && answered) || failed) {
|
|
191
|
+
unsubscribe();
|
|
192
|
+
resolve();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const unsubscribe = durable.view.subscribe(check);
|
|
196
|
+
durable.controller.submit(prompt, "followUp").then(() => {
|
|
197
|
+
submitted = true;
|
|
198
|
+
check();
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
await settled;
|
|
202
|
+
process.stdout.write(`${JSON.stringify(reportOf(durable.view.current(), before))}\n`);
|
|
203
|
+
await waitFor("close");
|
|
204
|
+
} catch (error) {
|
|
205
|
+
if (!(error instanceof Error && error.message === "__closed__")) {
|
|
206
|
+
code = 1;
|
|
207
|
+
process.stdout.write(`${JSON.stringify({ error: error instanceof Error ? error.message : String(error) })}\n`);
|
|
208
|
+
}
|
|
209
|
+
} finally {
|
|
210
|
+
await citizen.close();
|
|
211
|
+
}
|
|
212
|
+
process.stdout.write(`${JSON.stringify({ closed: true })}\n`);
|
|
213
|
+
process.exit(code);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// LIVE=1 ./run.sh smoke-acp-raw-turn-live
|
|
4
4
|
//
|
|
5
5
|
// What this proves (and ONLY this): the pinned Claude ACP adapter
|
|
6
|
-
// (@agentclientprotocol/claude-agent-acp
|
|
6
|
+
// (@agentclientprotocol/claude-agent-acp, exact pin in package.json) spawns, speaks the ACP wire
|
|
7
7
|
// protocol over stdio NDJSON, and returns one real model turn. It is the
|
|
8
8
|
// bytes-flow proof that the S2a dep surface is not just installable but
|
|
9
9
|
// actually drivable — before any provider/overlay/streamSimple code (S2b+).
|
|
@@ -196,10 +196,9 @@ function transcriptRecords(file: string): string[] {
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
|
-
* The
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* writes `"type":"toolCall","name":"entwurf_callback"`; neither records
|
|
199
|
+
* The verb names as the CLAUDE MCP activity log spells them — NOT the model-facing dialect.
|
|
200
|
+
* `[측정 2026-09-20, this smoke's own red fixture]` that log carries `Calling MCP tool:
|
|
201
|
+
* entwurf_callback` / `Tool 'entwurf_callback' completed`, never
|
|
203
202
|
* `mcp__entwurf-bridge__entwurf_callback`. The per-host dialect is owned by
|
|
204
203
|
* `FRESH_CALL_CALLBACK_TOOL` / `FRESH_CALL_DELIVERY_TOOL` in `fresh-call-composition.ts` and is
|
|
205
204
|
* what the FRAMING says; these two are what an OBSERVER sees, and conflating them is what this
|
|
@@ -208,6 +207,17 @@ function transcriptRecords(file: string): string[] {
|
|
|
208
207
|
const CALLBACK_VERB = "entwurf_callback";
|
|
209
208
|
const DELIVERY_VERB = "entwurf_v2";
|
|
210
209
|
|
|
210
|
+
/**
|
|
211
|
+
* The callback as a Pi 1.0 TRANSCRIPT spells it. Pi's built-in MCP is the tool ingress since
|
|
212
|
+
* 0.30.0, and Pi records the qualified name the model called. The bare `entwurf_callback` this
|
|
213
|
+
* smoke read on 2026-09-20 belonged to the retired native-tool registration; a pi→pi child that
|
|
214
|
+
* called back correctly would then never match, which is a red about the oracle, not the rail.
|
|
215
|
+
* Declared here as the OBSERVED literal, not imported from the compositor, so a change to the
|
|
216
|
+
* production framing cannot quietly move this expectation with it — the same rule as
|
|
217
|
+
* `PI_SOURCE_VERBS` in `lib/codex-fresh-source-receipts.ts`. No prefix strip, no legacy OR.
|
|
218
|
+
*/
|
|
219
|
+
const PI_CALLBACK_TOOL = "mcp__entwurf_bridge__entwurf_callback";
|
|
220
|
+
|
|
211
221
|
/**
|
|
212
222
|
* The id of the CALLBACK toolCall in this record, or null. Pi writes a call and its result as two
|
|
213
223
|
* records; this is one half of the join that replaces a same-record read.
|
|
@@ -238,7 +248,9 @@ function entwurfCallIdFor(record: string, nonce: string, callerGid: string): str
|
|
|
238
248
|
if (!Array.isArray(content)) return null;
|
|
239
249
|
for (const part of content) {
|
|
240
250
|
const call = part as { type?: unknown; name?: unknown; id?: unknown; arguments?: unknown };
|
|
241
|
-
if (call.type !== "toolCall"
|
|
251
|
+
if (call.type !== "toolCall") continue;
|
|
252
|
+
if (call.name === CALLBACK_VERB) throw new Error(`${LABEL}: retired raw Pi tool name ${CALLBACK_VERB}`);
|
|
253
|
+
if (call.name !== PI_CALLBACK_TOOL) continue;
|
|
242
254
|
// Zero-argument verb: absent, null and `{}` are all the shape it is called with. A supplied
|
|
243
255
|
// target or message is a model naming an address the env already owns — not this act.
|
|
244
256
|
const args = call.arguments as { message?: unknown; target?: unknown } | undefined | null;
|
|
@@ -444,8 +456,10 @@ async function main(): Promise<void> {
|
|
|
444
456
|
childBackend: "pi",
|
|
445
457
|
callerKind: "pi",
|
|
446
458
|
childKind: "pi",
|
|
447
|
-
|
|
448
|
-
|
|
459
|
+
// The approved roster's lighter Pi GPT tier (agent-config MODELS.md, 2026-09-30); gpt-5.6-sol
|
|
460
|
+
// is still in the catalog but no longer on the roster. A LIVE cost choice, not a product set.
|
|
461
|
+
callerModel: "openai-codex/gpt-6-luna",
|
|
462
|
+
childModel: "openai-codex/gpt-6-luna",
|
|
449
463
|
},
|
|
450
464
|
{
|
|
451
465
|
label: "claude→claude",
|