@vibefield/puppeteer-imposter 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/bin/ai.mjs +17 -0
- package/dist/cli/argv.d.ts +40 -0
- package/dist/cli/argv.d.ts.map +1 -0
- package/dist/cli/argv.js +62 -0
- package/dist/cli/argv.js.map +1 -0
- package/dist/cli/http-persona.d.ts +15 -0
- package/dist/cli/http-persona.d.ts.map +1 -0
- package/dist/cli/http-persona.js +216 -0
- package/dist/cli/http-persona.js.map +1 -0
- package/dist/cli/main.d.ts +11 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +671 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/prompt-line.d.ts +27 -0
- package/dist/cli/prompt-line.d.ts.map +1 -0
- package/dist/cli/prompt-line.js +93 -0
- package/dist/cli/prompt-line.js.map +1 -0
- package/dist/control/client.d.ts +51 -0
- package/dist/control/client.d.ts.map +1 -0
- package/dist/control/client.js +206 -0
- package/dist/control/client.js.map +1 -0
- package/dist/control/index.d.ts +10 -0
- package/dist/control/index.d.ts.map +1 -0
- package/dist/control/index.js +10 -0
- package/dist/control/index.js.map +1 -0
- package/dist/control/peer.d.ts +42 -0
- package/dist/control/peer.d.ts.map +1 -0
- package/dist/control/peer.js +174 -0
- package/dist/control/peer.js.map +1 -0
- package/dist/control/protocol.d.ts +207 -0
- package/dist/control/protocol.d.ts.map +1 -0
- package/dist/control/protocol.js +535 -0
- package/dist/control/protocol.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/persona/launch.d.ts +7 -0
- package/dist/persona/launch.d.ts.map +1 -0
- package/dist/persona/launch.js +26 -0
- package/dist/persona/launch.js.map +1 -0
- package/dist/persona/load.d.ts +28 -0
- package/dist/persona/load.d.ts.map +1 -0
- package/dist/persona/load.js +705 -0
- package/dist/persona/load.js.map +1 -0
- package/dist/persona/session-id.d.ts +4 -0
- package/dist/persona/session-id.d.ts.map +1 -0
- package/dist/persona/session-id.js +12 -0
- package/dist/persona/session-id.js.map +1 -0
- package/dist/persona/types.d.ts +265 -0
- package/dist/persona/types.d.ts.map +1 -0
- package/dist/persona/types.js +38 -0
- package/dist/persona/types.js.map +1 -0
- package/dist/session/channels/hook.d.ts +31 -0
- package/dist/session/channels/hook.d.ts.map +1 -0
- package/dist/session/channels/hook.js +114 -0
- package/dist/session/channels/hook.js.map +1 -0
- package/dist/session/channels/http-sse.d.ts +67 -0
- package/dist/session/channels/http-sse.d.ts.map +1 -0
- package/dist/session/channels/http-sse.js +212 -0
- package/dist/session/channels/http-sse.js.map +1 -0
- package/dist/session/channels/jsonrpc.d.ts +56 -0
- package/dist/session/channels/jsonrpc.d.ts.map +1 -0
- package/dist/session/channels/jsonrpc.js +196 -0
- package/dist/session/channels/jsonrpc.js.map +1 -0
- package/dist/session/channels/leader-ipc.d.ts +27 -0
- package/dist/session/channels/leader-ipc.d.ts.map +1 -0
- package/dist/session/channels/leader-ipc.js +314 -0
- package/dist/session/channels/leader-ipc.js.map +1 -0
- package/dist/session/channels/native-store.d.ts +31 -0
- package/dist/session/channels/native-store.d.ts.map +1 -0
- package/dist/session/channels/native-store.js +275 -0
- package/dist/session/channels/native-store.js.map +1 -0
- package/dist/session/channels/statusline.d.ts +20 -0
- package/dist/session/channels/statusline.d.ts.map +1 -0
- package/dist/session/channels/statusline.js +48 -0
- package/dist/session/channels/statusline.js.map +1 -0
- package/dist/session/channels/terminal.d.ts +27 -0
- package/dist/session/channels/terminal.d.ts.map +1 -0
- package/dist/session/channels/terminal.js +108 -0
- package/dist/session/channels/terminal.js.map +1 -0
- package/dist/session/channels/transcript.d.ts +16 -0
- package/dist/session/channels/transcript.d.ts.map +1 -0
- package/dist/session/channels/transcript.js +24 -0
- package/dist/session/channels/transcript.js.map +1 -0
- package/dist/session/channels/ws-unix.d.ts +57 -0
- package/dist/session/channels/ws-unix.d.ts.map +1 -0
- package/dist/session/channels/ws-unix.js +396 -0
- package/dist/session/channels/ws-unix.js.map +1 -0
- package/dist/session/http-session-server.d.ts +31 -0
- package/dist/session/http-session-server.d.ts.map +1 -0
- package/dist/session/http-session-server.js +508 -0
- package/dist/session/http-session-server.js.map +1 -0
- package/dist/session/scenario-driver.d.ts +105 -0
- package/dist/session/scenario-driver.d.ts.map +1 -0
- package/dist/session/scenario-driver.js +211 -0
- package/dist/session/scenario-driver.js.map +1 -0
- package/dist/session/scenario.d.ts +119 -0
- package/dist/session/scenario.d.ts.map +1 -0
- package/dist/session/scenario.js +299 -0
- package/dist/session/scenario.js.map +1 -0
- package/dist/session/serve.d.ts +124 -0
- package/dist/session/serve.d.ts.map +1 -0
- package/dist/session/serve.js +136 -0
- package/dist/session/serve.js.map +1 -0
- package/dist/session/session.d.ts +125 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/session/session.js +781 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/template.d.ts +35 -0
- package/dist/session/template.d.ts.map +1 -0
- package/dist/session/template.js +133 -0
- package/dist/session/template.js.map +1 -0
- package/dist/session/timeline.d.ts +81 -0
- package/dist/session/timeline.d.ts.map +1 -0
- package/dist/session/timeline.js +155 -0
- package/dist/session/timeline.js.map +1 -0
- package/dist/tui/app.d.ts +30 -0
- package/dist/tui/app.d.ts.map +1 -0
- package/dist/tui/app.js +72 -0
- package/dist/tui/app.js.map +1 -0
- package/dist/tui/mount.d.ts +37 -0
- package/dist/tui/mount.d.ts.map +1 -0
- package/dist/tui/mount.js +88 -0
- package/dist/tui/mount.js.map +1 -0
- package/dist/tui/store.d.ts +38 -0
- package/dist/tui/store.d.ts.map +1 -0
- package/dist/tui/store.js +56 -0
- package/dist/tui/store.js.map +1 -0
- package/dist/tui/theme.d.ts +40 -0
- package/dist/tui/theme.d.ts.map +1 -0
- package/dist/tui/theme.js +54 -0
- package/dist/tui/theme.js.map +1 -0
- package/package.json +67 -3
- package/personas/antigravity/behavior/happy-turn.json +9 -0
- package/personas/antigravity/ops.json +14 -0
- package/personas/antigravity/persona.json +15 -0
- package/personas/antigravity/runflows.json +6 -0
- package/personas/antigravity/scenarios/happy-turn.json +25 -0
- package/personas/claude/behavior/happy-turn.json +19 -0
- package/personas/claude/ops.json +128 -0
- package/personas/claude/persona.json +29 -0
- package/personas/claude/runflows.json +45 -0
- package/personas/claude/scenarios/channel-disconnect.json +19 -0
- package/personas/claude/scenarios/crash-mid-turn.json +42 -0
- package/personas/claude/scenarios/cross-layer-implementation.json +488 -0
- package/personas/claude/scenarios/deep-research.json +494 -0
- package/personas/claude/scenarios/duplicate-out-of-order.json +57 -0
- package/personas/claude/scenarios/flood.json +11 -0
- package/personas/claude/scenarios/happy-turn.json +57 -0
- package/personas/claude/scenarios/incident-investigation.json +465 -0
- package/personas/claude/scenarios/late-after-exit.json +27 -0
- package/personas/claude/scenarios/permission-allow.json +55 -0
- package/personas/claude/scenarios/permission-deny.json +71 -0
- package/personas/claude/scenarios/token-usage-refresh.json +33 -0
- package/personas/claude/scenarios/unknown-event.json +14 -0
- package/personas/codex/behavior/approval-turn.json +15 -0
- package/personas/codex/behavior/happy-turn.json +10 -0
- package/personas/codex/ops.json +159 -0
- package/personas/codex/persona.json +36 -0
- package/personas/codex/runflows.json +45 -0
- package/personas/codex/scenarios/channel-disconnect.json +31 -0
- package/personas/codex/scenarios/crash-mid-turn.json +30 -0
- package/personas/codex/scenarios/cross-layer-implementation.json +725 -0
- package/personas/codex/scenarios/deep-research.json +684 -0
- package/personas/codex/scenarios/duplicate-out-of-order.json +87 -0
- package/personas/codex/scenarios/flood.json +22 -0
- package/personas/codex/scenarios/happy-turn.json +81 -0
- package/personas/codex/scenarios/incident-investigation.json +695 -0
- package/personas/codex/scenarios/late-after-exit.json +59 -0
- package/personas/codex/scenarios/permission-allow.json +110 -0
- package/personas/codex/scenarios/permission-deny.json +83 -0
- package/personas/codex/scenarios/token-usage-refresh.json +49 -0
- package/personas/codex/scenarios/unknown-event.json +17 -0
- package/personas/codex/serve.json +124 -0
- package/personas/copilot/behavior/happy-turn.json +9 -0
- package/personas/copilot/ops.json +28 -0
- package/personas/copilot/persona.json +17 -0
- package/personas/copilot/runflows.json +6 -0
- package/personas/copilot/scenarios/happy-turn.json +50 -0
- package/personas/grok/behavior/approval-turn.json +16 -0
- package/personas/grok/behavior/happy-turn.json +13 -0
- package/personas/grok/ops.json +330 -0
- package/personas/grok/persona.json +24 -0
- package/personas/grok/runflows.json +25 -0
- package/personas/grok/scenarios/agent-team-lifecycle.json +74 -0
- package/personas/grok/scenarios/compact-lifecycle.json +61 -0
- package/personas/grok/serve.json +57 -0
- package/personas/hermes/behavior/approval-turn.json +11 -0
- package/personas/hermes/behavior/happy-turn.json +9 -0
- package/personas/hermes/ops.json +227 -0
- package/personas/hermes/persona.json +15 -0
- package/personas/hermes/runflows.json +50 -0
- package/personas/hermes/scenarios/happy-turn.json +25 -0
- package/personas/hermes/scenarios/late-after-exit.json +21 -0
- package/personas/hermes/scenarios/permission-deny.json +54 -0
- package/personas/hermes/scenarios/unknown-event.json +14 -0
- package/personas/hermes/serve.json +54 -0
- package/personas/kimi/behavior/happy-turn.json +9 -0
- package/personas/kimi/ops.json +357 -0
- package/personas/kimi/persona.json +23 -0
- package/personas/kimi/runflows.json +84 -0
- package/personas/kimi/scenarios/compaction-lifecycle.json +20 -0
- package/personas/kimi/scenarios/duplicate-out-of-order.json +60 -0
- package/personas/kimi/scenarios/happy-turn.json +66 -0
- package/personas/kimi/scenarios/late-after-end.json +28 -0
- package/personas/kimi/scenarios/tool-failure.json +43 -0
- package/personas/kimi/scenarios/tool-success.json +57 -0
- package/personas/kimi/scenarios/unknown-record.json +15 -0
- package/personas/opencode/README.md +32 -0
- package/personas/opencode/behavior/happy-turn.json +9 -0
- package/personas/opencode/behavior/permission-turn.json +18 -0
- package/personas/opencode/http-serve.json +72 -0
- package/personas/opencode/ops.json +250 -0
- package/personas/opencode/persona.json +22 -0
- package/personas/opencode/runflows.json +45 -0
- package/personas/opencode/scenarios/duplicate-event.json +27 -0
- package/personas/opencode/scenarios/failure.json +30 -0
- package/personas/opencode/scenarios/happy-turn.json +86 -0
- package/personas/opencode/scenarios/late-event.json +29 -0
- package/personas/opencode/scenarios/out-of-order.json +42 -0
- package/personas/opencode/scenarios/permission-allow.json +31 -0
- package/personas/opencode/scenarios/permission-deny.json +31 -0
- package/personas/opencode/scenarios/question-reject.json +37 -0
- package/personas/opencode/scenarios/question-reply.json +38 -0
- package/personas/opencode/scenarios/reconnect.json +22 -0
- package/personas/opencode/scenarios/resume.json +30 -0
- package/personas/opencode/scenarios/unknown-event.json +15 -0
- package/personas/pi/behavior/happy-turn.json +9 -0
- package/personas/pi/ops.json +19 -0
- package/personas/pi/persona.json +16 -0
- package/personas/pi/runflows.json +6 -0
- package/personas/pi/scenarios/happy-turn.json +52 -0
- package/personas/synthetic/behavior/happy-turn.json +12 -0
- package/personas/synthetic/groundtruth.html +164 -0
- package/personas/synthetic/groundtruth.json +380 -0
- package/personas/synthetic/model/behavior.json +27 -0
- package/personas/synthetic/model/channels.json +16 -0
- package/personas/synthetic/model/detection.json +13 -0
- package/personas/synthetic/model/events/agent.action.json +16 -0
- package/personas/synthetic/model/events/agent.boot.json +16 -0
- package/personas/synthetic/model/events/agent.halt.json +16 -0
- package/personas/synthetic/model/events/agent.prompt.json +16 -0
- package/personas/synthetic/model/events/agent.reply.json +16 -0
- package/personas/synthetic/model/events/agent.settled.json +16 -0
- package/personas/synthetic/model/manifest.json +7 -0
- package/personas/synthetic/ops.json +18 -0
- package/personas/synthetic/persona.json +11 -0
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenario-driver.d.ts","sourceRoot":"","sources":["../../src/session/scenario-driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,EAAY,KAAK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,CAAC;IACX,gFAAgF;IAChF,EAAE,CAAC,EAAE,qBAAqB,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,kBAAkB,EAAE,CAAC;IAC5B,KAAK,EAAE,kBAAkB,EAAE,CAAC;IAC5B,OAAO,EAAE,oBAAoB,EAAE,CAAC;IAChC,MAAM,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC9C;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,IAAI,yBAAyB,CAqClE"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The portable scenario driver, as a state machine over the op vocabulary
|
|
3
|
+
* (docs/archive/IMPOSTER.md §2, §11).
|
|
4
|
+
*
|
|
5
|
+
* This is authoring intent, NOT a vendor lifecycle or a normalized runtime
|
|
6
|
+
* projection. Vendor-native truth lives in Surface's versioned behavior graph;
|
|
7
|
+
* adapters alone translate that truth into Core/Godview state. The ops in
|
|
8
|
+
* `persona/types.ts` still benefit from a state machine — a turn cannot end
|
|
9
|
+
* before it starts, a tool cannot finish before it runs, an approval suspends
|
|
10
|
+
* whatever asked for it — but that structure lived only in the shape of the
|
|
11
|
+
* behavior packs. Written down, it becomes something the operator can see and
|
|
12
|
+
* steer by: where the session is now, which ops are organic from here, and what
|
|
13
|
+
* each one would do.
|
|
14
|
+
*
|
|
15
|
+
* Two properties matter more than the graph itself:
|
|
16
|
+
*
|
|
17
|
+
* 1. **Descriptive, never prescriptive.** The machine reports; it does not
|
|
18
|
+
* gate. Firing an op the current state does not handle leaves the state
|
|
19
|
+
* alone and marks the op off-model — it does NOT refuse it. That is
|
|
20
|
+
* deliberate: adversarial scenarios exist precisely to send traffic no
|
|
21
|
+
* organic turn would produce (`duplicate-out-of-order`, `late-after-exit`),
|
|
22
|
+
* and a machine that blocked them would delete the imposter's whole reason
|
|
23
|
+
* for existing. Refusal belongs at the ASM boundary (§7.3 item 3), which
|
|
24
|
+
* judges payloads, not order.
|
|
25
|
+
*
|
|
26
|
+
* 2. **It advances on the OP, not on the wire.** An op a persona leaves unbound
|
|
27
|
+
* still happened — codex binds no `session.ready`, and the imposter
|
|
28
|
+
* nonetheless enters the driver's ready phase. So the driver describes
|
|
29
|
+
* what a portable scenario intends, while the emitted log describes the
|
|
30
|
+
* vendor-native traffic the Imposter actually put on the wire. Only the
|
|
31
|
+
* latter can be used as evidence about vendor behavior.
|
|
32
|
+
*
|
|
33
|
+
* xstate costs 6 ms and 5.6 MB RSS to import (node 26.5, measured 2026-08-08) —
|
|
34
|
+
* an eighth of Ink's 40 MB, and unlike Ink this is wanted in every mode, so it
|
|
35
|
+
* is a static import rather than a dynamic one.
|
|
36
|
+
*/
|
|
37
|
+
import { assign, createActor, createMachine } from 'xstate';
|
|
38
|
+
import { OP_NAMES } from "../persona/types.js";
|
|
39
|
+
/**
|
|
40
|
+
* `session.end` and `usage.refresh` are handled at the root: both are legal
|
|
41
|
+
* from anywhere, and drawing seven edges for each would bury the flow that
|
|
42
|
+
* actually matters. `describeScenarioDriver` reports them as globals instead.
|
|
43
|
+
*/
|
|
44
|
+
const definition = {
|
|
45
|
+
id: 'imposter-session',
|
|
46
|
+
initial: 'starting',
|
|
47
|
+
context: { heartbeats: 0 },
|
|
48
|
+
on: {
|
|
49
|
+
'session.end': '.ended',
|
|
50
|
+
// Usage refreshes are a heartbeat, not a transition — but xstate's `can()`
|
|
51
|
+
// is false for an event with no effect at all, which would report every
|
|
52
|
+
// refresh as off-model. Counting them is both the fix and the honest
|
|
53
|
+
// authoring model: the op happened, and it moved no scenario phase.
|
|
54
|
+
'usage.refresh': { actions: assign({ heartbeats: ({ context }) => context.heartbeats + 1 }) },
|
|
55
|
+
},
|
|
56
|
+
states: {
|
|
57
|
+
/** Process alive, nothing announced. For a served vendor this is the wait for a thread. */
|
|
58
|
+
starting: {
|
|
59
|
+
on: {
|
|
60
|
+
// Negotiation/ambient bootstrap does not create a vendor session.
|
|
61
|
+
// Grok proves the distinction: its extension census arrives after ACP
|
|
62
|
+
// initialize but before session/new.
|
|
63
|
+
'session.initialize': 'starting',
|
|
64
|
+
'session.start': 'booting',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
booting: {
|
|
68
|
+
on: {
|
|
69
|
+
'session.ready': 'ready',
|
|
70
|
+
// A vendor with no readiness signal proves readiness by completing a
|
|
71
|
+
// turn — codex binds no `session.ready` on purpose, and its reducer
|
|
72
|
+
// reaches `ready` on the first `turn/completed`. Without this edge every
|
|
73
|
+
// codex turn would read as off-model, which would be a lie about codex
|
|
74
|
+
// rather than a finding about it.
|
|
75
|
+
'turn.start': 'turn',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
ready: {
|
|
79
|
+
on: { 'turn.start': 'turn' },
|
|
80
|
+
},
|
|
81
|
+
turn: {
|
|
82
|
+
initial: 'thinking',
|
|
83
|
+
on: { 'turn.end': 'ready' },
|
|
84
|
+
states: {
|
|
85
|
+
thinking: {
|
|
86
|
+
on: {
|
|
87
|
+
'assistant.delta': 'thinking',
|
|
88
|
+
'tool.start': 'tool',
|
|
89
|
+
'permission.ask': 'approval',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
tool: {
|
|
93
|
+
on: {
|
|
94
|
+
'tool.end': 'thinking',
|
|
95
|
+
'permission.ask': 'approval',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* Suspended on a client decision. Both entry orders are evidenced by
|
|
100
|
+
* the scenario packs rather than assumed: claude asks before the tool
|
|
101
|
+
* runs (`PermissionRequest` → `PreToolUse`) and codex asks after it
|
|
102
|
+
* starts (`item/started` → `requestApproval`). Both exits are real too
|
|
103
|
+
* — allowed runs the tool, denied returns to the turn without one,
|
|
104
|
+
* which is why codex's deny is `decline` and not `cancel` (C1d).
|
|
105
|
+
*/
|
|
106
|
+
approval: {
|
|
107
|
+
on: {
|
|
108
|
+
'tool.start': 'tool',
|
|
109
|
+
'tool.end': 'thinking',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
/** Nothing leaves. Anything after this is off-model by construction, which is what `late-after-exit` tests. */
|
|
115
|
+
ended: {},
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
function flatten(value) {
|
|
119
|
+
if (typeof value === 'string')
|
|
120
|
+
return value;
|
|
121
|
+
const [parent, child] = Object.entries(value)[0] ?? [];
|
|
122
|
+
return (child === undefined ? String(parent) : `${String(parent)}.${flatten(child)}`);
|
|
123
|
+
}
|
|
124
|
+
export function createScenarioDriver() {
|
|
125
|
+
const machine = createMachine(definition);
|
|
126
|
+
const actor = createActor(machine);
|
|
127
|
+
const listeners = new Set();
|
|
128
|
+
let offModel = 0;
|
|
129
|
+
let applied = 0;
|
|
130
|
+
actor.start();
|
|
131
|
+
const snapshot = () => {
|
|
132
|
+
const current = actor.getSnapshot();
|
|
133
|
+
return {
|
|
134
|
+
state: flatten(current.value),
|
|
135
|
+
// `usage.refresh` is handled at the root, so `can()` reports it in every
|
|
136
|
+
// state — correct, and the console shows it as the heartbeat it is.
|
|
137
|
+
enabled: OP_NAMES.filter((op) => current.can({ type: op })),
|
|
138
|
+
offModel,
|
|
139
|
+
applied,
|
|
140
|
+
heartbeats: current.context.heartbeats,
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
send(op) {
|
|
145
|
+
const handled = actor.getSnapshot().can({ type: op });
|
|
146
|
+
applied += 1;
|
|
147
|
+
if (!handled)
|
|
148
|
+
offModel += 1;
|
|
149
|
+
// Sent either way: an off-model op is reported, not swallowed, and one
|
|
150
|
+
// the machine happens not to model must never be lost from the counts.
|
|
151
|
+
actor.send({ type: op });
|
|
152
|
+
const next = snapshot();
|
|
153
|
+
for (const listener of listeners)
|
|
154
|
+
listener(next);
|
|
155
|
+
return { handled, snapshot: next };
|
|
156
|
+
},
|
|
157
|
+
snapshot,
|
|
158
|
+
subscribe(listener) {
|
|
159
|
+
listeners.add(listener);
|
|
160
|
+
return () => listeners.delete(listener);
|
|
161
|
+
},
|
|
162
|
+
stop: () => actor.stop(),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The picture of the portable scenario driver, laid out by hand.
|
|
167
|
+
*
|
|
168
|
+
* Positions live here rather than in the renderer because this graph is small,
|
|
169
|
+
* fixed, and worth reading: a generic layout engine would spend a dependency to
|
|
170
|
+
* produce something worse. They are grid coordinates, so the console can scale
|
|
171
|
+
* them to whatever space it has.
|
|
172
|
+
*/
|
|
173
|
+
export function describeScenarioDriver() {
|
|
174
|
+
return {
|
|
175
|
+
groups: [{ id: 'turn', label: 'turn' }],
|
|
176
|
+
nodes: [
|
|
177
|
+
{ id: 'starting', label: 'starting', x: 0, y: 1 },
|
|
178
|
+
{ id: 'booting', label: 'booting', x: 1, y: 1 },
|
|
179
|
+
{ id: 'ready', label: 'ready', x: 2, y: 1 },
|
|
180
|
+
{ id: 'turn.thinking', label: 'thinking', group: 'turn', x: 3.25, y: 0.42 },
|
|
181
|
+
{ id: 'turn.tool', label: 'tool', group: 'turn', x: 4.5, y: 0.42 },
|
|
182
|
+
{ id: 'turn.approval', label: 'approval', group: 'turn', x: 3.875, y: 1.55 },
|
|
183
|
+
{ id: 'ended', label: 'ended', x: 1.5, y: 2.5 },
|
|
184
|
+
],
|
|
185
|
+
edges: [
|
|
186
|
+
{ from: 'starting', to: 'starting', op: 'session.initialize', secondary: true },
|
|
187
|
+
{ from: 'starting', to: 'booting', op: 'session.start' },
|
|
188
|
+
{ from: 'booting', to: 'ready', op: 'session.ready' },
|
|
189
|
+
{ from: 'booting', to: 'turn.thinking', op: 'turn.start', secondary: true },
|
|
190
|
+
{ from: 'ready', to: 'turn.thinking', op: 'turn.start' },
|
|
191
|
+
{ from: 'turn.thinking', to: 'turn.thinking', op: 'assistant.delta' },
|
|
192
|
+
{ from: 'turn.thinking', to: 'turn.tool', op: 'tool.start' },
|
|
193
|
+
{ from: 'turn.thinking', to: 'turn.approval', op: 'permission.ask' },
|
|
194
|
+
{ from: 'turn.tool', to: 'turn.thinking', op: 'tool.end' },
|
|
195
|
+
{ from: 'turn.tool', to: 'turn.approval', op: 'permission.ask' },
|
|
196
|
+
{ from: 'turn.approval', to: 'turn.tool', op: 'tool.start' },
|
|
197
|
+
{ from: 'turn.approval', to: 'turn.thinking', op: 'tool.end' },
|
|
198
|
+
{ from: 'turn.thinking', to: 'ready', op: 'turn.end' },
|
|
199
|
+
// `turn.end` is handled on the compound state, so it is legal from every
|
|
200
|
+
// child. Drawing all three keeps the picture honest; two are dimmed
|
|
201
|
+
// because ending mid-tool or mid-approval is a fault path, not a turn.
|
|
202
|
+
{ from: 'turn.tool', to: 'ready', op: 'turn.end', secondary: true },
|
|
203
|
+
{ from: 'turn.approval', to: 'ready', op: 'turn.end', secondary: true },
|
|
204
|
+
],
|
|
205
|
+
globals: [
|
|
206
|
+
{ op: 'session.end', to: 'ended', note: 'legal from any state' },
|
|
207
|
+
{ op: 'usage.refresh', note: 'heartbeat — changes no state' },
|
|
208
|
+
],
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=scenario-driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenario-driver.js","sourceRoot":"","sources":["../../src/session/scenario-driver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAoC,MAAM,QAAQ,CAAC;AAC9F,OAAO,EAAE,QAAQ,EAAe,MAAM,qBAAqB,CAAC;AA6B5D;;;;GAIG;AACH,MAAM,UAAU,GAAG;IACjB,EAAE,EAAE,kBAAkB;IACtB,OAAO,EAAE,UAAU;IACnB,OAAO,EAAE,EAAE,UA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E,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,UAAU,EAAE;YAC1D,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,gBAAgB,EAAE;YAChE,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,YAAY,EAAE;YAC5D,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,UAAU,EAAE;YAC9D,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE;YACtD,yEAAyE;YACzE,oEAAoE;YACpE,uEAAuE;YACvE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE;YACnE,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE;SACxE;QACD,OAAO,EAAE;YACP,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,sBAAsB,EAAE;YAChE,EAAE,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,8BAA8B,EAAE;SAC9D;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scenario runner — the raw layer beneath the op timeline (docs/archive/IMPOSTER.md §2).
|
|
3
|
+
*
|
|
4
|
+
* Ops describe organic turns; scenarios describe everything adversarial that
|
|
5
|
+
* ops cannot express by definition — faults, duplicates, out-of-order arrival,
|
|
6
|
+
* floods, and unknown native events (there is no op for an event the model has
|
|
7
|
+
* never seen). Both reach the channels, but only ops fan out to the
|
|
8
|
+
* presentation projection.
|
|
9
|
+
*
|
|
10
|
+
* The entire script is structurally and schema-validated BEFORE the first side
|
|
11
|
+
* effect, so a typo late in an inline script cannot leave a half-applied
|
|
12
|
+
* scenario behind (§7.3 item 2).
|
|
13
|
+
*/
|
|
14
|
+
import type { TranscriptWriter } from './channels/transcript.ts';
|
|
15
|
+
export interface ScenarioAction {
|
|
16
|
+
emit?: {
|
|
17
|
+
channel?: string;
|
|
18
|
+
event: string;
|
|
19
|
+
with?: Record<string, unknown>;
|
|
20
|
+
afterMs?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Send as a SERVER request and wait for the client's answer, rather than as
|
|
23
|
+
* a notification. Codex's approvals genuinely are requests with ids — a
|
|
24
|
+
* scenario that emitted one as a notification would be scripting traffic
|
|
25
|
+
* the vendor never produces, and the adapter would never reply to it.
|
|
26
|
+
*/
|
|
27
|
+
request?: boolean;
|
|
28
|
+
};
|
|
29
|
+
transcript?: {
|
|
30
|
+
record: Record<string, unknown>;
|
|
31
|
+
};
|
|
32
|
+
statusline?: {
|
|
33
|
+
with: Record<string, unknown>;
|
|
34
|
+
};
|
|
35
|
+
delay?: {
|
|
36
|
+
ms: number;
|
|
37
|
+
};
|
|
38
|
+
fault?: {
|
|
39
|
+
kind: 'crash' | 'exit' | 'hang' | 'flood' | 'channel-drop';
|
|
40
|
+
exitCode?: number;
|
|
41
|
+
partialTranscriptLine?: string;
|
|
42
|
+
channel?: string;
|
|
43
|
+
count?: number;
|
|
44
|
+
event?: string;
|
|
45
|
+
with?: Record<string, unknown>;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export interface ScenarioTimelineStep {
|
|
49
|
+
/** Milliseconds from the timeline origin, before speed scaling. */
|
|
50
|
+
at: number;
|
|
51
|
+
do: ScenarioAction;
|
|
52
|
+
}
|
|
53
|
+
/** Behavior packs use direct actions; named scenarios may use `at`/`do` timelines. */
|
|
54
|
+
export type ScenarioStep = ScenarioAction | ScenarioTimelineStep;
|
|
55
|
+
export type ScenarioFault = NonNullable<ScenarioAction['fault']>;
|
|
56
|
+
export interface ScenarioRunnerOptions {
|
|
57
|
+
emit: (event: string, payload: Record<string, unknown>, channel?: string) => Promise<void>;
|
|
58
|
+
/** Server-initiated request, for `emit.request` (the JSON-RPC family only). */
|
|
59
|
+
request?: (event: string, payload: Record<string, unknown>) => Promise<unknown>;
|
|
60
|
+
transcript: TranscriptWriter;
|
|
61
|
+
/** ASM payload validation; violations fail the run before anything is emitted. */
|
|
62
|
+
validate?: (event: string, payload: Record<string, unknown>) => string[];
|
|
63
|
+
/** Extra template bindings beyond $stimulus.* (e.g. $reply from a behavior pack). */
|
|
64
|
+
bindings?: Record<string, unknown>;
|
|
65
|
+
statusline?: (payload: Record<string, unknown>) => Promise<void>;
|
|
66
|
+
fault?: (fault: ScenarioFault) => void | Promise<void>;
|
|
67
|
+
/** Legacy/default crash behavior when no general fault handler is supplied. */
|
|
68
|
+
crash?: (exitCode: number) => void;
|
|
69
|
+
log?: (message: string) => void;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The pause/step gate (docs/archive/IMPOSTER.md §5.1). The runner awaits this between
|
|
73
|
+
* prepared steps, which is the whole mechanism behind `scenario.control` — a
|
|
74
|
+
* held control connection can release one step at a time and watch the emitted
|
|
75
|
+
* traffic arrive between them.
|
|
76
|
+
*/
|
|
77
|
+
export interface ScenarioGate {
|
|
78
|
+
/** Resolves immediately while running; blocks while paused. */
|
|
79
|
+
wait(): Promise<void>;
|
|
80
|
+
pause(): void;
|
|
81
|
+
resume(): void;
|
|
82
|
+
/** Release exactly one step, then hold again. */
|
|
83
|
+
step(): void;
|
|
84
|
+
readonly paused: boolean;
|
|
85
|
+
}
|
|
86
|
+
export declare function createScenarioGate(initial?: 'play' | 'pause' | 'step'): ScenarioGate;
|
|
87
|
+
export interface ScenarioRunOptions {
|
|
88
|
+
speed?: number;
|
|
89
|
+
gate?: ScenarioGate;
|
|
90
|
+
/** Called after each completed step; this is control metadata, not evidence. */
|
|
91
|
+
onProgress?: (progress: {
|
|
92
|
+
step: number;
|
|
93
|
+
steps: number;
|
|
94
|
+
}) => void;
|
|
95
|
+
}
|
|
96
|
+
/** A fully validated scenario that has not yet touched a channel. */
|
|
97
|
+
export interface PreparedScenario {
|
|
98
|
+
readonly steps: number;
|
|
99
|
+
play(): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
export interface ScenarioRunner {
|
|
102
|
+
/**
|
|
103
|
+
* Validate a whole script without running it. Splitting preparation from
|
|
104
|
+
* playback is what lets a paused run answer its caller immediately: the
|
|
105
|
+
* request is already known to be well-formed, and progress is observed
|
|
106
|
+
* through pushed emissions rather than a reply that would not arrive until
|
|
107
|
+
* the console pressed resume.
|
|
108
|
+
*/
|
|
109
|
+
prepare(steps: readonly ScenarioStep[], stimulus?: Record<string, unknown>, options?: ScenarioRunOptions): PreparedScenario;
|
|
110
|
+
run(steps: readonly ScenarioStep[], stimulus?: Record<string, unknown>, options?: ScenarioRunOptions): Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Unwrap a scenario document into its steps. Named scenario files carry a
|
|
114
|
+
* `{ name, steps }` envelope; inline scripts from the control channel may be a
|
|
115
|
+
* bare array. `then` is accepted because the behavior packs use it.
|
|
116
|
+
*/
|
|
117
|
+
export declare function scenarioSteps(document: unknown): ScenarioStep[];
|
|
118
|
+
export declare function createScenarioRunner(options: ScenarioRunnerOptions): ScenarioRunner;
|
|
119
|
+
//# sourceMappingURL=scenario.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenario.d.ts","sourceRoot":"","sources":["../../src/session/scenario.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGjE,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,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M,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAClE;AAED,qEAAqE;AACrE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,OAAO,CACL,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,gBAAgB,CAAC;IACpB,GAAG,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtH;AAKD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,YAAY,EAAE,CAO/D;AAiBD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAqPnF"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scenario runner — the raw layer beneath the op timeline (docs/archive/IMPOSTER.md §2).
|
|
3
|
+
*
|
|
4
|
+
* Ops describe organic turns; scenarios describe everything adversarial that
|
|
5
|
+
* ops cannot express by definition — faults, duplicates, out-of-order arrival,
|
|
6
|
+
* floods, and unknown native events (there is no op for an event the model has
|
|
7
|
+
* never seen). Both reach the channels, but only ops fan out to the
|
|
8
|
+
* presentation projection.
|
|
9
|
+
*
|
|
10
|
+
* The entire script is structurally and schema-validated BEFORE the first side
|
|
11
|
+
* effect, so a typo late in an inline script cannot leave a half-applied
|
|
12
|
+
* scenario behind (§7.3 item 2).
|
|
13
|
+
*/
|
|
14
|
+
import { substitute } from "./template.js";
|
|
15
|
+
export function createScenarioGate(initial = 'play') {
|
|
16
|
+
let paused = initial !== 'play';
|
|
17
|
+
// Credits cover the race where `step` arrives before the runner reaches its
|
|
18
|
+
// next `wait` — without them the release would be lost and the scenario would
|
|
19
|
+
// sit forever one step behind the console.
|
|
20
|
+
let credits = initial === 'step' ? 1 : 0;
|
|
21
|
+
let waiters = [];
|
|
22
|
+
return {
|
|
23
|
+
get paused() {
|
|
24
|
+
return paused;
|
|
25
|
+
},
|
|
26
|
+
wait() {
|
|
27
|
+
if (!paused)
|
|
28
|
+
return Promise.resolve();
|
|
29
|
+
if (credits > 0) {
|
|
30
|
+
credits -= 1;
|
|
31
|
+
return Promise.resolve();
|
|
32
|
+
}
|
|
33
|
+
return new Promise((resolve) => waiters.push(resolve));
|
|
34
|
+
},
|
|
35
|
+
pause() {
|
|
36
|
+
paused = true;
|
|
37
|
+
},
|
|
38
|
+
resume() {
|
|
39
|
+
paused = false;
|
|
40
|
+
credits = 0;
|
|
41
|
+
const released = waiters;
|
|
42
|
+
waiters = [];
|
|
43
|
+
for (const resolve of released)
|
|
44
|
+
resolve();
|
|
45
|
+
},
|
|
46
|
+
step() {
|
|
47
|
+
paused = true;
|
|
48
|
+
const next = waiters.shift();
|
|
49
|
+
if (next)
|
|
50
|
+
next();
|
|
51
|
+
else
|
|
52
|
+
credits += 1;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const MAX_DELAY_MS = 5 * 60 * 1000;
|
|
57
|
+
const MAX_STEPS = 10_000;
|
|
58
|
+
/**
|
|
59
|
+
* Unwrap a scenario document into its steps. Named scenario files carry a
|
|
60
|
+
* `{ name, steps }` envelope; inline scripts from the control channel may be a
|
|
61
|
+
* bare array. `then` is accepted because the behavior packs use it.
|
|
62
|
+
*/
|
|
63
|
+
export function scenarioSteps(document) {
|
|
64
|
+
if (Array.isArray(document))
|
|
65
|
+
return document;
|
|
66
|
+
if (document === null || typeof document !== 'object')
|
|
67
|
+
throw new Error('scenario must be a JSON object or array');
|
|
68
|
+
const record = document;
|
|
69
|
+
const steps = Array.isArray(record.steps) ? record.steps : record.then;
|
|
70
|
+
if (!Array.isArray(steps))
|
|
71
|
+
throw new Error('scenario must contain a steps or then array');
|
|
72
|
+
return steps;
|
|
73
|
+
}
|
|
74
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
75
|
+
function rejectUnknownFields(value, allowed, label) {
|
|
76
|
+
const unknown = Object.keys(value).filter((field) => !allowed.includes(field));
|
|
77
|
+
if (unknown.length > 0)
|
|
78
|
+
throw new Error(`${label} has unknown field(s): ${unknown.join(', ')}`);
|
|
79
|
+
}
|
|
80
|
+
function boundedMs(value, label) {
|
|
81
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value > MAX_DELAY_MS) {
|
|
82
|
+
throw new Error(`${label} must be between 0 and ${MAX_DELAY_MS}ms`);
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
export function createScenarioRunner(options) {
|
|
87
|
+
const log = options.log ?? (() => { });
|
|
88
|
+
const crash = options.crash ?? ((exitCode) => process.exit(exitCode));
|
|
89
|
+
const prepareScenario = (steps, stimulus = {}, runOptions = {}) => {
|
|
90
|
+
if (!Array.isArray(steps) || steps.length > MAX_STEPS) {
|
|
91
|
+
throw new Error(`scenario steps must be an array with at most ${MAX_STEPS} entries`);
|
|
92
|
+
}
|
|
93
|
+
const speed = runOptions.speed ?? 1;
|
|
94
|
+
if (!Number.isFinite(speed) || speed <= 0 || speed > 100) {
|
|
95
|
+
throw new Error('scenario speed must be greater than 0 and at most 100');
|
|
96
|
+
}
|
|
97
|
+
const prepared = [];
|
|
98
|
+
const validationUuids = new Map();
|
|
99
|
+
let timelineAt = 0;
|
|
100
|
+
let totalWaitMs = 0;
|
|
101
|
+
for (const step of steps) {
|
|
102
|
+
if (!isRecord(step))
|
|
103
|
+
throw new Error('each scenario step must be an object');
|
|
104
|
+
const timelineStep = Object.hasOwn(step, 'do');
|
|
105
|
+
const rawAction = timelineStep ? step.do : step;
|
|
106
|
+
if (!isRecord(rawAction))
|
|
107
|
+
throw new Error('each scenario action must be an object');
|
|
108
|
+
const action = rawAction;
|
|
109
|
+
let waitMs = 0;
|
|
110
|
+
if (timelineStep) {
|
|
111
|
+
rejectUnknownFields(step, ['at', 'do'], 'scenario timeline step');
|
|
112
|
+
if (typeof step.at !== 'number' ||
|
|
113
|
+
!Number.isFinite(step.at) ||
|
|
114
|
+
step.at < timelineAt ||
|
|
115
|
+
step.at > MAX_DELAY_MS) {
|
|
116
|
+
throw new Error(`scenario timeline must be finite, sorted, and between 0 and ${MAX_DELAY_MS}ms (got ${String(step.at)})`);
|
|
117
|
+
}
|
|
118
|
+
waitMs += step.at - timelineAt;
|
|
119
|
+
timelineAt = step.at;
|
|
120
|
+
}
|
|
121
|
+
rejectUnknownFields(action, ['delay', 'emit', 'transcript', 'statusline', 'fault'], 'scenario action');
|
|
122
|
+
const actionCount = [action.delay, action.emit, action.transcript, action.statusline, action.fault].filter((value) => value !== undefined).length;
|
|
123
|
+
if (actionCount !== 1)
|
|
124
|
+
throw new Error('each scenario step must contain exactly one action');
|
|
125
|
+
if (action.delay !== undefined) {
|
|
126
|
+
if (!isRecord(action.delay))
|
|
127
|
+
throw new Error('scenario delay must be an object');
|
|
128
|
+
rejectUnknownFields(action.delay, ['ms'], 'scenario delay');
|
|
129
|
+
waitMs += boundedMs(action.delay.ms, 'scenario delay');
|
|
130
|
+
}
|
|
131
|
+
if (action.emit !== undefined) {
|
|
132
|
+
if (!isRecord(action.emit))
|
|
133
|
+
throw new Error('scenario emit must be an object');
|
|
134
|
+
rejectUnknownFields(action.emit, ['channel', 'event', 'with', 'afterMs', 'request'], 'scenario emit');
|
|
135
|
+
if (action.emit.request !== undefined && typeof action.emit.request !== 'boolean') {
|
|
136
|
+
throw new Error('scenario emit.request must be a boolean');
|
|
137
|
+
}
|
|
138
|
+
if (action.emit.request === true && !options.request) {
|
|
139
|
+
throw new Error('scenario emit.request needs a server-request handler');
|
|
140
|
+
}
|
|
141
|
+
if (typeof action.emit.event !== 'string' || action.emit.event.length === 0 || action.emit.event.length > 256) {
|
|
142
|
+
throw new Error('scenario emit.event must be a non-empty string of at most 256 characters');
|
|
143
|
+
}
|
|
144
|
+
if (action.emit.channel !== undefined &&
|
|
145
|
+
(typeof action.emit.channel !== 'string' ||
|
|
146
|
+
action.emit.channel.length === 0 ||
|
|
147
|
+
action.emit.channel.length > 128)) {
|
|
148
|
+
throw new Error('scenario emit.channel must be a non-empty string of at most 128 characters');
|
|
149
|
+
}
|
|
150
|
+
if (action.emit.with !== undefined && !isRecord(action.emit.with)) {
|
|
151
|
+
throw new Error('scenario emit.with must be an object');
|
|
152
|
+
}
|
|
153
|
+
if (action.emit.afterMs !== undefined)
|
|
154
|
+
waitMs += boundedMs(action.emit.afterMs, 'emit.afterMs');
|
|
155
|
+
// Validate exactly the payload that will hit the wire, with template
|
|
156
|
+
// bindings already resolved — an off-model scenario must fail before
|
|
157
|
+
// it emits anything at all.
|
|
158
|
+
const preview = substitute(action.emit.with ?? {}, {
|
|
159
|
+
scopes: { stimulus },
|
|
160
|
+
bindings: options.bindings,
|
|
161
|
+
uuids: validationUuids,
|
|
162
|
+
});
|
|
163
|
+
const violations = options.validate?.(action.emit.event, preview) ?? [];
|
|
164
|
+
if (violations.length > 0) {
|
|
165
|
+
throw new Error(`imposter emitted off-model payload for ${action.emit.event}: ${violations.join('; ')}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (action.transcript !== undefined) {
|
|
169
|
+
if (!isRecord(action.transcript))
|
|
170
|
+
throw new Error('scenario transcript must be an object');
|
|
171
|
+
rejectUnknownFields(action.transcript, ['record'], 'scenario transcript');
|
|
172
|
+
if (!isRecord(action.transcript.record))
|
|
173
|
+
throw new Error('scenario transcript.record must be an object');
|
|
174
|
+
}
|
|
175
|
+
if (action.statusline !== undefined) {
|
|
176
|
+
if (!isRecord(action.statusline))
|
|
177
|
+
throw new Error('scenario statusline must be an object');
|
|
178
|
+
rejectUnknownFields(action.statusline, ['with'], 'scenario statusline');
|
|
179
|
+
if (!isRecord(action.statusline.with))
|
|
180
|
+
throw new Error('scenario statusline.with must be an object');
|
|
181
|
+
if (!options.statusline)
|
|
182
|
+
throw new Error('scenario requested statusline but no invoker is configured');
|
|
183
|
+
}
|
|
184
|
+
if (action.fault !== undefined) {
|
|
185
|
+
if (!isRecord(action.fault))
|
|
186
|
+
throw new Error('scenario fault must be an object');
|
|
187
|
+
rejectUnknownFields(action.fault, ['kind', 'exitCode', 'partialTranscriptLine', 'channel', 'count', 'event', 'with'], 'scenario fault');
|
|
188
|
+
if (!['crash', 'exit', 'hang', 'flood', 'channel-drop'].includes(action.fault.kind)) {
|
|
189
|
+
throw new Error(`unsupported scenario fault ${String(action.fault.kind)}`);
|
|
190
|
+
}
|
|
191
|
+
if (action.fault.count !== undefined &&
|
|
192
|
+
(!Number.isInteger(action.fault.count) || action.fault.count < 1 || action.fault.count > 10_000)) {
|
|
193
|
+
throw new Error('scenario fault count must be an integer from 1 to 10000');
|
|
194
|
+
}
|
|
195
|
+
if (action.fault.channel !== undefined &&
|
|
196
|
+
(typeof action.fault.channel !== 'string' ||
|
|
197
|
+
action.fault.channel.length === 0 ||
|
|
198
|
+
action.fault.channel.length > 128)) {
|
|
199
|
+
throw new Error('scenario fault channel must be a non-empty string of at most 128 characters');
|
|
200
|
+
}
|
|
201
|
+
if (action.fault.event !== undefined &&
|
|
202
|
+
(typeof action.fault.event !== 'string' || action.fault.event.length === 0 || action.fault.event.length > 256)) {
|
|
203
|
+
throw new Error('scenario fault event must be a non-empty string of at most 256 characters');
|
|
204
|
+
}
|
|
205
|
+
if (action.fault.exitCode !== undefined &&
|
|
206
|
+
(!Number.isInteger(action.fault.exitCode) || action.fault.exitCode < 0 || action.fault.exitCode > 255)) {
|
|
207
|
+
throw new Error('scenario fault exitCode must be an integer from 0 to 255');
|
|
208
|
+
}
|
|
209
|
+
if (action.fault.partialTranscriptLine !== undefined &&
|
|
210
|
+
(typeof action.fault.partialTranscriptLine !== 'string' ||
|
|
211
|
+
Buffer.byteLength(action.fault.partialTranscriptLine) > 64 * 1024)) {
|
|
212
|
+
throw new Error('scenario partial transcript line must be a string of at most 65536 bytes');
|
|
213
|
+
}
|
|
214
|
+
if (action.fault.with !== undefined && !isRecord(action.fault.with)) {
|
|
215
|
+
throw new Error('scenario fault with must be an object');
|
|
216
|
+
}
|
|
217
|
+
if (!options.fault && action.fault.kind !== 'crash') {
|
|
218
|
+
throw new Error(`scenario fault ${action.fault.kind} requires a fault handler`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
totalWaitMs += waitMs;
|
|
222
|
+
if (totalWaitMs / speed > MAX_DELAY_MS) {
|
|
223
|
+
throw new Error(`scenario's total scaled delay must be at most ${MAX_DELAY_MS}ms`);
|
|
224
|
+
}
|
|
225
|
+
prepared.push({ action, waitMs });
|
|
226
|
+
}
|
|
227
|
+
// Validation above is deliberately complete before the first side effect.
|
|
228
|
+
return {
|
|
229
|
+
steps: prepared.length,
|
|
230
|
+
play: async () => {
|
|
231
|
+
const uuids = new Map();
|
|
232
|
+
let completed = 0;
|
|
233
|
+
const report = () => {
|
|
234
|
+
completed += 1;
|
|
235
|
+
runOptions.onProgress?.({ step: completed, steps: prepared.length });
|
|
236
|
+
};
|
|
237
|
+
for (const { action, waitMs } of prepared) {
|
|
238
|
+
// The gate comes before the delay so a paused scenario holds at the
|
|
239
|
+
// step boundary rather than partway through its wait.
|
|
240
|
+
await runOptions.gate?.wait();
|
|
241
|
+
if (waitMs > 0)
|
|
242
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs / speed));
|
|
243
|
+
if (action.delay !== undefined) {
|
|
244
|
+
report();
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (action.emit !== undefined) {
|
|
248
|
+
const payload = substitute(action.emit.with ?? {}, {
|
|
249
|
+
scopes: { stimulus },
|
|
250
|
+
bindings: options.bindings,
|
|
251
|
+
uuids,
|
|
252
|
+
});
|
|
253
|
+
if (action.emit.request)
|
|
254
|
+
await options.request(action.emit.event, payload);
|
|
255
|
+
else
|
|
256
|
+
await options.emit(action.emit.event, payload, action.emit.channel);
|
|
257
|
+
report();
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (action.transcript !== undefined) {
|
|
261
|
+
options.transcript.append(substitute(action.transcript.record, {
|
|
262
|
+
scopes: { stimulus },
|
|
263
|
+
bindings: options.bindings,
|
|
264
|
+
uuids,
|
|
265
|
+
}));
|
|
266
|
+
report();
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (action.statusline !== undefined) {
|
|
270
|
+
await options.statusline(substitute(action.statusline.with, { scopes: { stimulus }, bindings: options.bindings, uuids }));
|
|
271
|
+
report();
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
if (action.fault !== undefined) {
|
|
275
|
+
if (action.fault.partialTranscriptLine)
|
|
276
|
+
options.transcript.appendPartial(action.fault.partialTranscriptLine);
|
|
277
|
+
log(`fault: ${action.fault.kind}`);
|
|
278
|
+
if (options.fault)
|
|
279
|
+
await options.fault(action.fault);
|
|
280
|
+
else
|
|
281
|
+
crash(action.fault.exitCode ?? 1);
|
|
282
|
+
report();
|
|
283
|
+
if (['crash', 'exit', 'hang'].includes(action.fault.kind))
|
|
284
|
+
return;
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
return {
|
|
292
|
+
prepare: prepareScenario,
|
|
293
|
+
// `async` so a preparation failure stays a rejection for `run` callers;
|
|
294
|
+
// `prepare` keeps throwing synchronously, which is what lets the control
|
|
295
|
+
// channel answer a malformed scenario before starting anything.
|
|
296
|
+
run: async (steps, stimulus, runOptions) => prepareScenario(steps, stimulus, runOptions).play(),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=scenario.js.map
|