@arnilo/prism-hosts 0.0.0-stage → 0.13.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/CHANGELOG.md +394 -0
- package/LICENSE +21 -0
- package/README.md +34 -2
- package/acp/README.md +87 -0
- package/acp/src/capabilities.ts +184 -0
- package/acp/src/errors.ts +24 -0
- package/acp/src/host.ts +36 -0
- package/acp/src/index.ts +25 -0
- package/acp/src/limits.ts +49 -0
- package/acp/src/mapper.ts +419 -0
- package/acp/src/permission.ts +37 -0
- package/acp/src/projection.ts +39 -0
- package/acp/src/prompt.ts +170 -0
- package/acp/src/serve.ts +345 -0
- package/acp/src/session-map.ts +49 -0
- package/ag-ui/README.md +56 -0
- package/ag-ui/src/a2ui.ts +570 -0
- package/ag-ui/src/ag-ui-mapper.ts +507 -0
- package/ag-ui/src/encrypted-value.ts +40 -0
- package/ag-ui/src/errors.ts +29 -0
- package/ag-ui/src/handler.ts +642 -0
- package/ag-ui/src/index.ts +177 -0
- package/ag-ui/src/input.ts +190 -0
- package/ag-ui/src/limits.ts +279 -0
- package/ag-ui/src/mcp-apps.ts +256 -0
- package/ag-ui/src/mcp.ts +94 -0
- package/ag-ui/src/projection.ts +201 -0
- package/ag-ui/src/projectors.ts +272 -0
- package/ag-ui/src/renderer/bind.ts +152 -0
- package/ag-ui/src/renderer/core.ts +270 -0
- package/ag-ui/src/renderer/index.ts +165 -0
- package/ag-ui/src/replay.ts +189 -0
- package/ag-ui/src/types.ts +66 -0
- package/channels/README.md +139 -0
- package/channels/src/admission.ts +8 -0
- package/channels/src/approvals.ts +262 -0
- package/channels/src/checkpoint-contract.ts +97 -0
- package/channels/src/delivery.ts +116 -0
- package/channels/src/host-ui.ts +356 -0
- package/channels/src/identity.ts +46 -0
- package/channels/src/index.ts +82 -0
- package/channels/src/limits.ts +49 -0
- package/channels/src/memory-stores.ts +112 -0
- package/channels/src/pairing.ts +178 -0
- package/channels/src/runtime-admit.ts +389 -0
- package/channels/src/runtime-core.ts +621 -0
- package/channels/src/runtime-reconcile.ts +299 -0
- package/channels/src/runtime-turn.ts +664 -0
- package/channels/src/runtime-types.ts +95 -0
- package/channels/src/runtime.ts +86 -0
- package/channels/src/secret-ref.ts +42 -0
- package/channels/src/signal.ts +790 -0
- package/channels/src/state.ts +355 -0
- package/channels/src/telegram.ts +1317 -0
- package/channels/src/types.ts +442 -0
- package/devtools/README.md +92 -0
- package/devtools/bin/prism-devtools.ts +63 -0
- package/devtools/src/args.ts +71 -0
- package/devtools/src/bun.d.ts +27 -0
- package/devtools/src/compare.ts +190 -0
- package/devtools/src/errors.ts +15 -0
- package/devtools/src/index.ts +25 -0
- package/devtools/src/replay.ts +36 -0
- package/devtools/src/security.ts +80 -0
- package/devtools/src/serve.ts +259 -0
- package/devtools/src/ui/assets.ts +108 -0
- package/devtools/src/ui/inspector.ts +182 -0
- package/driver-process/README.md +197 -0
- package/driver-process/src/abort.ts +74 -0
- package/driver-process/src/adapter.ts +211 -0
- package/driver-process/src/driver.ts +303 -0
- package/driver-process/src/errors.ts +17 -0
- package/driver-process/src/extend.ts +72 -0
- package/driver-process/src/index.ts +5 -0
- package/driver-process/src/inspect.ts +33 -0
- package/driver-process/src/session.ts +72 -0
- package/driver-process/src/testing.ts +394 -0
- package/driver-process/src/transports/json-rpc.ts +147 -0
- package/driver-process/src/transports/jsonl-stream.ts +12 -0
- package/driver-process/src/transports/types.ts +11 -0
- package/driver-process/src/turn.ts +106 -0
- package/evals/README.md +843 -0
- package/evals/src/calibration.ts +179 -0
- package/evals/src/citation-integrity.ts +98 -0
- package/evals/src/citations.ts +45 -0
- package/evals/src/compare-experiments.ts +153 -0
- package/evals/src/comparison.ts +230 -0
- package/evals/src/curate.ts +257 -0
- package/evals/src/dataset.ts +81 -0
- package/evals/src/erp-invariants.ts +163 -0
- package/evals/src/errors.ts +23 -0
- package/evals/src/experiment.ts +537 -0
- package/evals/src/failure-injection.ts +77 -0
- package/evals/src/feedback.ts +53 -0
- package/evals/src/index.ts +198 -0
- package/evals/src/injection.ts +247 -0
- package/evals/src/judge-panel.ts +109 -0
- package/evals/src/judge.ts +89 -0
- package/evals/src/limits.ts +50 -0
- package/evals/src/report-record.ts +47 -0
- package/evals/src/rubric-judge.ts +334 -0
- package/evals/src/scenario-runner.ts +317 -0
- package/evals/src/scenarios.ts +81 -0
- package/evals/src/score.ts +328 -0
- package/evals/src/scorer.ts +21 -0
- package/evals/src/state-match.ts +130 -0
- package/evals/src/stats.ts +635 -0
- package/evals/src/threshold.ts +117 -0
- package/evals/src/timeline.ts +38 -0
- package/evals/src/toolless-session.ts +33 -0
- package/evals/src/trace.ts +80 -0
- package/evals/src/trajectory.ts +623 -0
- package/evals/src/types.ts +672 -0
- package/evals/src/user-simulator.ts +101 -0
- package/evals/src/util.ts +207 -0
- package/headless/README.md +172 -0
- package/headless/src/answers.ts +91 -0
- package/headless/src/authority.ts +32 -0
- package/headless/src/errors.ts +36 -0
- package/headless/src/index.ts +17 -0
- package/headless/src/limits.ts +11 -0
- package/headless/src/pending.ts +16 -0
- package/headless/src/policy.ts +36 -0
- package/headless/src/resume.ts +103 -0
- package/headless/src/route.ts +153 -0
- package/headless/src/scheduler/clock.ts +22 -0
- package/headless/src/scheduler/cron.ts +19 -0
- package/headless/src/scheduler/firing.ts +58 -0
- package/headless/src/scheduler/index.ts +399 -0
- package/headless/src/scheduler/lease.ts +38 -0
- package/headless/src/scheduler/missed.ts +12 -0
- package/headless/src/scheduler/state.ts +132 -0
- package/host-builder/README.md +251 -0
- package/host-builder/bin/prism-host-builder.ts +169 -0
- package/host-builder/data/api.json +6197 -0
- package/host-builder/data/errors.json +558 -0
- package/host-builder/data/examples/acp.ts +63 -0
- package/host-builder/data/examples/adapters/conformance.ts +34 -0
- package/host-builder/data/examples/adapters/fixtures/rpc-server.json +26 -0
- package/host-builder/data/examples/adapters/fixtures/stream-cli.json +27 -0
- package/host-builder/data/examples/adapters/fixtures/workspace-config.json +28 -0
- package/host-builder/data/examples/adapters/rpc-server.dialect.ts +218 -0
- package/host-builder/data/examples/adapters/rpc-server.ts +309 -0
- package/host-builder/data/examples/adapters/stream-cli.dialect.ts +165 -0
- package/host-builder/data/examples/adapters/stream-cli.ts +256 -0
- package/host-builder/data/examples/adapters/workspace-config.dialect.ts +172 -0
- package/host-builder/data/examples/adapters/workspace-config.ts +251 -0
- package/host-builder/data/examples/advisor.ts +94 -0
- package/host-builder/data/examples/ag-ui-a2ui.ts +80 -0
- package/host-builder/data/examples/ag-ui-mcp-apps.ts +44 -0
- package/host-builder/data/examples/ag-ui-server.ts +118 -0
- package/host-builder/data/examples/agent-durable-approval.ts +43 -0
- package/host-builder/data/examples/api-key-auth.ts +23 -0
- package/host-builder/data/examples/approval.ts +92 -0
- package/host-builder/data/examples/attention-compiler.ts +81 -0
- package/host-builder/data/examples/autonomous-coding-loop.ts +343 -0
- package/host-builder/data/examples/behavior-evaluation.ts +303 -0
- package/host-builder/data/examples/build-workflow.ts +334 -0
- package/host-builder/data/examples/cache-aware-prompt-assembly.ts +139 -0
- package/host-builder/data/examples/caveman-ponytail.ts +197 -0
- package/host-builder/data/examples/cli.ts +31 -0
- package/host-builder/data/examples/coding-approval.ts +115 -0
- package/host-builder/data/examples/coding-browser-evaluation.ts +208 -0
- package/host-builder/data/examples/coding-compaction.ts +30 -0
- package/host-builder/data/examples/coding-goal-verify.ts +121 -0
- package/host-builder/data/examples/coding-tools-capability-gaps.ts +75 -0
- package/host-builder/data/examples/compaction.ts +36 -0
- package/host-builder/data/examples/connected-slack-mcp.ts +67 -0
- package/host-builder/data/examples/context.ts +29 -0
- package/host-builder/data/examples/custom-adapter.ts +256 -0
- package/host-builder/data/examples/custom-builders.ts +66 -0
- package/host-builder/data/examples/custom-loop.ts +89 -0
- package/host-builder/data/examples/custom-provider.ts +70 -0
- package/host-builder/data/examples/custom-session-store.ts +72 -0
- package/host-builder/data/examples/custom-tools-skills-context.ts +97 -0
- package/host-builder/data/examples/decision-models.ts +98 -0
- package/host-builder/data/examples/define-package.ts +188 -0
- package/host-builder/data/examples/delegate.ts +200 -0
- package/host-builder/data/examples/discover-skills.ts +65 -0
- package/host-builder/data/examples/drive-rag-sync.ts +44 -0
- package/host-builder/data/examples/durable-approval.ts +139 -0
- package/host-builder/data/examples/durable-investigation.ts +93 -0
- package/host-builder/data/examples/durable-loops-and-approvals.ts +94 -0
- package/host-builder/data/examples/enterprise-identity.ts +21 -0
- package/host-builder/data/examples/enterprise-policy-audit.ts +50 -0
- package/host-builder/data/examples/enterprise-work-connectors.ts +103 -0
- package/host-builder/data/examples/eval-injection.ts +73 -0
- package/host-builder/data/examples/eval-judges.ts +145 -0
- package/host-builder/data/examples/evals.ts +86 -0
- package/host-builder/data/examples/evaluation-gate.ts +40 -0
- package/host-builder/data/examples/execution-timeline.ts +173 -0
- package/host-builder/data/examples/external-agent.ts +541 -0
- package/host-builder/data/examples/external-app-db-backed.ts +344 -0
- package/host-builder/data/examples/governance-deny.ts +122 -0
- package/host-builder/data/examples/guardrail-packs.ts +240 -0
- package/host-builder/data/examples/headless-host.ts +245 -0
- package/host-builder/data/examples/hooks-audit-command.mjs +31 -0
- package/host-builder/data/examples/hooks-json.ts +87 -0
- package/host-builder/data/examples/host-builder-agent.ts +150 -0
- package/host-builder/data/examples/host-hooks.ts +71 -0
- package/host-builder/data/examples/host-step-loop-timeline.ts +212 -0
- package/host-builder/data/examples/hosted-sandbox.ts +48 -0
- package/host-builder/data/examples/instruction-injection.ts +127 -0
- package/host-builder/data/examples/jsonl-stores-branching.ts +49 -0
- package/host-builder/data/examples/long-term-memory.ts +158 -0
- package/host-builder/data/examples/manifest.ts +112 -0
- package/host-builder/data/examples/mcp-server.ts +48 -0
- package/host-builder/data/examples/mcp-trust.ts +173 -0
- package/host-builder/data/examples/memory-and-wiki.ts +315 -0
- package/host-builder/data/examples/memory-lifecycle.ts +302 -0
- package/host-builder/data/examples/memory-system.ts +255 -0
- package/host-builder/data/examples/messaging-agent.ts +70 -0
- package/host-builder/data/examples/minimal-host-app.ts +41 -0
- package/host-builder/data/examples/model-router-aggregate-budgets.ts +364 -0
- package/host-builder/data/examples/model-router.ts +106 -0
- package/host-builder/data/examples/obscura.ts +48 -0
- package/host-builder/data/examples/observability.ts +116 -0
- package/host-builder/data/examples/open-connector-sidecar.ts +105 -0
- package/host-builder/data/examples/openai-compatible.ts +70 -0
- package/host-builder/data/examples/package-skills.ts +85 -0
- package/host-builder/data/examples/phase9-coding-intelligence.ts +221 -0
- package/host-builder/data/examples/provider-registration.ts +29 -0
- package/host-builder/data/examples/provider-resolver.ts +39 -0
- package/host-builder/data/examples/rag.ts +40 -0
- package/host-builder/data/examples/remote-agent-server.ts +45 -0
- package/host-builder/data/examples/remote-agent.ts +124 -0
- package/host-builder/data/examples/research-ledger.ts +79 -0
- package/host-builder/data/examples/revocation-propagation.ts +287 -0
- package/host-builder/data/examples/run-feedback.ts +93 -0
- package/host-builder/data/examples/scanned-document-rag.ts +48 -0
- package/host-builder/data/examples/sdk-basics.ts +21 -0
- package/host-builder/data/examples/secure-agent.ts +55 -0
- package/host-builder/data/examples/semantic-memory.ts +52 -0
- package/host-builder/data/examples/serve-tools.ts +495 -0
- package/host-builder/data/examples/session-memory.ts +318 -0
- package/host-builder/data/examples/session-search.ts +131 -0
- package/host-builder/data/examples/session.ts +52 -0
- package/host-builder/data/examples/side-call.ts +68 -0
- package/host-builder/data/examples/signal-agent.ts +9 -0
- package/host-builder/data/examples/skills-progressive-disclosure.ts +88 -0
- package/host-builder/data/examples/skills.ts +19 -0
- package/host-builder/data/examples/sqlite-resume.ts +147 -0
- package/host-builder/data/examples/system-project-prompts.ts +74 -0
- package/host-builder/data/examples/system-prompts.ts +19 -0
- package/host-builder/data/examples/telegram-agent.ts +30 -0
- package/host-builder/data/examples/tool-narrowing-planes.ts +99 -0
- package/host-builder/data/examples/tools.ts +29 -0
- package/host-builder/data/examples/validator.ts +67 -0
- package/host-builder/data/examples/web-no-key.ts +85 -0
- package/host-builder/data/examples/web-research.ts +35 -0
- package/host-builder/data/examples/workflow-event-sink.ts +114 -0
- package/host-builder/data/examples/workflow-loop.ts +93 -0
- package/host-builder/data/examples/workflow-multimodal-document.ts +94 -0
- package/host-builder/data/examples/workflow-parallel-research.ts +111 -0
- package/host-builder/data/examples/workflow-postgres-resume.ts +75 -0
- package/host-builder/data/examples/workflow-research-and-review.ts +98 -0
- package/host-builder/data/examples/workflow-sqlite-resume.ts +163 -0
- package/host-builder/data/examples.json +130 -0
- package/host-builder/skills/prism-host-builder/SKILL.md +85 -0
- package/host-builder/skills/prism-host-builder/references/choosing.md +101 -0
- package/host-builder/skills/prism-host-builder/references/layout.md +52 -0
- package/host-builder/skills/prism-host-builder/references/pitfalls.md +50 -0
- package/host-builder/skills/prism-host-builder/references/recipes.md +129 -0
- package/host-builder/skills/prism-host-builder/references/security.md +52 -0
- package/host-builder/skills/prism-host-builder/references/upgrading.md +67 -0
- package/host-builder/skills/prism-host-builder/references/verification.md +108 -0
- package/host-builder/src/check/child.ts +108 -0
- package/host-builder/src/check/conformance.ts +13 -0
- package/host-builder/src/check/inspect.ts +20 -0
- package/host-builder/src/check/manifest.ts +23 -0
- package/host-builder/src/check/runner.ts +181 -0
- package/host-builder/src/check/targets.ts +65 -0
- package/host-builder/src/errors.ts +35 -0
- package/host-builder/src/index.ts +25 -0
- package/host-builder/src/indexes.ts +145 -0
- package/host-builder/src/install/install.ts +400 -0
- package/host-builder/src/install/targets.ts +50 -0
- package/host-builder/src/lookup/api.ts +127 -0
- package/host-builder/src/lookup/bound.ts +38 -0
- package/host-builder/src/lookup/docs.ts +238 -0
- package/host-builder/src/lookup/errors.ts +92 -0
- package/host-builder/src/lookup/examples.ts +117 -0
- package/host-builder/src/lookup/text.ts +60 -0
- package/host-builder/src/server.ts +300 -0
- package/host-builder/src/version.ts +38 -0
- package/mcp-server/README.md +219 -0
- package/mcp-server/src/bounds.ts +23 -0
- package/mcp-server/src/host.ts +31 -0
- package/mcp-server/src/index.ts +27 -0
- package/mcp-server/src/serve-tools.ts +408 -0
- package/mcp-server/src/serve.ts +329 -0
- package/mcp-server/src/server.ts +331 -0
- package/mcp-server/src/session-map.ts +47 -0
- package/mcp-server/src/skill-resources.ts +85 -0
- package/mcp-server/src/types.ts +215 -0
- package/package.json +130 -4
- package/remote/README.md +244 -0
- package/remote/src/attribution.ts +22 -0
- package/remote/src/auth.ts +30 -0
- package/remote/src/bun-module.d.ts +34 -0
- package/remote/src/channel.ts +86 -0
- package/remote/src/connect.ts +212 -0
- package/remote/src/dispatcher.ts +282 -0
- package/remote/src/errors.ts +59 -0
- package/remote/src/host-ui.ts +152 -0
- package/remote/src/http-gate.ts +43 -0
- package/remote/src/index.ts +53 -0
- package/remote/src/jsonl.ts +69 -0
- package/remote/src/limits.ts +43 -0
- package/remote/src/mirror.ts +90 -0
- package/remote/src/pending.ts +22 -0
- package/remote/src/protocol.ts +107 -0
- package/remote/src/serve.ts +560 -0
- package/remote/src/session-proxy.ts +219 -0
- package/remote/src/sse.ts +38 -0
- package/remote/src/stdio-client.ts +41 -0
- package/remote/src/testing-fixtures/serve-stdio.ts +32 -0
- package/remote/src/testing.ts +230 -0
- package/remote/src/transport.ts +139 -0
- package/remote/src/transports/client.ts +126 -0
- package/remote/src/transports/network.ts +268 -0
- package/remote/src/wire.ts +244 -0
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 13 end to end, offline: an external agent driven through `@arnilo/prism/driver-kit`.
|
|
3
|
+
*
|
|
4
|
+
* The driver below is the template an adapter author copies. It names no vendor. Its binary is the scripted CLI
|
|
5
|
+
* from `@arnilo/prism/testing`, which speaks the `jsonl-stream` dialect. The run shows, in order:
|
|
6
|
+
* - an account profile signed in through a terminal request, which runs the login command for real
|
|
7
|
+
* - a run under a replaced prompt with two bridged tools (called through the broker's MCP route), one materialized
|
|
8
|
+
* skill, thinking and text deltas, a skill activation, a nested sub-agent, and a steer during the run
|
|
9
|
+
* - a write gated through `prism relay` with a scripted HostUi, then a second write whose relay fails closed
|
|
10
|
+
* because the broker's socket is gone
|
|
11
|
+
* - a run suspended for approval and resumed with `allow_once`
|
|
12
|
+
* - a session search with `createSessionIndex`
|
|
13
|
+
* - the policy errors: `plan_login_not_permitted`, `profile_principal_mismatch`, and `profile_busy`
|
|
14
|
+
* Imports only `@arnilo/prism`, `@arnilo/prism/driver-kit`, and `@arnilo/prism/testing`, plus Node built-ins.
|
|
15
|
+
* Run: npm run build:core && bun examples/external-agent.ts
|
|
16
|
+
* With `--conformance`, it runs `driverConformance` on the same driver for both reference dialects instead.
|
|
17
|
+
*/
|
|
18
|
+
import { type ChildProcessWithoutNullStreams, spawn, spawnSync } from "node:child_process";
|
|
19
|
+
import { randomUUID } from "node:crypto";
|
|
20
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
21
|
+
import { tmpdir } from "node:os";
|
|
22
|
+
import { join, resolve } from "node:path";
|
|
23
|
+
import { createInterface } from "node:readline";
|
|
24
|
+
import { pathToFileURL } from "node:url";
|
|
25
|
+
import {
|
|
26
|
+
type AgentEvent,
|
|
27
|
+
type AgentInput,
|
|
28
|
+
type JsonObject,
|
|
29
|
+
type JsonValue,
|
|
30
|
+
type Message,
|
|
31
|
+
type Skill,
|
|
32
|
+
type ToolDefinition,
|
|
33
|
+
createAgent,
|
|
34
|
+
createMemorySessionStore,
|
|
35
|
+
createSessionIndex,
|
|
36
|
+
} from "@arnilo/prism";
|
|
37
|
+
import {
|
|
38
|
+
type CallbackBroker,
|
|
39
|
+
type DriverRunContext,
|
|
40
|
+
type HookCodec,
|
|
41
|
+
type ToolBridge,
|
|
42
|
+
buildChildEnv,
|
|
43
|
+
bridgeTools,
|
|
44
|
+
createCallbackBroker,
|
|
45
|
+
createProfiles,
|
|
46
|
+
createRunDirectory,
|
|
47
|
+
defineDriver,
|
|
48
|
+
driverPackage,
|
|
49
|
+
effectsTable,
|
|
50
|
+
materializeSkills,
|
|
51
|
+
relayCommand,
|
|
52
|
+
signalLadder,
|
|
53
|
+
} from "@arnilo/prism/driver-kit";
|
|
54
|
+
import {
|
|
55
|
+
type ScriptStep,
|
|
56
|
+
type ScriptedCli,
|
|
57
|
+
type ScriptedDialect,
|
|
58
|
+
createScriptedCli,
|
|
59
|
+
createScriptedHostUi,
|
|
60
|
+
driverConformance,
|
|
61
|
+
jsonRpcDialect,
|
|
62
|
+
jsonlStreamDialect,
|
|
63
|
+
} from "@arnilo/prism/testing";
|
|
64
|
+
|
|
65
|
+
/** The profile env var the login and status commands read. Its value is a path, never a credential. */
|
|
66
|
+
const HOME_ENV = "EXAMPLE_HOME";
|
|
67
|
+
|
|
68
|
+
type Agent = Awaited<ReturnType<typeof createAgent>>;
|
|
69
|
+
|
|
70
|
+
interface ExampleConfig {
|
|
71
|
+
/** The driver's own config keys. The spec never carries them. */
|
|
72
|
+
readonly binary: string;
|
|
73
|
+
readonly args?: readonly string[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** What the driver reports back to the example, for the structured output. */
|
|
77
|
+
interface Evidence {
|
|
78
|
+
readonly materialized: string[];
|
|
79
|
+
readonly bridged: { name: string; value: unknown }[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The descriptor is the driver's declaration: what the vendor can do, what it reports, and how it signs in. The
|
|
84
|
+
* kit checks `requires` against it, and the policy guard reads `auth` before every run.
|
|
85
|
+
*/
|
|
86
|
+
const descriptor = {
|
|
87
|
+
vendor: "example",
|
|
88
|
+
usesModel: false as const,
|
|
89
|
+
models: "passthrough" as const,
|
|
90
|
+
controls: {
|
|
91
|
+
systemPrompt: ["replace" as const, "append" as const],
|
|
92
|
+
builtinTools: "partial" as const,
|
|
93
|
+
clientTools: "mcp" as const,
|
|
94
|
+
skills: true,
|
|
95
|
+
subagents: true,
|
|
96
|
+
permissionCallback: true,
|
|
97
|
+
rewrite: false,
|
|
98
|
+
continueOnStop: true,
|
|
99
|
+
steer: "mid-turn" as const,
|
|
100
|
+
resume: "store" as const,
|
|
101
|
+
isolation: "flags" as const,
|
|
102
|
+
},
|
|
103
|
+
capture: {
|
|
104
|
+
textDeltas: true,
|
|
105
|
+
thinking: "deltas" as const,
|
|
106
|
+
skillActivation: "tool" as const,
|
|
107
|
+
toolCalls: true,
|
|
108
|
+
fileDiffs: true,
|
|
109
|
+
subagents: "summary" as const,
|
|
110
|
+
usage: "tokens" as const,
|
|
111
|
+
},
|
|
112
|
+
auth: {
|
|
113
|
+
modes: [
|
|
114
|
+
// A key mode needs no sign-in. `driverConformance` selects it, so the conformance legs need no account.
|
|
115
|
+
{ name: "key", kind: "api-key" as const, deployments: ["local" as const], protected: { paths: [".example/api-key"], env: [] } },
|
|
116
|
+
{
|
|
117
|
+
name: "account",
|
|
118
|
+
kind: "account" as const,
|
|
119
|
+
deployments: ["local" as const],
|
|
120
|
+
// Protected paths and variables are never opened or read by the kit (the canary checks this).
|
|
121
|
+
protected: { paths: [".example/credentials.json"], env: ["EXAMPLE_TOKEN"] },
|
|
122
|
+
// `{binary}` is replaced by the probed binary. Login runs in the host's terminal; status is parsed, then dropped.
|
|
123
|
+
login: ["{binary}", "-e", `require("node:fs").writeFileSync(process.env.${HOME_ENV} + "/signed-in", "ok")`],
|
|
124
|
+
status: ["{binary}", "-e", `process.exit(require("node:fs").existsSync(process.env.${HOME_ENV} + "/signed-in") ? 0 : 1)`],
|
|
125
|
+
homeEnv: HOME_ENV,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const tools: ToolDefinition[] = [
|
|
132
|
+
{
|
|
133
|
+
name: "lookup",
|
|
134
|
+
description: "Looks up a note by key.",
|
|
135
|
+
parameters: { type: "object", properties: { key: { type: "string" } }, required: ["key"] },
|
|
136
|
+
effects: ["read"],
|
|
137
|
+
execute: (args, context) => ({ toolCallId: context.toolCallId, name: "lookup", value: { key: String(args.key), found: true } }),
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: "note",
|
|
141
|
+
description: "Appends a note.",
|
|
142
|
+
parameters: { type: "object", properties: { text: { type: "string" } }, required: ["text"] },
|
|
143
|
+
effects: ["write"],
|
|
144
|
+
execute: (args, context) => ({ toolCallId: context.toolCallId, name: "note", value: { saved: String(args.text).length } }),
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
type Parts = { readonly evidence: Evidence };
|
|
149
|
+
|
|
150
|
+
const reviewNotes: Skill = { name: "review-notes", description: "Review the notes before editing.", instructions: "Read the notes first." };
|
|
151
|
+
|
|
152
|
+
/** The effects the gate reports for each name. An unknown name gets every effect, so it is gated as the riskiest. */
|
|
153
|
+
const effectOf = effectsTable({ lookup: ["read"], note: ["write"], write_file: ["write"] });
|
|
154
|
+
|
|
155
|
+
/** Fresh parts for one agent: the evidence the driver reports. The tools and skills it bridges come from the run context. */
|
|
156
|
+
export function exampleParts(): Parts {
|
|
157
|
+
return { evidence: { materialized: [], bridged: [] } };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The driver: a config schema, a status parser, and `start`, which probes the binary and runs one conversation. */
|
|
161
|
+
export function exampleDriver(parts: Parts = exampleParts(), dialect: ScriptedDialect = jsonlStreamDialect) {
|
|
162
|
+
return defineDriver<ExampleConfig>({
|
|
163
|
+
name: "example-driver",
|
|
164
|
+
vendor: "example",
|
|
165
|
+
revision: "1",
|
|
166
|
+
descriptor,
|
|
167
|
+
config: {
|
|
168
|
+
type: "object",
|
|
169
|
+
properties: { binary: { type: "string", minLength: 1 }, args: { type: "array", items: { type: "string" } } },
|
|
170
|
+
required: ["binary"],
|
|
171
|
+
},
|
|
172
|
+
// The kit keeps only `signedIn`. The raw status output is parsed here and dropped.
|
|
173
|
+
parseStatus: ({ exitCode }) => ({ signedIn: exitCode === 0 }),
|
|
174
|
+
start: {
|
|
175
|
+
probe: async (config) => ({ path: config.binary, version: "1.0.0" }),
|
|
176
|
+
run: (context) => runAdapter(context, parts, dialect),
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** One run: a run directory, a callback broker, and the vendor process, closed in `finally` however the run ends. */
|
|
182
|
+
async function runAdapter(context: DriverRunContext<ExampleConfig>, parts: Parts, dialect: ScriptedDialect): Promise<void> {
|
|
183
|
+
const { run, spec, lease } = context;
|
|
184
|
+
if (lease === undefined) throw new Error("the adapter needs a profile lease");
|
|
185
|
+
// The run directory holds the relay socket, so keep its name short (a Unix socket path must fit in 103 bytes).
|
|
186
|
+
const runDir = await createRunDirectory(lease.home, randomUUID().slice(0, 8));
|
|
187
|
+
try {
|
|
188
|
+
if (spec.skills !== undefined) {
|
|
189
|
+
// Skills are copied from the agent's registry into the run directory, never linked.
|
|
190
|
+
const skills = await materializeSkills(runDir, context.skills, spec.skills);
|
|
191
|
+
parts.evidence.materialized.push(...skills.pathToSkill.keys());
|
|
192
|
+
}
|
|
193
|
+
const broker = await createCallbackBroker(run, {
|
|
194
|
+
runDir: runDir.path,
|
|
195
|
+
hookCodec: gateCodec(effectOf),
|
|
196
|
+
// Answered whenever the broker cannot: the relay prints this and the vendor must not proceed.
|
|
197
|
+
failClosed: { exitCode: 2, stdout: '{"allow":false,"message":"prism relay is unavailable"}' },
|
|
198
|
+
timeoutMs: 5000,
|
|
199
|
+
});
|
|
200
|
+
try {
|
|
201
|
+
const bridge = bridgeTools(run, spec.prismTools ?? [], {
|
|
202
|
+
origin: { kind: "external", agent: spec.name, agentId: spec.name, vendor: "example", depth: 0 },
|
|
203
|
+
tools: context.tools,
|
|
204
|
+
});
|
|
205
|
+
broker.route("mcp", (request) => serveMcp(request, bridge, parts.evidence));
|
|
206
|
+
await converse(context, broker, runDir.path, dialect);
|
|
207
|
+
} finally {
|
|
208
|
+
await broker.close();
|
|
209
|
+
}
|
|
210
|
+
} finally {
|
|
211
|
+
await runDir.dispose();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The vendor's gate calls arrive as JSON on the relay's stdin. The codec turns each into a `pre-tool` request and
|
|
217
|
+
* encodes the answer back. An approval that is pending comes back as a deny whose message says so.
|
|
218
|
+
*/
|
|
219
|
+
function gateCodec(effectOf: (name: string) => readonly ("read" | "write" | "execute" | "network" | "external")[]): HookCodec {
|
|
220
|
+
return {
|
|
221
|
+
decode(stdin) {
|
|
222
|
+
const value = JSON.parse(stdin) as { kind?: string; id?: string; name?: string; args?: JsonValue };
|
|
223
|
+
// Anything the codec does not recognize throws, and the broker answers fail-closed.
|
|
224
|
+
if (value.kind !== "pre-tool" || value.id === undefined || value.name === undefined) throw new Error("unknown hook payload");
|
|
225
|
+
return {
|
|
226
|
+
kind: "pre-tool",
|
|
227
|
+
request: { toolCallId: value.id, name: value.name, args: value.args ?? {}, effects: effectOf(value.name) },
|
|
228
|
+
};
|
|
229
|
+
},
|
|
230
|
+
encode(answer) {
|
|
231
|
+
if ("allow" in answer) {
|
|
232
|
+
return answer.allow
|
|
233
|
+
? { exitCode: 0, stdout: '{"allow":true}' }
|
|
234
|
+
: { exitCode: 2, stdout: JSON.stringify({ allow: false, message: answer.message }) };
|
|
235
|
+
}
|
|
236
|
+
if ("respond" in answer) return { exitCode: 0, stdout: JSON.stringify({ respond: answer.respond }) };
|
|
237
|
+
return { exitCode: 0, stdout: "" };
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Starts the vendor process, sends the input, maps its frames, and waits for the turn to end or the run to stop. */
|
|
243
|
+
async function converse(
|
|
244
|
+
context: DriverRunContext<ExampleConfig>,
|
|
245
|
+
broker: CallbackBroker,
|
|
246
|
+
runDir: string,
|
|
247
|
+
dialect: ScriptedDialect,
|
|
248
|
+
): Promise<void> {
|
|
249
|
+
const { run, config, binary, descriptor: driverDescriptor } = context;
|
|
250
|
+
// The vendor runs this command for each gate call, with the call as JSON on stdin. It is the relay, not a vendor script.
|
|
251
|
+
const hookCommand = [...relayCommand(), "relay", "hook", "--run", runDir];
|
|
252
|
+
const child = spawn(binary.path, [...(config.args ?? []), "--hook-command", JSON.stringify(hookCommand)], {
|
|
253
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
254
|
+
env: buildChildEnv({ base: process.env, modes: driverDescriptor.auth.modes }),
|
|
255
|
+
}) as ChildProcessWithoutNullStreams;
|
|
256
|
+
child.stdin.on("error", () => undefined);
|
|
257
|
+
const write = (line: string) => child.stdin.write(`${line}\n`);
|
|
258
|
+
|
|
259
|
+
let turnDone!: () => void;
|
|
260
|
+
const turn = new Promise<"turn">((resolve) => (turnDone = () => resolve("turn")));
|
|
261
|
+
const exited = new Promise<"exit">((resolve) => child.once("close", () => resolve("exit")));
|
|
262
|
+
const aborted = new Promise<"abort">((resolve) => run.signal.addEventListener("abort", () => resolve("abort"), { once: true }));
|
|
263
|
+
|
|
264
|
+
const handle = async (line: string): Promise<void> => {
|
|
265
|
+
const output = dialect.parseFrame(line);
|
|
266
|
+
if (output === undefined) return;
|
|
267
|
+
if (output.kind === "hook") {
|
|
268
|
+
// A dialect with client-side gating (`json-rpc`) sends each gate call as a request. Ask, then answer on stdin.
|
|
269
|
+
const decision = await run.ask({
|
|
270
|
+
toolCallId: output.call.id,
|
|
271
|
+
name: output.call.tool,
|
|
272
|
+
args: output.call.args,
|
|
273
|
+
effects: effectOf(output.call.tool),
|
|
274
|
+
});
|
|
275
|
+
write(dialect.encodeInput({ kind: "answer", id: output.call.id, allow: "allow" in decision && decision.allow === true }));
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const frame = output.frame;
|
|
279
|
+
// `turn.done` is the only frame without a `kind`; every activity has one.
|
|
280
|
+
if (!("kind" in frame)) {
|
|
281
|
+
turnDone();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (frame.kind === "raw" && frame.type === "mcp.call") {
|
|
285
|
+
// A bridged-tool call. The vendor's MCP client would post it to the broker; the broker answers through the route.
|
|
286
|
+
await callBridged(broker, frame.data);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
await run.observe(frame);
|
|
290
|
+
};
|
|
291
|
+
// Frames are handled in order, one at a time, so a steer or an activity never overtakes the one before it.
|
|
292
|
+
let queue: Promise<void> = Promise.resolve();
|
|
293
|
+
createInterface({ input: child.stdout }).on("line", (line) => {
|
|
294
|
+
queue = queue.then(() => handle(line)).catch(() => undefined);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
void (async () => {
|
|
298
|
+
for await (const message of run.steers()) write(dialect.encodeInput({ kind: "steer", text: messageText(message) }));
|
|
299
|
+
})().catch(() => undefined);
|
|
300
|
+
run.signal.addEventListener("abort", () => void signalLadder(child, { graceMs: 200 }), { once: true });
|
|
301
|
+
|
|
302
|
+
write(dialect.encodeInput({ kind: "user", text: inputText(run.input) }));
|
|
303
|
+
const outcome = await Promise.race([turn, exited, aborted]);
|
|
304
|
+
if (outcome === "exit" && !run.signal.aborted) throw new Error("the vendor process exited before turn.done");
|
|
305
|
+
child.stdin.end();
|
|
306
|
+
await Promise.race([exited, sleep(2000)]);
|
|
307
|
+
if (child.exitCode === null && child.signalCode === null) await signalLadder(child, { graceMs: 200 });
|
|
308
|
+
await queue;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Posts one bridged call to the broker's MCP route, with the per-run bearer token. */
|
|
312
|
+
async function callBridged(broker: CallbackBroker, data: JsonValue): Promise<void> {
|
|
313
|
+
const response = await fetch(`${broker.url}/mcp`, {
|
|
314
|
+
method: "POST",
|
|
315
|
+
headers: { authorization: `Bearer ${broker.token}`, "content-type": "application/json" },
|
|
316
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: randomUUID(), method: "tools/call", params: data }),
|
|
317
|
+
});
|
|
318
|
+
await response.text();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** The MCP route: `tools/list` shows the bridged tools, `tools/call` runs one through `executeTools`, so `tool.call` fires. */
|
|
322
|
+
async function serveMcp(request: Request, bridge: ToolBridge, evidence: Evidence): Promise<Response> {
|
|
323
|
+
const message = (await request.json()) as { id: string; method: string; params: { name: string; arguments: JsonObject } };
|
|
324
|
+
if (message.method === "tools/list") return rpc(message.id, { tools: bridge.tools });
|
|
325
|
+
const outcome = await bridge.invoke({
|
|
326
|
+
type: "tool_call",
|
|
327
|
+
id: message.id,
|
|
328
|
+
name: message.params.name,
|
|
329
|
+
arguments: message.params.arguments,
|
|
330
|
+
});
|
|
331
|
+
evidence.bridged.push({ name: message.params.name, value: outcome.value });
|
|
332
|
+
return rpc(message.id, { value: outcome.value ?? null });
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const rpc = (id: string, result: unknown): Response =>
|
|
336
|
+
new Response(JSON.stringify({ jsonrpc: "2.0", id, result }), { headers: { "content-type": "application/json" } });
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* The scripted terminal runs the login command in the profile home, as a person would in a shell. The terminal's
|
|
340
|
+
* output never reaches the kit; the answer carries only the exit code.
|
|
341
|
+
*/
|
|
342
|
+
function runLogin(command: readonly string[], env: Readonly<Record<string, string>>): { exitCode: number } {
|
|
343
|
+
const [program = "", ...args] = command;
|
|
344
|
+
return { exitCode: spawnSync(program, args, { env, encoding: "utf8" }).status ?? 1 };
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** A host UI: confirms every gate prompt, and runs the login command for a terminal request. */
|
|
348
|
+
const scriptedUi = () =>
|
|
349
|
+
createScriptedHostUi((request) => {
|
|
350
|
+
if (request.kind === "terminal") return runLogin(request.command, request.env ?? {});
|
|
351
|
+
if (request.kind === "confirm") return true;
|
|
352
|
+
return { status: "unavailable" as const };
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
/** The main run: thinking and text, a skill, a sub-agent, two bridged calls, a gated write, a steer, and a fail-closed write. */
|
|
356
|
+
const MAIN_SCRIPT: ScriptStep[] = [
|
|
357
|
+
{ out: { kind: "message.delta", content: { type: "thinking", text: "Read the notes, then write them up." } } },
|
|
358
|
+
{ out: { kind: "message.delta", content: { type: "text", text: "Reading the notes." } } },
|
|
359
|
+
{ out: { kind: "skill", name: "review-notes", source: "tool", resolved: true } },
|
|
360
|
+
{ out: { kind: "subagent", phase: "started", id: "sub-1", name: "reviewer", parentToolCallId: "t-1" } },
|
|
361
|
+
{ out: { kind: "raw", vendor: "example", type: "mcp.call", data: { name: "lookup", arguments: { key: "readme" } } } },
|
|
362
|
+
{ out: { kind: "raw", vendor: "example", type: "mcp.call", data: { name: "note", arguments: { text: "reviewed" } } } },
|
|
363
|
+
{ hook: { tool: "write_file", id: "w-1", args: { path: "README.md" } } },
|
|
364
|
+
{ wait: 800 },
|
|
365
|
+
{ hook: { tool: "write_file", id: "w-2", args: { path: "CHANGELOG.md" }, breakBroker: true } },
|
|
366
|
+
{ out: { kind: "subagent", phase: "completed", id: "sub-1", result: "reviewed" } },
|
|
367
|
+
{ out: { kind: "message.delta", content: { type: "text", text: "Done." } } },
|
|
368
|
+
];
|
|
369
|
+
|
|
370
|
+
const RESUME_SCRIPT: ScriptStep[] = [{ hook: { tool: "write_file", id: "r-1", args: { path: "RESUME.md" } } }];
|
|
371
|
+
const FINAL_SCRIPT: ScriptStep[] = [{ out: { kind: "message.delta", content: { type: "text", text: "Written." } } }];
|
|
372
|
+
const BUSY_SCRIPT: ScriptStep[] = [{ wait: 800 }];
|
|
373
|
+
|
|
374
|
+
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
|
|
375
|
+
|
|
376
|
+
const eventName = (event: AgentEvent): string => (event.type === "package.event" ? event.name : event.type);
|
|
377
|
+
const messageText = (message: Message): string =>
|
|
378
|
+
message.content.map((block) => ("text" in block && typeof block.text === "string" ? block.text : "")).join("");
|
|
379
|
+
const inputText = (input: AgentInput): string =>
|
|
380
|
+
typeof input === "string" ? input : (Array.isArray(input) ? input : [input]).map(messageText).join("");
|
|
381
|
+
const codeOf = (result: { readonly error?: { readonly code?: string | number; readonly message: string } }): string | undefined =>
|
|
382
|
+
result.error === undefined ? undefined : String(result.error.code ?? result.error.message);
|
|
383
|
+
|
|
384
|
+
export async function demo(): Promise<Record<string, unknown>> {
|
|
385
|
+
const root = mkdtempSync(join(tmpdir(), "ex-"));
|
|
386
|
+
const parts = exampleParts();
|
|
387
|
+
const { evidence } = parts;
|
|
388
|
+
const driver = exampleDriver(parts);
|
|
389
|
+
const store = createMemorySessionStore();
|
|
390
|
+
const ui = scriptedUi();
|
|
391
|
+
const clis: ScriptedCli[] = [];
|
|
392
|
+
|
|
393
|
+
/** One agent over the scripted CLI. Each agent gets its own binary, so each scenario's record is its own. */
|
|
394
|
+
const agentFor = async (options: {
|
|
395
|
+
readonly script: readonly ScriptStep[];
|
|
396
|
+
readonly profile: string;
|
|
397
|
+
readonly principal?: string;
|
|
398
|
+
readonly deployment?: "local" | "hosted";
|
|
399
|
+
readonly withUi: boolean;
|
|
400
|
+
}): Promise<{ agent: Agent; cli: ScriptedCli }> => {
|
|
401
|
+
const cli = createScriptedCli({ dialect: jsonlStreamDialect, script: options.script });
|
|
402
|
+
clis.push(cli);
|
|
403
|
+
const agent = await createAgent({
|
|
404
|
+
id: "external-agent-demo",
|
|
405
|
+
packages: [driverPackage(driver)],
|
|
406
|
+
packageConfig: {
|
|
407
|
+
[driver.name]: {
|
|
408
|
+
binary: cli.command[0],
|
|
409
|
+
args: cli.command.slice(1),
|
|
410
|
+
name: "planner",
|
|
411
|
+
profile: options.profile,
|
|
412
|
+
profilesRoot: root,
|
|
413
|
+
principal: options.principal ?? "u1",
|
|
414
|
+
...(options.deployment === undefined ? {} : { deployment: options.deployment }),
|
|
415
|
+
systemPrompt: { replace: "You are the planner. Keep each edit small." },
|
|
416
|
+
prismTools: ["lookup", "note"],
|
|
417
|
+
skills: ["review-notes"],
|
|
418
|
+
requires: { steer: "mid-turn", resume: "store", thinking: "deltas", skillActivation: true, subagents: true },
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
...(options.withUi ? { host: { ui: ui.ui } } : {}),
|
|
422
|
+
slots: { store },
|
|
423
|
+
// Every write asks the host. Without a UI the ask suspends the run, which the resume scenario relies on.
|
|
424
|
+
hooks: (hooks) => hooks.on("tool.call", (call) => (call.name === "write_file" ? { ask: "Allow the write?" } : undefined)),
|
|
425
|
+
tools: { add: [...tools] },
|
|
426
|
+
skills: { add: [reviewNotes] },
|
|
427
|
+
});
|
|
428
|
+
return { agent, cli };
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
try {
|
|
432
|
+
// Sign in: the profile is created, then `ensure` runs the login through the scripted terminal.
|
|
433
|
+
// `binary` replaces `{binary}` in the login and status argv, as the driver package does with its probed path.
|
|
434
|
+
const profiles = createProfiles({ root, driver, host: { ui: ui.ui }, binary: process.execPath });
|
|
435
|
+
await profiles.create("me", { mode: "account", principal: "u1" });
|
|
436
|
+
await profiles.ensure("me");
|
|
437
|
+
const me = await profiles.read("me");
|
|
438
|
+
|
|
439
|
+
// 1. The main run: deltas, a skill, a sub-agent, bridged tools, a gated write, a steer, and a fail-closed write.
|
|
440
|
+
const main = await agentFor({ script: MAIN_SCRIPT, profile: "me", withUi: true });
|
|
441
|
+
const session = await main.agent.session();
|
|
442
|
+
const subscription = session.subscribe({ acrossRuns: true });
|
|
443
|
+
const events: AgentEvent[] = [];
|
|
444
|
+
const pump = (async () => {
|
|
445
|
+
for await (const event of subscription) events.push(event);
|
|
446
|
+
})();
|
|
447
|
+
const running = session.run("Update the README and the changelog.");
|
|
448
|
+
await sleep(300);
|
|
449
|
+
session.steer("change course");
|
|
450
|
+
const result = await running;
|
|
451
|
+
await session.close();
|
|
452
|
+
await pump.catch(() => undefined);
|
|
453
|
+
|
|
454
|
+
const names = new Set(events.map(eventName));
|
|
455
|
+
const hookResult = (id: string) =>
|
|
456
|
+
main.cli.record().flatMap((entry) => (entry.event === "hook-result" && entry.id === id ? [entry] : []))[0];
|
|
457
|
+
|
|
458
|
+
// 2. Suspension and resume: with no UI the gated write suspends. A new agent over the same store, as a new process
|
|
459
|
+
// would be, reopens the session and resumes it with `allow_once`. The resumed process has nothing left to gate.
|
|
460
|
+
const gated = await agentFor({ script: RESUME_SCRIPT, profile: "me", withUi: false });
|
|
461
|
+
const suspendedSession = await gated.agent.session();
|
|
462
|
+
const first = await suspendedSession.run("Write the resume file.");
|
|
463
|
+
const decisions = (first.pending ?? []).map((entry) => ({ approvalId: entry.approvalId, outcome: "allow_once" as const }));
|
|
464
|
+
const finisher = await agentFor({ script: FINAL_SCRIPT, profile: "me", withUi: false });
|
|
465
|
+
const reopened = await finisher.agent.session({ id: suspendedSession.id });
|
|
466
|
+
const resumed: string[] = [];
|
|
467
|
+
for await (const event of reopened.resume(decisions)) resumed.push(event.type);
|
|
468
|
+
|
|
469
|
+
// 3. Search: the sessions this demo wrote, through the same store.
|
|
470
|
+
const page = await createSessionIndex(store).search({ query: "README" });
|
|
471
|
+
|
|
472
|
+
// 4. Policy: each refusal happens before the vendor process starts, so these scripts never run.
|
|
473
|
+
const hosted = await agentFor({ script: [], profile: "me", deployment: "hosted", withUi: true });
|
|
474
|
+
const hostedRun = await (await hosted.agent.session()).run("Hello");
|
|
475
|
+
const other = await agentFor({ script: [], profile: "me", principal: "u2", withUi: true });
|
|
476
|
+
const mismatch = await (await other.agent.session()).run("Hello");
|
|
477
|
+
await profiles.create("busy", { mode: "account", principal: "u1", maxConcurrentRuns: 1 });
|
|
478
|
+
await profiles.ensure("busy");
|
|
479
|
+
const busy = await agentFor({ script: BUSY_SCRIPT, profile: "busy", withUi: true });
|
|
480
|
+
const [firstBusy, secondBusy] = await Promise.all([
|
|
481
|
+
busy.agent.session().then((s) => s.run("first")),
|
|
482
|
+
busy.agent.session().then((s) => s.run("second")),
|
|
483
|
+
]);
|
|
484
|
+
const busyResults = [firstBusy, secondBusy];
|
|
485
|
+
|
|
486
|
+
return {
|
|
487
|
+
signIn: { signedIn: me?.auth?.signedIn === true, terminalRuns: ui.requestsOf("terminal").length },
|
|
488
|
+
main: {
|
|
489
|
+
status: result.status,
|
|
490
|
+
thinkingDeltas: events.some((event) => event.type === "message.delta" && event.content.type === "thinking"),
|
|
491
|
+
textDeltas: events.some((event) => event.type === "message.delta" && event.content.type === "text"),
|
|
492
|
+
skillActivation: names.has("agent.skill"),
|
|
493
|
+
subagent: names.has("agent.subagent"),
|
|
494
|
+
materializedSkills: [...new Set(evidence.materialized)],
|
|
495
|
+
bridgedTools: evidence.bridged.map((call) => call.name),
|
|
496
|
+
steered: main.cli.record().some((entry) => entry.event === "input" && entry.input.kind === "steer"),
|
|
497
|
+
confirmRequests: ui.requestsOf("confirm").length,
|
|
498
|
+
allowedWriteExit: hookResult("w-1")?.exitCode,
|
|
499
|
+
failClosedExit: hookResult("w-2")?.exitCode,
|
|
500
|
+
},
|
|
501
|
+
resume: {
|
|
502
|
+
suspended: first.status === "suspended",
|
|
503
|
+
completed: resumed.at(-1) === "run.completed",
|
|
504
|
+
gateEntries: gated.cli.record().filter((entry) => entry.event === "hook").length,
|
|
505
|
+
},
|
|
506
|
+
search: { hits: page.items.length, found: page.items.some((hit) => hit.sessionId === session.id) },
|
|
507
|
+
policy: {
|
|
508
|
+
hosted: codeOf(hostedRun),
|
|
509
|
+
principal: codeOf(mismatch),
|
|
510
|
+
busy: {
|
|
511
|
+
completed: busyResults.filter((run) => run.status === "completed").length,
|
|
512
|
+
refused: busyResults.map(codeOf).filter(Boolean),
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
};
|
|
516
|
+
} finally {
|
|
517
|
+
for (const cli of clis) cli.dispose();
|
|
518
|
+
rmSync(root, { recursive: true, force: true });
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* `--conformance` runs `driverConformance` on this example's driver, once per reference dialect, and prints each
|
|
524
|
+
* leg. The Phase 13 Done record cites this output; a test spawns it.
|
|
525
|
+
*/
|
|
526
|
+
async function conformance(): Promise<Record<string, unknown>> {
|
|
527
|
+
const out: Record<string, unknown> = {};
|
|
528
|
+
for (const dialect of [jsonlStreamDialect, jsonRpcDialect]) {
|
|
529
|
+
// The key mode declares a protected path, so the canary leg runs; it reads no account and needs no sign-in.
|
|
530
|
+
const result = await driverConformance(exampleDriver(exampleParts(), dialect), {
|
|
531
|
+
dialect,
|
|
532
|
+
fixtures: { mode: "key", config: (cli) => ({ binary: cli.command[0] ?? "", args: cli.command.slice(1) }) },
|
|
533
|
+
});
|
|
534
|
+
out[dialect.name] = result.legs;
|
|
535
|
+
}
|
|
536
|
+
return out;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
540
|
+
console.log(JSON.stringify(process.argv.includes("--conformance") ? await conformance() : await demo()));
|
|
541
|
+
}
|