@zvada/agent-server 0.3.22 → 0.3.23
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 +261 -0
- package/dist/types/accounts/chatgpt.d.ts +1 -1
- package/dist/types/accounts/chatgpt.d.ts.map +1 -1
- package/dist/types/accounts/http.d.ts +2 -4
- package/dist/types/accounts/http.d.ts.map +1 -1
- package/dist/types/client/client.d.ts +37 -11
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/connection.d.ts +64 -13
- package/dist/types/client/connection.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/logins.d.ts +2 -1
- package/dist/types/client/logins.d.ts.map +1 -1
- package/dist/types/client/streams.d.ts +9 -3
- package/dist/types/client/streams.d.ts.map +1 -1
- package/dist/types/client/turns.d.ts +1 -1
- package/dist/types/client/turns.d.ts.map +1 -1
- package/dist/types/core/agents/acp/acp-agent.d.ts +34 -1
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/acp/client.d.ts +12 -3
- package/dist/types/core/agents/acp/client.d.ts.map +1 -1
- package/dist/types/core/agents/acp/mappings.d.ts +8 -2
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
- package/dist/types/core/agents/base.d.ts +22 -8
- package/dist/types/core/agents/base.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/adapter.d.ts +7 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts +4 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +16 -5
- package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/events.d.ts +9 -1
- package/dist/types/core/agents/claude-code/events.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/login.d.ts +4 -1
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/mcp.d.ts +21 -7
- package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/models.d.ts +5 -1
- package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/options.d.ts +10 -4
- package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/outcome.d.ts +3 -5
- package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/results.d.ts +16 -0
- package/dist/types/core/agents/claude-code/results.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/sdk-pair.d.ts +13 -0
- package/dist/types/core/agents/claude-code/sdk-pair.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session.d.ts +50 -12
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/spend.d.ts +2 -1
- package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/tools.d.ts +26 -3
- package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/adapter.d.ts +2 -2
- package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/client.d.ts +12 -2
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +58 -13
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/commands.d.ts +2 -2
- package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/credentials.d.ts +5 -1
- package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/effort.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/homes.d.ts +19 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/items.d.ts +27 -2
- package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts +4 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/mcp.d.ts +15 -30
- package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/models.d.ts +3 -10
- package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/options.d.ts +27 -4
- package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/protocol.d.ts +16 -3
- package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/session.d.ts +68 -40
- package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/subagents.d.ts +9 -4
- package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +3 -2
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/turn.d.ts +31 -8
- package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/user-login.d.ts +28 -0
- package/dist/types/core/agents/codex-app-server/user-login.d.ts.map +1 -0
- package/dist/types/core/agents/credentials.d.ts +3 -1
- package/dist/types/core/agents/credentials.d.ts.map +1 -1
- package/dist/types/core/agents/diffs.d.ts +9 -0
- package/dist/types/core/agents/diffs.d.ts.map +1 -0
- package/dist/types/core/agents/elicitation.d.ts +3 -2
- package/dist/types/core/agents/elicitation.d.ts.map +1 -1
- package/dist/types/core/agents/login.d.ts +6 -0
- package/dist/types/core/agents/login.d.ts.map +1 -1
- package/dist/types/core/agents/mcp-config.d.ts +0 -4
- package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
- package/dist/types/core/agents/process-pool.d.ts +193 -0
- package/dist/types/core/agents/process-pool.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/adapter.d.ts +68 -0
- package/dist/types/core/agents/scripted/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/mcp-call.d.ts +56 -0
- package/dist/types/core/agents/scripted/mcp-call.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/scripted-agent.d.ts +73 -0
- package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/scripts.d.ts +29 -0
- package/dist/types/core/agents/scripted/scripts.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/steps.d.ts +132 -0
- package/dist/types/core/agents/scripted/steps.d.ts.map +1 -0
- package/dist/types/core/agents/session-agent.d.ts +49 -6
- package/dist/types/core/agents/session-agent.d.ts.map +1 -1
- package/dist/types/core/diagnostics.d.ts +4 -1
- package/dist/types/core/diagnostics.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +5 -0
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/presets.d.ts +32 -6
- package/dist/types/core/presets.d.ts.map +1 -1
- package/dist/types/core/processes/lifeline.d.ts +0 -20
- package/dist/types/core/processes/lifeline.d.ts.map +1 -1
- package/dist/types/core/provision/index.d.ts +2 -2
- package/dist/types/core/provision/index.d.ts.map +1 -1
- package/dist/types/core/provision/install-build.d.ts +2 -1
- package/dist/types/core/provision/install-build.d.ts.map +1 -1
- package/dist/types/core/provision/npm.d.ts +20 -8
- package/dist/types/core/provision/npm.d.ts.map +1 -1
- package/dist/types/core/provision/provisioner.d.ts +4 -1
- package/dist/types/core/provision/provisioner.d.ts.map +1 -1
- package/dist/types/core/provision/tools.d.ts +2 -1
- package/dist/types/core/provision/tools.d.ts.map +1 -1
- package/dist/types/core/runtime/agent-runtime.d.ts +16 -8
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/types/core/runtime/event-processor.d.ts +5 -1
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
- package/dist/types/core/runtime/harness-clis.d.ts +9 -0
- package/dist/types/core/runtime/harness-clis.d.ts.map +1 -1
- package/dist/types/core/runtime/harness-logins.d.ts +33 -5
- package/dist/types/core/runtime/harness-logins.d.ts.map +1 -1
- package/dist/types/core/runtime/model-lists.d.ts +2 -0
- package/dist/types/core/runtime/model-lists.d.ts.map +1 -1
- package/dist/types/core/runtime/permission-policy.d.ts +5 -3
- package/dist/types/core/runtime/permission-policy.d.ts.map +1 -1
- package/dist/types/core/runtime/request-broker.d.ts +2 -1
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
- package/dist/types/core/runtime/turn.d.ts +12 -1
- package/dist/types/core/runtime/turn.d.ts.map +1 -1
- package/dist/types/core/utils/deadline.d.ts +6 -0
- package/dist/types/core/utils/deadline.d.ts.map +1 -1
- package/dist/types/core/utils/errors.d.ts +7 -1
- package/dist/types/core/utils/errors.d.ts.map +1 -1
- package/dist/types/operator/operator.d.ts.map +1 -1
- package/dist/types/operator/render.d.ts +6 -4
- package/dist/types/operator/render.d.ts.map +1 -1
- package/dist/types/protocol/auth.d.ts +54 -24
- package/dist/types/protocol/auth.d.ts.map +1 -1
- package/dist/types/protocol/clis.d.ts +14 -7
- package/dist/types/protocol/clis.d.ts.map +1 -1
- package/dist/types/protocol/config.d.ts +2 -0
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +40 -3
- package/dist/types/protocol/conversation.d.ts.map +1 -1
- package/dist/types/protocol/credentials.d.ts +7 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -1
- package/dist/types/protocol/execution.d.ts +2 -1
- package/dist/types/protocol/execution.d.ts.map +1 -1
- package/dist/types/protocol/factories.d.ts +12 -2
- package/dist/types/protocol/factories.d.ts.map +1 -1
- package/dist/types/protocol/harness.d.ts +6 -2
- package/dist/types/protocol/harness.d.ts.map +1 -1
- package/dist/types/protocol/history.d.ts +19 -0
- package/dist/types/protocol/history.d.ts.map +1 -1
- package/dist/types/protocol/lifecycle.d.ts +47 -8
- package/dist/types/protocol/lifecycle.d.ts.map +1 -1
- package/dist/types/protocol/model-catalog.d.ts.map +1 -1
- package/dist/types/protocol/models.d.ts +3 -0
- package/dist/types/protocol/models.d.ts.map +1 -1
- package/dist/types/protocol/parts.d.ts +14 -0
- package/dist/types/protocol/parts.d.ts.map +1 -1
- package/dist/types/protocol/tool-state.d.ts +12 -0
- package/dist/types/protocol/tool-state.d.ts.map +1 -1
- package/dist/types/protocol/wire-api.d.ts +129 -23
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +70 -10
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/dist/types/server/acp/binding.d.ts +6 -1
- package/dist/types/server/acp/binding.d.ts.map +1 -1
- package/dist/types/server/acp/translate.d.ts +33 -7
- package/dist/types/server/acp/translate.d.ts.map +1 -1
- package/dist/types/server/agent-server.d.ts +6 -0
- package/dist/types/server/agent-server.d.ts.map +1 -1
- package/dist/types/server/feedback.d.ts +2 -1
- package/dist/types/server/feedback.d.ts.map +1 -1
- package/dist/types/server/install.d.ts +11 -0
- package/dist/types/server/install.d.ts.map +1 -1
- package/dist/types/server/session-gate.d.ts +2 -1
- package/dist/types/server/session-gate.d.ts.map +1 -1
- package/dist/types/server/session-store.d.ts +1 -0
- package/dist/types/server/session-store.d.ts.map +1 -1
- package/dist/types/server/subscriptions.d.ts +2 -1
- package/dist/types/server/subscriptions.d.ts.map +1 -1
- package/dist/types/server/transports.d.ts.map +1 -1
- package/dist/types/sync/fit.d.ts +8 -7
- package/dist/types/sync/fit.d.ts.map +1 -1
- package/dist/types/sync/history-sqlite.d.ts.map +1 -1
- package/dist/types/sync/index.d.ts +1 -0
- package/dist/types/sync/index.d.ts.map +1 -1
- package/dist/types/sync/journal-sqlite.d.ts +2 -1
- package/dist/types/sync/journal-sqlite.d.ts.map +1 -1
- package/dist/types/sync/journal.d.ts +11 -3
- package/dist/types/sync/journal.d.ts.map +1 -1
- package/dist/types/sync/projection.d.ts +6 -0
- package/dist/types/sync/projection.d.ts.map +1 -1
- package/dist/types/sync/recovery.d.ts +2 -1
- package/dist/types/sync/recovery.d.ts.map +1 -1
- package/dist/types/sync/schema.d.ts +10 -0
- package/dist/types/sync/schema.d.ts.map +1 -1
- package/dist/types/sync/sql.d.ts +2 -1
- package/dist/types/sync/sql.d.ts.map +1 -1
- package/docs/consuming.md +278 -28
- package/docs/deploy.md +36 -8
- package/docs/durable-sessions.md +35 -5
- package/docs/harnesses.md +385 -24
- package/package.json +6 -1
- package/src/accounts/chatgpt.ts +2 -2
- package/src/accounts/http.ts +2 -16
- package/src/client/client.ts +92 -31
- package/src/client/connection.ts +103 -22
- package/src/client/index.ts +1 -0
- package/src/client/logins.ts +1 -1
- package/src/client/streams.ts +12 -4
- package/src/client/turns.ts +1 -1
- package/src/core/agents/acp/acp-agent.ts +181 -52
- package/src/core/agents/acp/adapter.ts +9 -1
- package/src/core/agents/acp/client.ts +16 -4
- package/src/core/agents/acp/mappings.ts +27 -0
- package/src/core/agents/base.ts +25 -10
- package/src/core/agents/claude-code/adapter.ts +47 -17
- package/src/core/agents/claude-code/approvals.ts +6 -5
- package/src/core/agents/claude-code/claude-agent.ts +60 -30
- package/src/core/agents/claude-code/events.ts +11 -1
- package/src/core/agents/claude-code/login.ts +14 -2
- package/src/core/agents/claude-code/mcp.ts +31 -15
- package/src/core/agents/claude-code/models.ts +7 -2
- package/src/core/agents/claude-code/options.ts +11 -3
- package/src/core/agents/claude-code/outcome.ts +10 -2
- package/src/core/agents/claude-code/results.ts +73 -0
- package/src/core/agents/claude-code/sdk-pair.ts +66 -0
- package/src/core/agents/claude-code/session.ts +166 -37
- package/src/core/agents/claude-code/spend.ts +1 -1
- package/src/core/agents/claude-code/tools.ts +108 -12
- package/src/core/agents/codex-app-server/adapter.ts +37 -12
- package/src/core/agents/codex-app-server/client.ts +37 -8
- package/src/core/agents/codex-app-server/codex-agent.ts +115 -50
- package/src/core/agents/codex-app-server/commands.ts +2 -2
- package/src/core/agents/codex-app-server/credentials.ts +10 -5
- package/src/core/agents/codex-app-server/effort.ts +1 -1
- package/src/core/agents/codex-app-server/homes.ts +43 -1
- package/src/core/agents/codex-app-server/items.ts +219 -31
- package/src/core/agents/codex-app-server/login.ts +14 -2
- package/src/core/agents/codex-app-server/mcp.ts +47 -32
- package/src/core/agents/codex-app-server/models.ts +9 -8
- package/src/core/agents/codex-app-server/options.ts +69 -10
- package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
- package/src/core/agents/codex-app-server/protocol.ts +14 -4
- package/src/core/agents/codex-app-server/requests.ts +14 -6
- package/src/core/agents/codex-app-server/session.ts +151 -113
- package/src/core/agents/codex-app-server/subagents.ts +21 -14
- package/src/core/agents/codex-app-server/thread-settings.ts +18 -8
- package/src/core/agents/codex-app-server/turn-items.ts +1 -1
- package/src/core/agents/codex-app-server/turn.ts +79 -32
- package/src/core/agents/codex-app-server/user-login.ts +107 -0
- package/src/core/agents/credentials.ts +5 -2
- package/src/core/agents/diffs.ts +25 -0
- package/src/core/agents/elicitation.ts +2 -2
- package/src/core/agents/login.ts +6 -0
- package/src/core/agents/mcp-config.ts +2 -2
- package/src/core/agents/process-pool.ts +432 -0
- package/src/core/agents/scripted/adapter.ts +142 -0
- package/src/core/agents/scripted/mcp-call.ts +134 -0
- package/src/core/agents/scripted/scripted-agent.ts +418 -0
- package/src/core/agents/scripted/scripts.ts +171 -0
- package/src/core/agents/scripted/steps.ts +127 -0
- package/src/core/agents/session-agent.ts +105 -8
- package/src/core/diagnostics.ts +9 -1
- package/src/core/index.ts +11 -0
- package/src/core/presets.ts +99 -14
- package/src/core/processes/lifeline.ts +99 -25
- package/src/core/provision/index.ts +1 -2
- package/src/core/provision/install-build.ts +4 -1
- package/src/core/provision/npm.ts +309 -97
- package/src/core/provision/provisioner.ts +22 -8
- package/src/core/provision/tools.ts +44 -19
- package/src/core/runtime/agent-runtime.ts +48 -18
- package/src/core/runtime/event-processor.ts +18 -2
- package/src/core/runtime/harness-clis.ts +36 -1
- package/src/core/runtime/harness-logins.ts +82 -31
- package/src/core/runtime/model-lists.ts +1 -1
- package/src/core/runtime/permission-policy.ts +4 -3
- package/src/core/runtime/request-broker.ts +1 -1
- package/src/core/runtime/turn.ts +51 -3
- package/src/core/utils/deadline.ts +23 -0
- package/src/core/utils/errors.ts +11 -4
- package/src/operator/operator.ts +8 -4
- package/src/operator/render.ts +46 -8
- package/src/protocol/auth.ts +30 -23
- package/src/protocol/clis.ts +12 -4
- package/src/protocol/credentials.ts +19 -0
- package/src/protocol/execution.ts +5 -0
- package/src/protocol/factories.ts +25 -3
- package/src/protocol/harness.ts +11 -1
- package/src/protocol/history.ts +20 -0
- package/src/protocol/lifecycle.ts +10 -1
- package/src/protocol/model-catalog.ts +19 -8
- package/src/protocol/parts.ts +12 -1
- package/src/protocol/tool-state.ts +14 -1
- package/src/protocol/wire.ts +14 -0
- package/src/server/acp/binding.ts +113 -23
- package/src/server/acp/translate.ts +161 -8
- package/src/server/agent-server.ts +10 -1
- package/src/server/bin.ts +83 -9
- package/src/server/feedback.ts +1 -1
- package/src/server/install.ts +82 -4
- package/src/server/session-gate.ts +1 -1
- package/src/server/session-store.ts +5 -1
- package/src/server/subscriptions.ts +1 -1
- package/src/server/transports.ts +14 -0
- package/src/sync/fit.ts +115 -28
- package/src/sync/history-sqlite.ts +6 -2
- package/src/sync/index.ts +1 -0
- package/src/sync/journal-sqlite.ts +20 -2
- package/src/sync/journal.ts +10 -2
- package/src/sync/projection.ts +10 -0
- package/src/sync/recovery.ts +11 -4
- package/src/sync/schema.ts +7 -5
- package/src/sync/sql.ts +1 -1
- package/dist/types/core/agents/claude-code/session-pool.d.ts +0 -36
- package/dist/types/core/agents/claude-code/session-pool.d.ts.map +0 -1
- package/dist/types/core/agents/session-pool.d.ts +0 -41
- package/dist/types/core/agents/session-pool.d.ts.map +0 -1
- package/src/core/agents/claude-code/session-pool.ts +0 -136
- package/src/core/agents/session-pool.ts +0 -111
package/src/core/runtime/turn.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AgentHarness,
|
|
3
|
+
AgentInput,
|
|
3
4
|
ErrorInfo,
|
|
4
5
|
LifecycleEvent,
|
|
6
|
+
RunConfig,
|
|
5
7
|
RunRequest,
|
|
6
8
|
StopReason,
|
|
7
9
|
ThinkingLevel,
|
|
@@ -79,6 +81,46 @@ export interface TurnHost {
|
|
|
79
81
|
|
|
80
82
|
const CANCEL = { decision: "cancel" } as const;
|
|
81
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Whether a turn sets a field: a value, but a boolean only when `true`, a
|
|
86
|
+
* string only when it is not empty, and an array or a record only when it
|
|
87
|
+
* holds something; the others mean the same as unset.
|
|
88
|
+
*/
|
|
89
|
+
function setsField(config: RunConfig, field: string): boolean {
|
|
90
|
+
const value = (config as Record<string, unknown>)[field];
|
|
91
|
+
if (value === undefined || value === false || value === "") return false;
|
|
92
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
93
|
+
if (typeof value === "object" && value !== null) return Object.keys(value).length > 0;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The settings a turn set that its harness never applies. */
|
|
98
|
+
export function ignoredSettingsOf(config: RunConfig, ignored: readonly string[] = []): string[] {
|
|
99
|
+
return ignored.filter((field) => setsField(config, field));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// @ref LLP 0013#f12-a-lone-surrogate-hung-codex — no agent is given text it cannot read
|
|
103
|
+
/**
|
|
104
|
+
* Input as an agent is given it: every string of it well-formed, a lone
|
|
105
|
+
* UTF-16 surrogate (a string cut in the middle of an emoji) made U+FFFD.
|
|
106
|
+
* Codex cannot read a line that carries one and never answers it. The user
|
|
107
|
+
* echo is made of the caller's own input, not this (LLP 0002, The user echo
|
|
108
|
+
* comes first). A text element's byte range still holds: UTF-8 writes a lone
|
|
109
|
+
* surrogate as U+FFFD, three bytes.
|
|
110
|
+
*/
|
|
111
|
+
export function wellFormedInput(input: AgentInput): AgentInput {
|
|
112
|
+
if (typeof input === "string") return input.toWellFormed();
|
|
113
|
+
return input.map(
|
|
114
|
+
(part) =>
|
|
115
|
+
Object.fromEntries(
|
|
116
|
+
Object.entries(part).map(([key, value]) => [
|
|
117
|
+
key,
|
|
118
|
+
typeof value === "string" ? value.toWellFormed() : value,
|
|
119
|
+
]),
|
|
120
|
+
) as typeof part,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
82
124
|
/**
|
|
83
125
|
* One admitted turn, from admission until it settles. It executes the request
|
|
84
126
|
* on its harness, streams what the harness does through the processor to its
|
|
@@ -168,22 +210,28 @@ export class Turn {
|
|
|
168
210
|
config.model,
|
|
169
211
|
);
|
|
170
212
|
|
|
213
|
+
// @ref LLP 0001#d22--a-turn-says-what-it-did-not-apply — up front, then as the harness finds out
|
|
214
|
+
const notApplied = ignoredSettingsOf(config, agent.capabilities.ignoredSettings);
|
|
215
|
+
this.processor.markNotApplied(notApplied);
|
|
171
216
|
await this.emit({
|
|
172
217
|
type: "turn.started",
|
|
173
218
|
turnId,
|
|
174
219
|
sessionId,
|
|
175
|
-
execution: this.execution,
|
|
220
|
+
execution: { ...this.execution, ...(notApplied.length && { notApplied }) },
|
|
176
221
|
timestamp: Date.now(),
|
|
177
222
|
});
|
|
178
223
|
// @ref LLP 0002#the-user-echo-comes-first — before any harness output
|
|
179
224
|
// The user echo: the submitted input goes back onto the stream as a
|
|
180
225
|
// complete user message (outputIndex 0) before any harness output, so
|
|
181
|
-
// the stream is a complete transcript and multi-client attach works.
|
|
226
|
+
// the stream is a complete transcript and multi-client attach works. It is
|
|
227
|
+
// the caller's input as sent, which the caller can predict; the agent is
|
|
228
|
+
// given it well-formed (`wellFormedInput`).
|
|
182
229
|
for (const event of this.processor.echoUserMessage(input)) await this.emit(event);
|
|
183
230
|
|
|
184
231
|
let threw: TurnThrew | undefined;
|
|
185
232
|
try {
|
|
186
|
-
|
|
233
|
+
const given = wellFormedInput(input);
|
|
234
|
+
for await (const raw of agent.execute(given, this.agentOptions(modelThinking))) {
|
|
187
235
|
await this.announceNativeSession();
|
|
188
236
|
if (config.includeRaw) {
|
|
189
237
|
await this.emit({
|
|
@@ -21,6 +21,29 @@ export async function withTimeout<T>(
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Wait for `promise` until `signal` aborts: its value, or the signal's reason
|
|
26
|
+
* thrown once the signal aborts first. Only the wait ends: the work goes on
|
|
27
|
+
* for whoever else waits for it. Without a signal it waits for the work.
|
|
28
|
+
*/
|
|
29
|
+
export async function untilAborted<T>(
|
|
30
|
+
promise: Promise<T>,
|
|
31
|
+
signal: AbortSignal | undefined,
|
|
32
|
+
): Promise<T> {
|
|
33
|
+
if (!signal) return await promise;
|
|
34
|
+
let off = () => {};
|
|
35
|
+
try {
|
|
36
|
+
return await Promise.race([
|
|
37
|
+
promise,
|
|
38
|
+
new Promise<never>((_, reject) => {
|
|
39
|
+
off = onAbort(signal, () => reject(signal.reason));
|
|
40
|
+
}),
|
|
41
|
+
]);
|
|
42
|
+
} finally {
|
|
43
|
+
off();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
24
47
|
/**
|
|
25
48
|
* Run `fn` once `signal` aborts, or at once if it already has. Returns what
|
|
26
49
|
* removes it again. Without a signal it never runs.
|
package/src/core/utils/errors.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { type ErrorCategory, classifyError } from "../../protocol/index.ts";
|
|
|
4
4
|
* Appended to setup/integration errors only — the moments a coding agent
|
|
5
5
|
* integrating this package is most likely holding actionable friction. Runtime
|
|
6
6
|
* failures stay clean: they are usually the harness's or the caller's problem,
|
|
7
|
-
* and hinting there would train agents to file noise.
|
|
7
|
+
* and hinting there would train agents to file noise. Installing a CLI is one
|
|
8
|
+
* since the engine installs during a turn and at `clis/prepare` (LLP 0010):
|
|
9
|
+
* its failure reaches a product's users, on the stream and in `clis/*`.
|
|
8
10
|
*/
|
|
9
11
|
function feedbackHint(category: string, subject: string): string {
|
|
10
12
|
return `\nAI agent? Report this agent-server friction: npx --yes hivenet@latest --to agent-server --category ${category} --subject "${subject}" --message "<what you tried and what you expected>"`;
|
|
@@ -191,10 +193,15 @@ export class CliNotFoundError extends AgentServerError {
|
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
/**
|
|
196
|
+
/**
|
|
197
|
+
* Managed CLI provisioning failed (download, integrity, or a bad override).
|
|
198
|
+
* `category` says what failed where the install knows (`network` for a
|
|
199
|
+
* registry that cannot be reached or answers 5xx, and for a cut transfer);
|
|
200
|
+
* otherwise its message is classified. `clis/*` and the turn carry it alike.
|
|
201
|
+
*/
|
|
195
202
|
export class CliProvisionError extends AgentServerError {
|
|
196
|
-
constructor(message: string, options?: { cause?: unknown }) {
|
|
197
|
-
super(
|
|
203
|
+
constructor(message: string, options?: { cause?: unknown; category?: ErrorCategory }) {
|
|
204
|
+
super(message, "cliProvisionFailed", options?.category);
|
|
198
205
|
this.name = "CliProvisionError";
|
|
199
206
|
if (options?.cause !== undefined) this.cause = options.cause;
|
|
200
207
|
}
|
package/src/operator/operator.ts
CHANGED
|
@@ -431,7 +431,7 @@ export function createOperator<Caller = unknown>(
|
|
|
431
431
|
const phase = phaseOf(view);
|
|
432
432
|
if (phase === "working") return renderOutcome(view, ref, waited);
|
|
433
433
|
const note = await host.outcome?.(caller, { ...entry, phase });
|
|
434
|
-
return renderOutcome(view, ref, undefined, note);
|
|
434
|
+
return renderOutcome(view, ref, undefined, note, entry.root);
|
|
435
435
|
}
|
|
436
436
|
|
|
437
437
|
const listSessions = tool<Record<string, never>, Caller>({
|
|
@@ -475,7 +475,9 @@ export function createOperator<Caller = unknown>(
|
|
|
475
475
|
if (entry.phase !== "needs_input") continue;
|
|
476
476
|
const view = await host.view(caller, entry.id, { last: 1 });
|
|
477
477
|
for (const waiting of view.waiting) {
|
|
478
|
-
lines.push(
|
|
478
|
+
lines.push(
|
|
479
|
+
describeWaiting(waiting, refIn(all, entry), entry.root).replace(/^/gm, " "),
|
|
480
|
+
);
|
|
479
481
|
}
|
|
480
482
|
}
|
|
481
483
|
}
|
|
@@ -564,7 +566,9 @@ export function createOperator<Caller = unknown>(
|
|
|
564
566
|
const before = await host.view(caller, entry.id, { last: REPLY_MESSAGES });
|
|
565
567
|
// A session waiting on the person wants an answer, not a new turn: say which call gives it.
|
|
566
568
|
if (before.waiting.length && !interrupt) {
|
|
567
|
-
const waits = before.waiting
|
|
569
|
+
const waits = before.waiting
|
|
570
|
+
.map((waiting) => describeWaiting(waiting, ref, entry.root))
|
|
571
|
+
.join("\n");
|
|
568
572
|
throw new OperatorError(
|
|
569
573
|
`${quoted(ref)} is waiting on an answer, so nothing was sent.\n${waits}\n (interrupt: true would drop the question and start on this message instead)`,
|
|
570
574
|
);
|
|
@@ -658,7 +662,7 @@ export function createOperator<Caller = unknown>(
|
|
|
658
662
|
if (entry.phase === "needs_input") {
|
|
659
663
|
const view = await host.view(caller, entry.id, { last: 1 });
|
|
660
664
|
for (const waiting of view.waiting) {
|
|
661
|
-
lines.push(describeWaiting(waiting, ref).replace(/^/gm, " "));
|
|
665
|
+
lines.push(describeWaiting(waiting, ref, entry.root).replace(/^/gm, " "));
|
|
662
666
|
}
|
|
663
667
|
} else lines.push(` ${callHint("read_session", { session: ref })}`);
|
|
664
668
|
}
|
package/src/operator/render.ts
CHANGED
|
@@ -9,7 +9,14 @@
|
|
|
9
9
|
import type { ElicitationOutcome, PermissionOutcome } from "../protocol/lifecycle.ts";
|
|
10
10
|
import type { Part, UnknownPart } from "../protocol/parts.ts";
|
|
11
11
|
import { PLAN_OPTION_IDS } from "../protocol/plan.ts";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
type DecisionRequest,
|
|
14
|
+
type SessionView,
|
|
15
|
+
type ViewMessage,
|
|
16
|
+
type Waiting,
|
|
17
|
+
isPlan,
|
|
18
|
+
phaseOf,
|
|
19
|
+
} from "./view.ts";
|
|
13
20
|
|
|
14
21
|
const clip = (text: string, limit: number) =>
|
|
15
22
|
text.length > limit ? `${text.slice(0, limit - 1)}…` : text;
|
|
@@ -180,8 +187,12 @@ export function toolLine(part: Part | UnknownPart, root = "", working = true): s
|
|
|
180
187
|
if (part.type !== "tool" || !("toolName" in part)) return null;
|
|
181
188
|
const state = part.state as { status: string; input?: Record<string, unknown>; output?: unknown };
|
|
182
189
|
const input = state.input ?? {};
|
|
190
|
+
// @ref LLP 0002#a-tool-call-says-what-it-acts-on — the command the model wrote, not a harness's shell around it
|
|
191
|
+
const { command, url } = part as { command?: string; url?: string };
|
|
183
192
|
const raw = String(
|
|
184
|
-
|
|
193
|
+
command ??
|
|
194
|
+
url ??
|
|
195
|
+
input.file_path ??
|
|
185
196
|
input.path ??
|
|
186
197
|
input.command ??
|
|
187
198
|
input.pattern ??
|
|
@@ -232,11 +243,35 @@ export function personOnly(waiting: Waiting): string | undefined {
|
|
|
232
243
|
return questions.some((question) => question.secret) ? "a secret to type" : undefined;
|
|
233
244
|
}
|
|
234
245
|
|
|
246
|
+
/**
|
|
247
|
+
* What a permission is about, a line each, quoted: its command, else its
|
|
248
|
+
* address, else its files (under `root` relative to it), then why the agent
|
|
249
|
+
* asks, when it says. Empty when the request carries none of them.
|
|
250
|
+
*/
|
|
251
|
+
function aboutLines(toolCall: DecisionRequest["toolCall"], root: string): string {
|
|
252
|
+
if (!toolCall) return "";
|
|
253
|
+
const files = (toolCall.locations ?? []).map((location) => relativeTo(root, location.path));
|
|
254
|
+
const more = files.length > 10 ? ` (and ${files.length - 10} more)` : "";
|
|
255
|
+
const what = toolCall.command?.trim()
|
|
256
|
+
? `command: ${quoted(clip(relativeTo(root, toolCall.command), 500))}`
|
|
257
|
+
: toolCall.url?.trim()
|
|
258
|
+
? `url: ${quoted(clip(toolCall.url, 500))}`
|
|
259
|
+
: files.length
|
|
260
|
+
? `files: ${files.slice(0, 10).map(quoted).join(", ")}${more}`
|
|
261
|
+
: "";
|
|
262
|
+
const why = toolCall.reason?.trim() ? `reason: ${quoted(clip(toolCall.reason, 300))}` : "";
|
|
263
|
+
return [what, why]
|
|
264
|
+
.filter(Boolean)
|
|
265
|
+
.map((line) => `\n${line}`)
|
|
266
|
+
.join("");
|
|
267
|
+
}
|
|
268
|
+
|
|
235
269
|
/**
|
|
236
270
|
* What the agent waits on, and the exact call that answers it. What only the
|
|
237
|
-
* person can answer (`personOnly`) is one line, with no call.
|
|
271
|
+
* person can answer (`personOnly`) is one line, with no call. Paths under
|
|
272
|
+
* `root` read relative to it.
|
|
238
273
|
*/
|
|
239
|
-
export function describeWaiting(waiting: Waiting, ref: string): string {
|
|
274
|
+
export function describeWaiting(waiting: Waiting, ref: string, root = ""): string {
|
|
240
275
|
const only = waiting.kind === "question" && personOnly(waiting);
|
|
241
276
|
if (only) {
|
|
242
277
|
return `only the person can answer this, where the session runs (${only}): ${quoted(clip(waiting.request.message, 300))}`;
|
|
@@ -270,7 +305,8 @@ export function describeWaiting(waiting: Waiting, ref: string): string {
|
|
|
270
305
|
: `plan waiting for approval; read it before answering\n ${callHint("read_session", { session: ref })}\n${approve}`;
|
|
271
306
|
}
|
|
272
307
|
const named = waiting.request.options.map((option) => option.name);
|
|
273
|
-
|
|
308
|
+
const about = aboutLines(waiting.request.toolCall, root);
|
|
309
|
+
return `${block("permission:", waiting.request.title)}${about}${options(named)}\n ${answer("allow")} (or answer: "deny")`;
|
|
274
310
|
}
|
|
275
311
|
|
|
276
312
|
/** The agent's words since the person last spoke. */
|
|
@@ -289,13 +325,15 @@ export function lastReply(messages: readonly ViewMessage[]): string {
|
|
|
289
325
|
/**
|
|
290
326
|
* How a turn stands: finished, waiting on the person, failed, or still going.
|
|
291
327
|
* `waitedSeconds` is how long this call waited; `note` is the host's line of
|
|
292
|
-
* facts for a turn that is not working any more
|
|
328
|
+
* facts for a turn that is not working any more; paths under `root` in what it
|
|
329
|
+
* waits on read relative to it.
|
|
293
330
|
*/
|
|
294
331
|
export function renderOutcome(
|
|
295
332
|
view: SessionView,
|
|
296
333
|
ref: string,
|
|
297
334
|
waitedSeconds?: number,
|
|
298
335
|
note?: string,
|
|
336
|
+
root?: string,
|
|
299
337
|
): string {
|
|
300
338
|
const phase = phaseOf(view);
|
|
301
339
|
if (phase === "working") {
|
|
@@ -310,7 +348,7 @@ export function renderOutcome(
|
|
|
310
348
|
const lines = [`status: ${fresh ? "idle (no messages yet)" : phase === "idle" ? "done" : phase}`];
|
|
311
349
|
const reply = lastReply(view.messages);
|
|
312
350
|
if (reply) lines.push(block("agent said:", clip(reply, 1500)));
|
|
313
|
-
for (const waiting of view.waiting) lines.push(describeWaiting(waiting, ref));
|
|
351
|
+
for (const waiting of view.waiting) lines.push(describeWaiting(waiting, ref, root));
|
|
314
352
|
if (phase === "error") lines.push(block("error:", view.error ?? "the turn failed"));
|
|
315
353
|
if (note) lines.push(oneLine(note));
|
|
316
354
|
if (phase === "error" || reply.length > 1500) {
|
|
@@ -362,7 +400,7 @@ export function renderConversation(
|
|
|
362
400
|
const cut = view.older || shown.length < view.messages.length;
|
|
363
401
|
lines.push(`(status: ${phaseOf(view)})`);
|
|
364
402
|
if (view.error && phaseOf(view) === "error") lines.push(block("error:", view.error));
|
|
365
|
-
for (const waiting of view.waiting) lines.push(describeWaiting(waiting, ref));
|
|
403
|
+
for (const waiting of view.waiting) lines.push(describeWaiting(waiting, ref, options.root));
|
|
366
404
|
if (cut) {
|
|
367
405
|
lines.push(
|
|
368
406
|
shown.length >= MAX_LAST
|
package/src/protocol/auth.ts
CHANGED
|
@@ -68,6 +68,24 @@ export const AuthMethodSchema = z.object({
|
|
|
68
68
|
});
|
|
69
69
|
export type AuthMethod = z.infer<typeof AuthMethodSchema>;
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* A login under way, answered at once: the user signs in at `url` (entering
|
|
73
|
+
* `userCode` there, for a device code) or, from another device, at `codeUrl`
|
|
74
|
+
* and pastes the code it shows (`auth/complete`). An `api_key` login has none
|
|
75
|
+
* of them. `auth/updated` says how it ended.
|
|
76
|
+
*/
|
|
77
|
+
export const AuthLoginSchema = z.object({
|
|
78
|
+
loginId: z.string(),
|
|
79
|
+
harness: HarnessIdSchema,
|
|
80
|
+
method: z.string(),
|
|
81
|
+
url: z.string().optional(),
|
|
82
|
+
codeUrl: z.string().optional(),
|
|
83
|
+
userCode: z.string().optional(),
|
|
84
|
+
/** When the server gives up on it (epoch ms). */
|
|
85
|
+
expiresAt: z.number().int().nonnegative(),
|
|
86
|
+
});
|
|
87
|
+
export type AuthLogin = z.infer<typeof AuthLoginSchema>;
|
|
88
|
+
|
|
71
89
|
/**
|
|
72
90
|
* One harness's login, as `auth/status` and `auth/logout` answer it, and as
|
|
73
91
|
* a product shows one it holds (`grantAuth`): who, on what kind of
|
|
@@ -85,6 +103,13 @@ export const HarnessAuthSchema = AccountInfoSchema.extend({
|
|
|
85
103
|
/** The logins this harness offers here; none where its agent signs in on its own. */
|
|
86
104
|
methods: z.array(AuthMethodSchema),
|
|
87
105
|
error: z.string().optional(),
|
|
106
|
+
/**
|
|
107
|
+
* The login under way to this harness and store, as `auth/login` answered
|
|
108
|
+
* it: present from its start until its end is told, in every status read
|
|
109
|
+
* and `auth/updated`, so every window shows it (its `url`, `userCode`)
|
|
110
|
+
* and can cancel it; absent otherwise.
|
|
111
|
+
*/
|
|
112
|
+
loginUnderWay: AuthLoginSchema.optional(),
|
|
88
113
|
});
|
|
89
114
|
export type HarnessAuth = z.infer<typeof HarnessAuthSchema>;
|
|
90
115
|
|
|
@@ -129,24 +154,6 @@ export const AuthLoginParamsSchema = z.object({
|
|
|
129
154
|
});
|
|
130
155
|
export type AuthLoginParams = z.infer<typeof AuthLoginParamsSchema>;
|
|
131
156
|
|
|
132
|
-
/**
|
|
133
|
-
* A login under way, answered at once: the user signs in at `url` (entering
|
|
134
|
-
* `userCode` there, for a device code) or, from another device, at `codeUrl`
|
|
135
|
-
* and pastes the code it shows (`auth/complete`). An `api_key` login has none
|
|
136
|
-
* of them. `auth/updated` says how it ended.
|
|
137
|
-
*/
|
|
138
|
-
export const AuthLoginSchema = z.object({
|
|
139
|
-
loginId: z.string(),
|
|
140
|
-
harness: HarnessIdSchema,
|
|
141
|
-
method: z.string(),
|
|
142
|
-
url: z.string().optional(),
|
|
143
|
-
codeUrl: z.string().optional(),
|
|
144
|
-
userCode: z.string().optional(),
|
|
145
|
-
/** When the server gives up on it (epoch ms). */
|
|
146
|
-
expiresAt: z.number().int().nonnegative(),
|
|
147
|
-
});
|
|
148
|
-
export type AuthLogin = z.infer<typeof AuthLoginSchema>;
|
|
149
|
-
|
|
150
157
|
/** `auth/complete`: the code a `codeUrl` page showed, as pasted (`code#state`, or the page's address). */
|
|
151
158
|
export const AuthCompleteParamsSchema = z.object({
|
|
152
159
|
loginId: z.string(),
|
|
@@ -173,11 +180,11 @@ export const AuthLoginEndSchema = z.object({
|
|
|
173
180
|
export type AuthLoginEnd = z.infer<typeof AuthLoginEndSchema>;
|
|
174
181
|
|
|
175
182
|
/**
|
|
176
|
-
* `auth/updated` (server -> every connection): a harness's login changed,
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* answers it.
|
|
183
|
+
* `auth/updated` (server -> every connection): a harness's login changed, a
|
|
184
|
+
* login started (`auth.loginUnderWay`, no `login`), or a login ended
|
|
185
|
+
* (`login`), whoever caused it: `auth/login`, `auth/logout`, or a login in a
|
|
186
|
+
* terminal that a status read noticed. A login's end is always one of these,
|
|
187
|
+
* with the harness's login after it, as `auth/complete` answers it.
|
|
181
188
|
*/
|
|
182
189
|
export const AuthUpdatedSchema = z.object({
|
|
183
190
|
auth: HarnessAuthSchema,
|
package/src/protocol/clis.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { ErrorCategorySchema } from "./errors.ts";
|
|
2
3
|
import { AgentHarnessSchema, HarnessIdSchema } from "./harness.ts";
|
|
3
4
|
import { openVocabulary } from "./vocabulary.ts";
|
|
4
5
|
|
|
@@ -10,8 +11,10 @@ import { openVocabulary } from "./vocabulary.ts";
|
|
|
10
11
|
* cannot run here;
|
|
11
12
|
* - `installing` — being installed now, `receivedBytes` of `totalBytes`
|
|
12
13
|
* downloaded (none before its download starts);
|
|
13
|
-
* - `failed` — the last install failed, `error` says why
|
|
14
|
-
*
|
|
14
|
+
* - `failed` — the last install failed, `error` says why and `category`
|
|
15
|
+
* what failed (the error vocabulary's: `network` for a registry that
|
|
16
|
+
* cannot be reached or answers 5xx, or a transfer that was cut); the next
|
|
17
|
+
* turn or prepare tries again;
|
|
15
18
|
* - `unmanaged` — the engine does not install this harness's agent (ACP: the
|
|
16
19
|
* operator's launch command).
|
|
17
20
|
* OPEN: treat a state this build does not know as `missing`.
|
|
@@ -37,6 +40,8 @@ export const HarnessCliSchema = z.object({
|
|
|
37
40
|
receivedBytes: z.number().int().nonnegative().optional(),
|
|
38
41
|
totalBytes: z.number().int().nonnegative().optional(),
|
|
39
42
|
error: z.string().optional(),
|
|
43
|
+
/** What failed, with `error` (`failed` only). OPEN, as every category is. */
|
|
44
|
+
category: ErrorCategorySchema.optional(),
|
|
40
45
|
});
|
|
41
46
|
export type HarnessCli = z.infer<typeof HarnessCliSchema>;
|
|
42
47
|
|
|
@@ -55,8 +60,9 @@ export type CliPhase = (typeof CLI_PHASES)[number] | (string & {});
|
|
|
55
60
|
|
|
56
61
|
/**
|
|
57
62
|
* `clis/progress` (server -> every connection): a harness's CLI being
|
|
58
|
-
* installed, whoever caused it (a turn,
|
|
59
|
-
*
|
|
63
|
+
* installed, whoever caused it (a turn, `clis/prepare`, `auth/login`,
|
|
64
|
+
* `auth/logout`; a read such as `models/list` or `auth/status` installs
|
|
65
|
+
* nothing). At most four a second per install, and always its last phase.
|
|
60
66
|
*/
|
|
61
67
|
export const HarnessCliProgressSchema = z.object({
|
|
62
68
|
harness: HarnessIdSchema,
|
|
@@ -65,5 +71,7 @@ export const HarnessCliProgressSchema = z.object({
|
|
|
65
71
|
receivedBytes: z.number().int().nonnegative(),
|
|
66
72
|
totalBytes: z.number().int().nonnegative().optional(),
|
|
67
73
|
error: z.string().optional(),
|
|
74
|
+
/** What failed, with `error` (`failed` only), as on `HarnessCli`. */
|
|
75
|
+
category: ErrorCategorySchema.optional(),
|
|
68
76
|
});
|
|
69
77
|
export type HarnessCliProgress = z.infer<typeof HarnessCliProgressSchema>;
|
|
@@ -83,6 +83,25 @@ export async function tokenDigest(token: string): Promise<string> {
|
|
|
83
83
|
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* A JWT's claims, read, not verified: only ever of a token its issuer just
|
|
88
|
+
* answered over TLS, or the CLI that holds it. `{}` for anything else.
|
|
89
|
+
*/
|
|
90
|
+
export function claimsOf(jwt: string): Record<string, unknown> {
|
|
91
|
+
try {
|
|
92
|
+
const payload = (jwt.split(".")[1] ?? "").replace(/-/g, "+").replace(/_/g, "/");
|
|
93
|
+
const binary = atob(payload.padEnd(Math.ceil(payload.length / 4) * 4, "="));
|
|
94
|
+
// UTF-8, so an email in another script reads as it was written.
|
|
95
|
+
const text = new TextDecoder().decode(Uint8Array.from(binary, (char) => char.charCodeAt(0)));
|
|
96
|
+
const parsed: unknown = JSON.parse(text);
|
|
97
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)
|
|
98
|
+
? (parsed as Record<string, unknown>)
|
|
99
|
+
: {};
|
|
100
|
+
} catch {
|
|
101
|
+
return {};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
86
105
|
/**
|
|
87
106
|
* What a product stores for an account it holds: who it is (`AccountInfo`),
|
|
88
107
|
* the credential a turn gets, and what renews it (a ChatGPT login's refresh
|
|
@@ -21,5 +21,10 @@ export const TurnExecutionSchema = z.object({
|
|
|
21
21
|
* those its stream named, else the model Codex reported for the thread. Excludes
|
|
22
22
|
* subagents. Absence means unreported, never a fallback to the requested alias. */
|
|
23
23
|
reportedModels: z.array(z.string()).optional(),
|
|
24
|
+
/** The `RunConfig` fields this turn set that the harness did not apply: those it
|
|
25
|
+
* never applies (`AgentCapabilities.ignoredSettings`) on `turn.started`, and on
|
|
26
|
+
* `turn.ended` with them those it found it could not apply as it ran (an ACP agent
|
|
27
|
+
* that takes no extra directories). Absent when it applied everything the turn set. */
|
|
28
|
+
notApplied: z.array(z.string()).optional(),
|
|
24
29
|
});
|
|
25
30
|
export type TurnExecution = z.infer<typeof TurnExecutionSchema>;
|
|
@@ -3,7 +3,7 @@ import type { Delta } from "./lifecycle.ts";
|
|
|
3
3
|
import { META_KEYS } from "./meta-keys.ts";
|
|
4
4
|
import type { AgentInput } from "./part-input.ts";
|
|
5
5
|
import type { Part, ReasoningPart, SubagentMetadata, TextPart, ToolPart } from "./parts.ts";
|
|
6
|
-
import type { ToolKind, ToolLocation, ToolResultContent } from "./tool-state.ts";
|
|
6
|
+
import type { McpTool, ToolKind, ToolLocation, ToolResultContent } from "./tool-state.ts";
|
|
7
7
|
|
|
8
8
|
/** Context an adapter threads through while building parts for one message. */
|
|
9
9
|
export interface StreamContext {
|
|
@@ -15,7 +15,13 @@ export interface StreamContext {
|
|
|
15
15
|
/** Optional normalized metadata for a tool part (see ToolPart). */
|
|
16
16
|
export interface ToolMeta {
|
|
17
17
|
kind?: ToolKind;
|
|
18
|
+
/** A call to an MCP tool, when the harness knows its server and tool. */
|
|
19
|
+
mcp?: McpTool;
|
|
18
20
|
title?: string;
|
|
21
|
+
/** A command's line as the agent wrote it, apart from any wrapper the harness adds. */
|
|
22
|
+
command?: string;
|
|
23
|
+
/** A fetch's address. */
|
|
24
|
+
url?: string;
|
|
19
25
|
locations?: ToolLocation[];
|
|
20
26
|
/** Present when this tool spawns a subagent (implies kind "task"). */
|
|
21
27
|
subagent?: SubagentMetadata;
|
|
@@ -59,7 +65,10 @@ function toolBase(ctx: StreamContext, toolCallId: string, toolName: string, meta
|
|
|
59
65
|
toolCallId,
|
|
60
66
|
toolName,
|
|
61
67
|
...(meta?.subagent ? { kind: "task" as const } : meta?.kind ? { kind: meta.kind } : {}),
|
|
68
|
+
...(meta?.mcp && { mcp: { ...meta.mcp } }),
|
|
62
69
|
...(meta?.title && { title: meta.title }),
|
|
70
|
+
...(meta?.command && { command: meta.command }),
|
|
71
|
+
...(meta?.url && { url: meta.url }),
|
|
63
72
|
...(meta?.locations?.length && { locations: meta.locations }),
|
|
64
73
|
...(meta?.subagent && { subagent: meta.subagent }),
|
|
65
74
|
};
|
|
@@ -134,11 +143,18 @@ export function setToolMeta(part: ToolPart, meta: ToolMeta): void {
|
|
|
134
143
|
} else if (meta.kind) {
|
|
135
144
|
part.kind = meta.kind;
|
|
136
145
|
}
|
|
146
|
+
if (meta.mcp) part.mcp = { ...meta.mcp };
|
|
137
147
|
if (meta.title) part.title = meta.title;
|
|
148
|
+
if (meta.command) part.command = meta.command;
|
|
149
|
+
if (meta.url) part.url = meta.url;
|
|
138
150
|
if (meta.locations?.length) part.locations = meta.locations;
|
|
139
151
|
}
|
|
140
152
|
|
|
141
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* Mutates a tool part into its terminal `completed`/`failed` state. A failure
|
|
155
|
+
* keeps its `metadata` (a command's exit code) and drops its `content`: what
|
|
156
|
+
* a failed call would have shown did not happen.
|
|
157
|
+
*/
|
|
142
158
|
export function completeToolPart(
|
|
143
159
|
part: ToolPart,
|
|
144
160
|
result: {
|
|
@@ -154,7 +170,13 @@ export function completeToolPart(
|
|
|
154
170
|
const start = part.state.status === "in_progress" ? part.state.time.start : Date.now();
|
|
155
171
|
const input = "input" in part.state ? part.state.input : {};
|
|
156
172
|
part.state = result.isError
|
|
157
|
-
? {
|
|
173
|
+
? {
|
|
174
|
+
status: "failed",
|
|
175
|
+
input,
|
|
176
|
+
error: result.output,
|
|
177
|
+
...(result.metadata && { metadata: result.metadata }),
|
|
178
|
+
time: { start, end: Date.now() },
|
|
179
|
+
}
|
|
158
180
|
: {
|
|
159
181
|
status: "completed",
|
|
160
182
|
input,
|
package/src/protocol/harness.ts
CHANGED
|
@@ -8,8 +8,10 @@ import { openVocabulary } from "./vocabulary.ts";
|
|
|
8
8
|
* - `acp` — any Agent Client Protocol v1 agent subprocess (`gemini --acp`,
|
|
9
9
|
* `claude-code-acp`, `codex-acp`, ACP registry agents); the launch
|
|
10
10
|
* command is operator-configured, never taken from the wire
|
|
11
|
+
* - `scripted` — a script the operator gives plays the agent (a product's
|
|
12
|
+
* free test double); registered only with its script
|
|
11
13
|
*/
|
|
12
|
-
export const AGENT_HARNESSES = ["claude-code", "codex-app-server", "acp"] as const;
|
|
14
|
+
export const AGENT_HARNESSES = ["claude-code", "codex-app-server", "acp", "scripted"] as const;
|
|
13
15
|
export type AgentHarness = (typeof AGENT_HARNESSES)[number];
|
|
14
16
|
export const AgentHarnessSchema = z.enum(AGENT_HARNESSES);
|
|
15
17
|
|
|
@@ -98,5 +100,13 @@ export const AgentCapabilitiesSchema = z.object({
|
|
|
98
100
|
* its next step, inside the same turn.
|
|
99
101
|
*/
|
|
100
102
|
steering: z.boolean().optional(),
|
|
103
|
+
/**
|
|
104
|
+
* The `RunConfig` fields this harness never applies: a turn that sets one
|
|
105
|
+
* runs without it, and says so (`turn.started.execution.notApplied`). A
|
|
106
|
+
* setting applied with another meaning is not listed, nor one the harness
|
|
107
|
+
* refuses (the turn fails). Always present from this engine; absent from
|
|
108
|
+
* an older one, which says nothing either way.
|
|
109
|
+
*/
|
|
110
|
+
ignoredSettings: z.array(z.string()).optional(),
|
|
101
111
|
});
|
|
102
112
|
export type AgentCapabilities = z.infer<typeof AgentCapabilitiesSchema>;
|
package/src/protocol/history.ts
CHANGED
|
@@ -26,6 +26,26 @@ export const HISTORY_MAX_RECORDS = 256;
|
|
|
26
26
|
export const HISTORY_WAIT_TIMEOUT_MS = 15_000;
|
|
27
27
|
export const HISTORY_MAX_BYTES = 8 * 1024 * 1024;
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* The `_meta` key on what a durable store kept in place of a binary it could
|
|
31
|
+
* not keep whole: an image or file whose base64 `data` would not fit an
|
|
32
|
+
* event's record or a checkpoint. The entry is text, so every reader renders
|
|
33
|
+
* it as it is: a tool result's `content` image becomes a `text` entry, an
|
|
34
|
+
* image or file part a `text` part at the same address. Under this key it
|
|
35
|
+
* says what was there (`OmittedBinary`). Every client receives this entry,
|
|
36
|
+
* live and on replay alike: the stream delivers what the store kept.
|
|
37
|
+
*/
|
|
38
|
+
export const OMITTED_BINARY_META_KEY = "agent-server/omittedBinary";
|
|
39
|
+
/** What an entry under `OMITTED_BINARY_META_KEY` stands for. */
|
|
40
|
+
export interface OmittedBinary {
|
|
41
|
+
/** The entry it replaced: a tool result's or part's `image`, or a `file` part. */
|
|
42
|
+
type: "image" | "file";
|
|
43
|
+
mimeType: string;
|
|
44
|
+
/** The binary's size, decoded from its base64. */
|
|
45
|
+
bytes: number;
|
|
46
|
+
filename?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
29
49
|
const id = z.string().min(1).max(512);
|
|
30
50
|
const seq = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
31
51
|
/** A history: the store that writes it (`sourceId`) and its session. */
|
|
@@ -8,7 +8,7 @@ import { MetaSchema } from "./meta.ts";
|
|
|
8
8
|
import { type Part, PartSchema, type UnknownPart, decodePart } from "./parts.ts";
|
|
9
9
|
import { EpochMsSchema } from "./time.ts";
|
|
10
10
|
import { TokenUsageSchema } from "./tokens.ts";
|
|
11
|
-
import { ToolKindSchema, ToolLocationSchema } from "./tool-state.ts";
|
|
11
|
+
import { McpToolSchema, ToolKindSchema, ToolLocationSchema } from "./tool-state.ts";
|
|
12
12
|
import { openVocabulary } from "./vocabulary.ts";
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -374,8 +374,17 @@ export const PermissionToolCallSchema = z.object({
|
|
|
374
374
|
toolCallId: z.string().optional(),
|
|
375
375
|
toolName: z.string(),
|
|
376
376
|
kind: ToolKindSchema.optional(),
|
|
377
|
+
/** A call to an MCP tool: its server and tool, as on its tool part. */
|
|
378
|
+
mcp: McpToolSchema.optional(),
|
|
379
|
+
/** The label the engine or the agent gives the call, on every harness. */
|
|
377
380
|
title: z.string().optional(),
|
|
381
|
+
/** A command's line, as on its tool part. */
|
|
382
|
+
command: z.string().optional(),
|
|
383
|
+
/** A fetch's address, as on its tool part. */
|
|
384
|
+
url: z.string().optional(),
|
|
378
385
|
locations: z.array(ToolLocationSchema).optional(),
|
|
386
|
+
/** Why this call needs the person, in the harness's or the model's words, when it says. */
|
|
387
|
+
reason: z.string().optional(),
|
|
379
388
|
rawInput: z.record(z.string(), z.unknown()).optional(),
|
|
380
389
|
});
|
|
381
390
|
export type PermissionToolCall = z.infer<typeof PermissionToolCallSchema>;
|