@sema-agent/core 7.54.1 → 7.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +437 -0
- package/dist/agents/agent-transcript-tool.js +2 -1
- package/dist/agents/builtin-agents.d.ts +12 -14
- package/dist/agents/cc-peer-directory.d.ts +36 -0
- package/dist/agents/cc-peer-directory.js +138 -0
- package/dist/agents/cc-peer-wire.d.ts +105 -0
- package/dist/agents/cc-peer-wire.js +98 -0
- package/dist/agents/cc-uds-peer-channel.d.ts +40 -0
- package/dist/agents/cc-uds-peer-channel.js +457 -0
- package/dist/agents/cross-session-envelope.d.ts +4 -1
- package/dist/agents/cross-session-envelope.js +8 -1
- package/dist/agents/cross-session-judge.d.ts +2 -2
- package/dist/agents/list-agents-tool.js +2 -1
- package/dist/agents/observer.d.ts +4 -5
- package/dist/agents/observer.js +2 -1
- package/dist/agents/peer-admission.d.ts +6 -0
- package/dist/agents/peer-admission.js +4 -1
- package/dist/agents/peer-directory.d.ts +43 -9
- package/dist/agents/peer-directory.js +66 -23
- package/dist/agents/peer-notices.d.ts +1 -1
- package/dist/agents/peer-session-drain.d.ts +3 -1
- package/dist/agents/peer-session-drain.js +1 -0
- package/dist/agents/read-inbox-tool.js +2 -1
- package/dist/agents/retain-ledger.d.ts +1 -1
- package/dist/agents/roster-store.d.ts +1 -1
- package/dist/agents/send-message-tool.d.ts +10 -0
- package/dist/agents/send-message-tool.js +34 -5
- package/dist/agents/subagent.d.ts +34 -79
- package/dist/agents/subagent.js +45 -46
- package/dist/agents/tool-filter.d.ts +29 -46
- package/dist/agents/tool-filter.js +8 -31
- package/dist/agents/verify.d.ts +3 -3
- package/dist/brain/anthropic.js +14 -9
- package/dist/brain/errors.d.ts +15 -0
- package/dist/brain/errors.js +10 -0
- package/dist/brain/model-presets.d.ts +4 -4
- package/dist/brain/open-responses.js +15 -10
- package/dist/brain/openai.js +17 -12
- package/dist/brain/provider-dialect.d.ts +39 -3
- package/dist/brain/provider-dialect.js +28 -0
- package/dist/brain/reasoning.d.ts +1 -1
- package/dist/brain/request-params.d.ts +55 -5
- package/dist/brain/request-params.js +35 -3
- package/dist/brain/retry.d.ts +1 -1
- package/dist/brain/route-adjudicator.d.ts +15 -0
- package/dist/brain/route-adjudicator.js +15 -0
- package/dist/brain/stream-engine.js +6 -5
- package/dist/brain/stream-shared.d.ts +1 -1
- package/dist/core/advisor-verdict.d.ts +120 -0
- package/dist/core/advisor-verdict.js +92 -0
- package/dist/core/agent-definition.d.ts +7 -8
- package/dist/core/allow-entry.d.ts +49 -23
- package/dist/core/allow-entry.js +57 -32
- package/dist/core/allow-rule-shadow.d.ts +7 -0
- package/dist/core/approval-object.d.ts +2 -1
- package/dist/core/approval-object.js +6 -6
- package/dist/core/ask-origin.d.ts +63 -11
- package/dist/core/ask-origin.js +27 -5
- package/dist/core/ask-question.js +10 -4
- package/dist/core/auto-compaction.d.ts +11 -8
- package/dist/core/auto-compaction.js +4 -2
- package/dist/core/auto-mode-arming.d.ts +2 -2
- package/dist/core/auto-mode-defaults.d.ts +8 -8
- package/dist/core/auto-mode-prompt-assets.d.ts +3 -3
- package/dist/core/auto-mode-prompt.d.ts +1 -1
- package/dist/core/auto-mode.d.ts +17 -9
- package/dist/core/auto-mode.js +9 -6
- package/dist/core/background-agent-store.d.ts +3 -3
- package/dist/core/canonical-json.d.ts +1 -1
- package/dist/core/canonical-json.js +2 -2
- package/dist/core/checkpoint-requirements.d.ts +6 -3
- package/dist/core/checkpoint-requirements.js +4 -14
- package/dist/core/checkpoint-store.d.ts +80 -51
- package/dist/core/checkpoint-store.js +56 -74
- package/dist/core/child-clamp-seats.d.ts +6 -0
- package/dist/core/child-clamp-seats.js +3 -16
- package/dist/core/compliance.d.ts +2 -2
- package/dist/core/context-edit.d.ts +6 -7
- package/dist/core/cross-boundary-taint.d.ts +9 -3
- package/dist/core/cross-boundary-taint.js +5 -3
- package/dist/core/decision-receipt.js +2 -2
- package/dist/core/effective-path-target.d.ts +1 -1
- package/dist/core/engine-notice.d.ts +19 -5
- package/dist/core/exec-output-tail.d.ts +1 -1
- package/dist/core/file-history-retention.d.ts +1 -1
- package/dist/core/file-history-store.d.ts +59 -9
- package/dist/core/file-history-store.js +35 -17
- package/dist/core/gate-fold.js +3 -2
- package/dist/core/gate-lanes.js +12 -8
- package/dist/core/gate-outcome.d.ts +17 -4
- package/dist/core/gate-outcome.js +30 -0
- package/dist/core/governance-codes.d.ts +13 -3
- package/dist/core/governance-codes.js +10 -0
- package/dist/core/hands-band.d.ts +1 -1
- package/dist/core/hooks.d.ts +4 -4
- package/dist/core/host-target.d.ts +49 -0
- package/dist/core/host-target.js +59 -0
- package/dist/core/image-downsample.d.ts +1 -1
- package/dist/core/lsp-diagnostics.d.ts +4 -4
- package/dist/core/lsp.d.ts +3 -3
- package/dist/core/mailbox-store.d.ts +4 -0
- package/dist/core/mcp-connection-pool.d.ts +18 -2
- package/dist/core/mcp-connection-pool.js +53 -6
- package/dist/core/mcp-failure.d.ts +23 -4
- package/dist/core/mcp-failure.js +26 -11
- package/dist/core/mcp-listing-drift.d.ts +10 -0
- package/dist/core/mcp-listing-drift.js +6 -0
- package/dist/core/mcp-server-link.d.ts +173 -0
- package/dist/core/mcp-server-link.js +127 -0
- package/dist/core/mcp-server-spec.d.ts +4 -2
- package/dist/core/mcp-session-end.d.ts +26 -0
- package/dist/core/mcp-session-end.js +29 -0
- package/dist/core/mcp-startup-request.d.ts +17 -0
- package/dist/core/mcp-startup-request.js +17 -0
- package/dist/core/mcp.d.ts +13 -13
- package/dist/core/mcp.js +187 -162
- package/dist/core/media-byte-cap.d.ts +1 -1
- package/dist/core/memory-engine/engine.d.ts +9 -9
- package/dist/core/memory-engine/provenance-wording.d.ts +1 -1
- package/dist/core/memory-engine/tools.js +4 -1
- package/dist/core/mode-policy.d.ts +1 -1
- package/dist/core/namespaced-rule-name.d.ts +33 -7
- package/dist/core/namespaced-rule-name.js +39 -25
- package/dist/core/output-style.d.ts +1 -1
- package/dist/core/param-rule-reach.d.ts +15 -0
- package/dist/core/param-rule-reach.js +30 -0
- package/dist/core/parent-spec-seat.d.ts +8 -1
- package/dist/core/parent-spec-seat.js +4 -0
- package/dist/core/pause-registry.d.ts +16 -5
- package/dist/core/pause-registry.js +6 -2
- package/dist/core/peer-channel.d.ts +70 -0
- package/dist/core/peer-channel.js +1 -0
- package/dist/core/permission-rule-consent.d.ts +11 -5
- package/dist/core/permission-rule-consent.js +37 -30
- package/dist/core/permission-rule-model.d.ts +233 -64
- package/dist/core/permission-rule-model.js +384 -85
- package/dist/core/permission-rule-provider.d.ts +2 -1
- package/dist/core/permission-rule-store.d.ts +20 -25
- package/dist/core/permission-rule-store.js +1 -4
- package/dist/core/permission-rule-sync.d.ts +11 -2
- package/dist/core/permission-rule-sync.js +8 -1
- package/dist/core/permission-rules.d.ts +49 -11
- package/dist/core/permission-rules.js +123 -89
- package/dist/core/persisted-rule-arms.d.ts +4 -2
- package/dist/core/present-plan-tool.js +3 -1
- package/dist/core/protocol-naming.d.ts +2 -2
- package/dist/core/read-only-shell-table.d.ts +1 -1
- package/dist/core/read-only-shell.d.ts +1 -1
- package/dist/core/roles.d.ts +6 -2
- package/dist/core/roles.js +45 -44
- package/dist/core/rule-offer-read.d.ts +53 -0
- package/dist/core/rule-offer-read.js +146 -0
- package/dist/core/rule-owner.d.ts +46 -0
- package/dist/core/rule-owner.js +28 -0
- package/dist/core/runner/advisor-instructions.d.ts +70 -0
- package/dist/core/runner/advisor-instructions.js +61 -0
- package/dist/core/runner/advisor-tool.d.ts +33 -0
- package/dist/core/runner/advisor-tool.js +112 -0
- package/dist/core/runner/announce-once-ledger.d.ts +4 -26
- package/dist/core/runner/announce-once-ledger.js +14 -46
- package/dist/core/runner/approval-feedback.js +6 -3
- package/dist/core/runner/assemble-result.d.ts +1 -1
- package/dist/core/runner/caller-roster.d.ts +7 -0
- package/dist/core/runner/caller-roster.js +11 -0
- package/dist/core/runner/classifier-ladder.d.ts +27 -5
- package/dist/core/runner/classifier-ladder.js +12 -11
- package/dist/core/runner/compaction-restate.d.ts +10 -6
- package/dist/core/runner/compaction-restate.js +9 -3
- package/dist/core/runner/contracts.d.ts +13 -9
- package/dist/core/runner/conversation-segment.d.ts +28 -0
- package/dist/core/runner/conversation-segment.js +42 -0
- package/dist/core/runner/cross-boundary-lane.d.ts +6 -5
- package/dist/core/runner/cross-boundary-lane.js +26 -15
- package/dist/core/runner/decide-continuation.d.ts +7 -4
- package/dist/core/runner/decide-continuation.js +2 -2
- package/dist/core/runner/denial-limit-arms.d.ts +2 -2
- package/dist/core/runner/derived-route-fallback.d.ts +24 -24
- package/dist/core/runner/derived-route-fallback.js +9 -7
- package/dist/core/runner/gate-exit.d.ts +6 -0
- package/dist/core/runner/gate-exit.js +7 -2
- package/dist/core/runner/initial-run-state.js +1 -1
- package/dist/core/runner/permission-rule-lanes.d.ts +2 -2
- package/dist/core/runner/permission-rule-lanes.js +14 -7
- package/dist/core/runner/person-path-rows.js +1 -1
- package/dist/core/runner/prepare-advisor.d.ts +63 -0
- package/dist/core/runner/prepare-advisor.js +77 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +1 -1
- package/dist/core/runner/prepare-config-doors.d.ts +6 -4
- package/dist/core/runner/prepare-config-doors.js +18 -12
- package/dist/core/runner/prepare-delegation-surface.d.ts +2 -2
- package/dist/core/runner/prepare-delegation-surface.js +1 -1
- package/dist/core/runner/prepare-file-history.js +39 -39
- package/dist/core/runner/prepare-gate-stations.d.ts +1 -4
- package/dist/core/runner/prepare-gate-stations.js +2 -7
- package/dist/core/runner/prepare-inherited-gate.d.ts +5 -4
- package/dist/core/runner/prepare-inherited-gate.js +3 -3
- package/dist/core/runner/prepare-park-ask.js +7 -7
- package/dist/core/runner/prepare-policy-chain.d.ts +1 -1
- package/dist/core/runner/prepare-policy-chain.js +4 -10
- package/dist/core/runner/prepare-project-context.d.ts +5 -2
- package/dist/core/runner/prepare-project-context.js +6 -3
- package/dist/core/runner/prepare-prompt-inputs.js +1 -1
- package/dist/core/runner/prepare-protocol-tools.d.ts +2 -2
- package/dist/core/runner/prepare-protocol-tools.js +3 -2
- package/dist/core/runner/prepare-safety-scan.d.ts +9 -12
- package/dist/core/runner/prepare-safety-scan.js +8 -6
- package/dist/core/runner/prepare-task.js +15 -18
- package/dist/core/runner/prepare-tool-disclosure-mount.js +6 -4
- package/dist/core/runner/prepare-wiring-manifest.d.ts +6 -3
- package/dist/core/runner/prepare-wiring-manifest.js +2 -2
- package/dist/core/runner/resume-policy-outcome.js +1 -1
- package/dist/core/runner/retired-runner-deps.js +1 -1
- package/dist/core/runner/run-attachment-seats.js +0 -1
- package/dist/core/runner/run-compaction-machinery.d.ts +1 -1
- package/dist/core/runner/run-compaction-machinery.js +2 -12
- package/dist/core/runner/run-git-lane.d.ts +1 -0
- package/dist/core/runner/run-harness-handlers.js +2 -3
- package/dist/core/runner/run-leg.js +13 -0
- package/dist/core/runner/run-settle-and-teardown.js +1 -1
- package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
- package/dist/core/runner/run-turn-boundary.d.ts +1 -0
- package/dist/core/runner/run-turn-boundary.js +14 -12
- package/dist/core/runner/session-rule-policy.d.ts +22 -21
- package/dist/core/runner/session-rule-policy.js +13 -28
- package/dist/core/runner/side-call-account.d.ts +32 -8
- package/dist/core/runner/side-call-account.js +23 -1
- package/dist/core/runner/strict-output-schema.d.ts +1 -1
- package/dist/core/runner/sub-agent-deny-lists.js +4 -3
- package/dist/core/runner/synthetic-tools.d.ts +10 -13
- package/dist/core/runner/synthetic-tools.js +4 -2
- package/dist/core/runner/tool-disclosure.js +2 -1
- package/dist/core/runner/tool-face-overlay.d.ts +2 -1
- package/dist/core/runner/tool-face-overlay.js +17 -1
- package/dist/core/runner/tool-progress-lane.d.ts +2 -2
- package/dist/core/runner/tool-turn-repair-seat.d.ts +3 -2
- package/dist/core/runner/turn-attachments.d.ts +60 -67
- package/dist/core/runner-deps.d.ts +37 -37
- package/dist/core/runtime-caps.d.ts +4 -4
- package/dist/core/safety-merge-corpus.js +17 -1
- package/dist/core/same-plain-value.d.ts +40 -0
- package/dist/core/same-plain-value.js +49 -0
- package/dist/core/scheduler.d.ts +1 -1
- package/dist/core/sensitive-path-policy.d.ts +1 -1
- package/dist/core/sensitive-path-policy.js +1 -1
- package/dist/core/session-policy-store.d.ts +77 -22
- package/dist/core/session-policy-store.js +56 -14
- package/dist/core/session-reconcile.d.ts +2 -2
- package/dist/core/session-store.d.ts +80 -30
- package/dist/core/session-store.js +118 -76
- package/dist/core/session.d.ts +24 -46
- package/dist/core/shared-memory/tools.js +3 -1
- package/dist/core/shared-memory/types.d.ts +1 -1
- package/dist/core/side-query.d.ts +10 -0
- package/dist/core/side-query.js +5 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +29 -2
- package/dist/core/store-contracts/file-history-store-contract.js +43 -3
- package/dist/core/store-contracts/session-policy-store-contract.d.ts +7 -0
- package/dist/core/store-contracts/session-policy-store-contract.js +130 -0
- package/dist/core/store-contracts/session-repo-contract.js +125 -0
- package/dist/core/store-contracts/session-store-contract.d.ts +4 -7
- package/dist/core/store-contracts/session-store-contract.js +215 -41
- package/dist/core/store-contracts/workflow-journal-store-contract.js +26 -1
- package/dist/core/surrogate-safe-slice.d.ts +3 -3
- package/dist/core/task-event.d.ts +10 -4
- package/dist/core/task-notification.d.ts +3 -3
- package/dist/core/task-registry-agent.d.ts +4 -4
- package/dist/core/task-registry-shared.d.ts +4 -4
- package/dist/core/task-registry-shared.js +1 -0
- package/dist/core/task-registry.d.ts +4 -4
- package/dist/core/task-registry.js +3 -1
- package/dist/core/task-result.d.ts +3 -3
- package/dist/core/task-spec.d.ts +52 -52
- package/dist/core/task-stream.d.ts +6 -6
- package/dist/core/task-tool-shape.d.ts +4 -4
- package/dist/core/tighten-task-spec.d.ts +1 -1
- package/dist/core/tool-catalog-entries.d.ts +19 -2
- package/dist/core/tool-catalog-entries.js +57 -42
- package/dist/core/tool-conformance.js +1 -0
- package/dist/core/tool-errors.d.ts +2 -2
- package/dist/core/tool-face-reader.js +5 -3
- package/dist/core/tool-face.d.ts +21 -2
- package/dist/core/tool-face.js +1 -1
- package/dist/core/tool-model-gate.d.ts +3 -3
- package/dist/core/tool-name-aliases.d.ts +29 -8
- package/dist/core/tool-name-aliases.js +27 -3
- package/dist/core/tool-name-readings.d.ts +5 -8
- package/dist/core/tool-name-readings.js +1 -2
- package/dist/core/tool-policy.d.ts +24 -5
- package/dist/core/tool-policy.js +34 -10
- package/dist/core/tool-registry.d.ts +14 -7
- package/dist/core/tool-registry.js +17 -7
- package/dist/core/tool-result-store.js +2 -1
- package/dist/core/tool-roster.d.ts +47 -18
- package/dist/core/tool-roster.js +53 -32
- package/dist/core/tool-spec-members.js +1 -1
- package/dist/core/tool-spec.d.ts +35 -21
- package/dist/core/tools.js +3 -2
- package/dist/core/trace.d.ts +4 -0
- package/dist/core/untrusted-egress.d.ts +1 -1
- package/dist/core/untrusted-text.d.ts +1 -1
- package/dist/core/warm-resume.d.ts +1 -1
- package/dist/core/wiring-manifest.d.ts +49 -0
- package/dist/core/wiring-manifest.js +13 -5
- package/dist/core/workflow-journal-store.d.ts +62 -0
- package/dist/core/workflow-journal-store.js +77 -1
- package/dist/core/workflow-run-store.d.ts +6 -0
- package/dist/core/workflow-run-store.js +2 -0
- package/dist/engine/compaction/compaction.d.ts +9 -9
- package/dist/engine/execution-env/node-execution-env.d.ts +19 -5
- package/dist/engine/execution-env/node-execution-env.js +43 -22
- package/dist/engine/harness/agent-harness.d.ts +14 -8
- package/dist/engine/harness/agent-harness.js +33 -26
- package/dist/engine/harness/types.d.ts +29 -7
- package/dist/engine/harness/types.js +12 -1
- package/dist/engine/llm/types.d.ts +9 -9
- package/dist/engine/llm/validation.d.ts +4 -1
- package/dist/engine/llm/validation.js +13 -1
- package/dist/engine/loop/agent-loop.d.ts +1 -1
- package/dist/engine/loop/agent-loop.js +10 -8
- package/dist/engine/loop/types.d.ts +15 -13
- package/dist/engine/lsp/node-lsp-manager.d.ts +2 -2
- package/dist/engine/session/memory-repo.d.ts +10 -11
- package/dist/engine/session/memory-repo.js +13 -8
- package/dist/engine/session/parent-chain-guard.d.ts +3 -2
- package/dist/engine/session/parent-chain-guard.js +1 -1
- package/dist/engine/session/repo-utils.d.ts +31 -3
- package/dist/engine/session/repo-utils.js +42 -5
- package/dist/index.d.ts +27 -15
- package/dist/index.js +21 -11
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +3 -3
- package/dist/internal/harness.js +2 -2
- package/dist/internal/llm.d.ts +1 -1
- package/dist/internal/llm.js +1 -1
- package/dist/orchestration/goal.js +2 -2
- package/dist/orchestration/run-workflow-tool.d.ts +2 -2
- package/dist/orchestration/run-workflow-tool.js +5 -3
- package/dist/orchestration/workflow-size-guideline.d.ts +4 -4
- package/dist/orchestration/workflow-types.d.ts +18 -0
- package/dist/orchestration/workflow-types.js +6 -0
- package/dist/orchestration/workflow.d.ts +2 -13
- package/dist/orchestration/workflow.js +21 -31
- package/dist/prompt-assembly/event-registry.js +1 -0
- package/dist/prompt-assembly/tool-catalog.d.ts +3 -0
- package/dist/prompt-assembly/tool-catalog.js +3 -0
- package/dist/prompts/default.d.ts +14 -14
- package/dist/scenarios/full-body.d.ts +4 -4
- package/dist/stores/file/adoption/adopt.d.ts +4 -3
- package/dist/stores/file/adoption/adopt.js +24 -31
- package/dist/stores/file/adoption/marker.d.ts +6 -13
- package/dist/stores/file/adoption/marker.js +6 -15
- package/dist/stores/file/checkpoint-store.d.ts +3 -0
- package/dist/stores/file/checkpoint-store.js +9 -3
- package/dist/stores/file/file-history-store.d.ts +20 -19
- package/dist/stores/file/file-history-store.js +152 -135
- package/dist/stores/file/fs-atomic.d.ts +15 -0
- package/dist/stores/file/fs-atomic.js +89 -14
- package/dist/stores/file/index.d.ts +1 -1
- package/dist/stores/file/mailbox-store.d.ts +3 -0
- package/dist/stores/file/mailbox-store.js +3 -1
- package/dist/stores/file/permission-rule-adopt.d.ts +1 -1
- package/dist/stores/file/permission-rule-adopt.js +15 -16
- package/dist/stores/file/permission-rule-store.d.ts +18 -2
- package/dist/stores/file/permission-rule-store.js +21 -14
- package/dist/stores/file/session-policy-store.d.ts +3 -3
- package/dist/stores/file/session-store.d.ts +26 -11
- package/dist/stores/file/session-store.js +77 -40
- package/dist/stores/file/workflow-journal-store.d.ts +10 -4
- package/dist/stores/file/workflow-journal-store.js +28 -13
- package/dist/tools/artifact/artifact-text.d.ts +1 -1
- package/dist/tools/artifact/artifact-tool.js +2 -1
- package/dist/tools/fs/bash-readonly-classifier.d.ts +3 -3
- package/dist/tools/fs/fs-bash.d.ts +2 -2
- package/dist/tools/fs/fs-bash.js +3 -1
- package/dist/tools/fs/fs-shared.d.ts +8 -8
- package/dist/tools/fs/gh-rate-limit.d.ts +1 -1
- package/dist/tools/fs/notebook.d.ts +2 -2
- package/dist/tools/fs/read-deny.d.ts +29 -7
- package/dist/tools/fs/read-deny.js +63 -22
- package/dist/tools/fs/removal-targets.d.ts +1 -1
- package/dist/tools/fs/safety.d.ts +9 -9
- package/dist/tools/fs/search.d.ts +6 -6
- package/dist/tools/fs/shell-read-check.js +6 -1
- package/dist/tools/fs/shell-read-judge.d.ts +4 -0
- package/dist/tools/fs/shell-read-judge.js +5 -2
- package/dist/tools/loop-tick.d.ts +2 -2
- package/dist/tools/scheduler-tools.js +5 -1
- package/dist/tools/task-list.d.ts +7 -7
- package/dist/tools/task-list.js +5 -1
- package/dist/tools/todo.js +2 -1
- package/dist/tools/web.d.ts +1 -1
- package/dist/tools/web.js +40 -37
- package/dist/tools/worktree.d.ts +3 -3
- package/dist/tools/worktree.js +3 -1
- package/package.json +1 -1
- package/test/export-surface.snapshot.json +5756 -5638
- package/wire-changes/core@7.55.0.json +3318 -0
- package/dist/core/store-contracts/session-store-incarnation-contract.d.ts +0 -39
- package/dist/core/store-contracts/session-store-incarnation-contract.js +0 -95
|
@@ -7,7 +7,7 @@ import { stepsFromMessages } from "./subagent-steps.js";
|
|
|
7
7
|
import { agentStateSourceOfRecord, agentStateSummary, formatAgo, readAgentState } from "../core/agent-state.js";
|
|
8
8
|
import { REPORT_FIELD_MAX } from "./subagent.js";
|
|
9
9
|
import { getSessionRetainLedger } from "./retain-ledger.js";
|
|
10
|
-
import { toolFace } from "../core/tool-catalog-entries.js";
|
|
10
|
+
import { mountRuleFace, toolFace } from "../core/tool-catalog-entries.js";
|
|
11
11
|
import { thrownText } from "../core/thrown-value.js";
|
|
12
12
|
export const AGENT_TRANSCRIPT_TOOL_NAME = "AgentTranscript";
|
|
13
13
|
const AGENT_TRANSCRIPT_DEFAULT_N = 20;
|
|
@@ -25,6 +25,7 @@ export function createAgentTranscriptTool(opts) {
|
|
|
25
25
|
return defineTool({
|
|
26
26
|
name: AGENT_TRANSCRIPT_TOOL_NAME,
|
|
27
27
|
...toolFace("agent-transcript"),
|
|
28
|
+
ruleFace: mountRuleFace("agent-transcript"),
|
|
28
29
|
description: `Read the recent tool steps of a background agent you launched (task_id 'a…' from the Agent tool with ` +
|
|
29
30
|
`run_in_background), so you can see precisely where it got to — useful before SendMessage-ing a follow-up, ` +
|
|
30
31
|
`or to inspect a stopped agent's tail. Returns the last N steps (tool, target, outcome); it does not re-run ` +
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentDefinition } from "../core/types.js";
|
|
2
2
|
/**
|
|
3
|
-
* F1 (design/135 批次3 / PARITY-SPOT-AGENT-TYPES-2026-07-10) — the
|
|
3
|
+
* F1 (design/135 批次3 / PARITY-SPOT-AGENT-TYPES-2026-07-10) — the BUILT-IN `Explore` and
|
|
4
4
|
* `Plan` agent types, ported to sema's AgentDefinition roster shape.
|
|
5
5
|
*
|
|
6
6
|
* Both definitions, their `whenToUse` lines and their system prompts are ported VERBATIM from the
|
|
@@ -13,10 +13,10 @@ import type { AgentDefinition } from "../core/types.js";
|
|
|
13
13
|
* sema adaptations (deliberate, each recorded):
|
|
14
14
|
* - De-branding (prompt-sovereignty / SUBAGENT_PROMPT precedent): CC's persona first sentences name the
|
|
15
15
|
* product ("… for Claude Code, Anthropic's official CLI for Claude." / "… for Claude Code.") — sema
|
|
16
|
-
* stays provider-neutral, the brand clause is dropped; every other byte is
|
|
16
|
+
* stays provider-neutral, the brand clause is dropped; every other byte is unchanged.
|
|
17
17
|
* - Platform arm: CC's `tbm`/`kBm` interpolate per-platform tool guidance (unix Bash vs PowerShell) and
|
|
18
18
|
* a bash-only search mode (`ww()`). sema children run in a POSIX ExecutionEnv with first-party
|
|
19
|
-
* Glob/Grep/Read/Bash under
|
|
19
|
+
* Glob/Grep/Read/Bash under the reference's names — the unix + Glob/Grep arm is baked in
|
|
20
20
|
* (Mu="Glob" :149761, Jc="Grep" :224202, Ls="Read", Lo="Bash").
|
|
21
21
|
* - `model:"inherit"` — sema shape: `model` omitted on an AgentDefinition = inherit the caller's current
|
|
22
22
|
* model (identical semantics). CC's Explore firstParty opus UPGRADE (`GAe`, 409162-409171: built-in
|
|
@@ -27,26 +27,24 @@ import type { AgentDefinition } from "../core/types.js";
|
|
|
27
27
|
* conflict domain at port time. Recorded as the F7 residual; the deployment `loadProjectMemory` seam
|
|
28
28
|
* already receives `isSubagent`/`agentName` and can trim today.
|
|
29
29
|
* - `disallowedTools` → `denyTools` (sema name), with the DELEGATION-tool entry tracking the deployment's
|
|
30
|
-
* actual tool name (default "Agent"
|
|
30
|
+
* actual tool name (default "Agent"). "Artifact" (mounted on the `RunnerDeps.artifactHost`
|
|
31
31
|
* seat) and "ExitPlanMode" (present_plan's canonical name) both name first-party sema tools — the deny bites
|
|
32
32
|
* when the tool is mounted; a deny of an unmounted name is a documented no-op (tool-filter), CC byte parity.
|
|
33
33
|
*/
|
|
34
|
-
/**
|
|
34
|
+
/** Explore `whenToUse`. */
|
|
35
35
|
export declare const EXPLORE_WHEN_TO_USE = "Fast read-only search agent for locating code. Use it to find files by pattern (eg. \"src/components/**/*.tsx\"), grep for symbols or keywords (eg. \"API endpoints\"), or answer \"where is X defined / which files reference Y.\" Do NOT use it for code review, design-doc auditing, cross-file consistency checks, or open-ended analysis \u2014 it reads excerpts rather than whole files and will miss content past its read window. When calling, specify search breadth: \"quick\" for a single targeted lookup, \"medium\" for moderate exploration, or \"very thorough\" to search across multiple locations and naming conventions.";
|
|
36
|
-
/**
|
|
36
|
+
/** Explore `whenToUseLean`. */
|
|
37
37
|
export declare const EXPLORE_WHEN_TO_USE_LEAN = "Read-only search agent for broad fan-out searches \u2014 when answering means sweeping many files, directories, or naming conventions and you only need the conclusion, not the file dumps. It reads excerpts rather than whole files, so it locates code; it doesn't review or audit it. Specify search breadth: \"medium\" for moderate exploration, \"very thorough\" for multiple locations and naming conventions.";
|
|
38
|
-
/**
|
|
38
|
+
/** Plan `whenToUse` (Plan has no lean variant). */
|
|
39
39
|
export declare const PLAN_WHEN_TO_USE = "Software architect agent for designing implementation plans. Use this when you need to plan the implementation strategy for a task. Returns step-by-step plans, identifies critical files, and considers architectural trade-offs.";
|
|
40
|
-
/**
|
|
40
|
+
/** Explore persona, unix+Glob/Grep arm, first sentence de-branded. */
|
|
41
41
|
export declare const EXPLORE_SYSTEM_PROMPT = "You are a file search specialist. You excel at thoroughly navigating and exploring codebases.\n\n=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===\nThis is a READ-ONLY exploration task. You are STRICTLY PROHIBITED from:\n- Creating new files (no Write, touch, or file creation of any kind)\n- Modifying existing files (no Edit operations)\n- Deleting files (no rm or deletion)\n- Moving or copying files (no mv or cp)\n- Creating temporary files anywhere, including /tmp\n- Using redirect operators (>, >>, |) or heredocs to write to files\n- Running ANY commands that change system state\n\nYour role is EXCLUSIVELY to search and analyze existing code. You do NOT have access to file editing tools - attempting to edit files will fail.\n\nYour strengths:\n- Rapidly finding files using glob patterns\n- Searching code and text with powerful regex patterns\n- Reading and analyzing file contents\n\nGuidelines:\n- Use Glob for broad file pattern matching\n- Use Grep for searching file contents with regex\n- Use Read when you know the specific file path you need to read\n- Use Bash ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)\n- NEVER use Bash for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification\n- Adapt your search approach based on the thoroughness level specified by the caller\n- Communicate your final report directly as a regular message - do NOT attempt to create files\n\nNOTE: You are meant to be a fast agent that returns output as quickly as possible. In order to achieve this you must:\n- Make efficient use of the tools that you have at your disposal: be smart about how you search for files and implementations\n- Wherever possible you should try to spawn multiple parallel tool calls for grepping and reading files\n\nComplete the user's search request efficiently and report your findings clearly.";
|
|
42
|
-
/**
|
|
42
|
+
/** Plan persona, unix arm, first sentence de-branded. */
|
|
43
43
|
export declare const PLAN_SYSTEM_PROMPT = "You are a software architect and planning specialist. Your role is to explore the codebase and design implementation plans.\n\n=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===\nThis is a READ-ONLY planning task. You are STRICTLY PROHIBITED from:\n- Creating new files (no Write, touch, or file creation of any kind)\n- Modifying existing files (no Edit operations)\n- Deleting files (no rm or deletion)\n- Moving or copying files (no mv or cp)\n- Creating temporary files anywhere, including /tmp\n- Using redirect operators (>, >>, |) or heredocs to write to files\n- Running ANY commands that change system state\n\nYour role is EXCLUSIVELY to explore the codebase and design implementation plans. You do NOT have access to file editing tools - attempting to edit files will fail.\n\nYou will be provided with a set of requirements and optionally a perspective on how to approach the design process.\n\n## Your Process\n\n1. **Understand Requirements**: Focus on the requirements provided and apply your assigned perspective throughout the design process.\n\n2. **Explore Thoroughly**:\n - Read any files provided to you in the initial prompt\n - Find existing patterns and conventions using Glob, Grep, and Read\n - Understand the current architecture\n - Identify similar features as reference\n - Trace through relevant code paths\n - Use Bash ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)\n - NEVER use Bash for: mkdir, touch, rm, cp, mv, git add, git commit, npm install, pip install, or any file creation/modification\n\n3. **Design Solution**:\n - Create implementation approach based on your assigned perspective\n - Consider trade-offs and architectural decisions\n - Follow existing patterns where appropriate\n\n4. **Detail the Plan**:\n - Provide step-by-step implementation strategy\n - Identify dependencies and sequencing\n - Anticipate potential challenges\n\n## Required Output\n\nEnd your response with:\n\n### Critical Files for Implementation\nList 3-5 files most critical for implementing this plan:\n- path/to/file1.ts\n- path/to/file2.ts\n- path/to/file3.ts\n\nREMEMBER: You can ONLY explore and plan. You CANNOT and MUST NOT write, edit, or modify any files. You do NOT have access to file editing tools.";
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* NotebookEdit FR(143373). The delegation-tool entry is parameterized on the deployment's actual tool
|
|
49
|
-
* name (default = "Agent", CC-verbatim).
|
|
45
|
+
* The six-tool deny set shared by both read-only built-ins: Agent, Artifact, ExitPlanMode, Edit, Write, NotebookEdit.
|
|
46
|
+
* The delegation-tool entry is parameterized on the deployment's actual tool
|
|
47
|
+
* name (default = "Agent").
|
|
50
48
|
*/
|
|
51
49
|
export declare const BUILTIN_READONLY_DENY_TOOLS: (delegationToolName?: string) => string[];
|
|
52
50
|
/**
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type PeerDirectory, type PeerRegistryDirectoryRefusal } from "./peer-directory.js";
|
|
2
|
+
/** The reference's label for a session that has no name (its listing prints it; a peer is addressed by it). */
|
|
3
|
+
export declare const CC_UNNAMED_SESSION_NAME = "(unnamed session)";
|
|
4
|
+
/** What the liveness judgment asks the operating system. Injectable: a test never spawns `ps`. */
|
|
5
|
+
export interface CcProcessProbe {
|
|
6
|
+
/** Does a process with this pid exist (signal 0; a process this uid may not signal still exists)? */
|
|
7
|
+
processExists(pid: number): boolean;
|
|
8
|
+
/** The process start token the reference writes and compares, or `undefined` when it cannot be read
|
|
9
|
+
* (the reference then takes the pid's word). */
|
|
10
|
+
processStartToken(pid: number): Promise<string | undefined>;
|
|
11
|
+
}
|
|
12
|
+
/** The reference's start token: `ps -o lstart= -p <pid>` under `LC_ALL=C TZ=UTC`, trimmed. An OPAQUE token the
|
|
13
|
+
* reference compares for equality — never parsed into a time (the engine's own lock probe asks `etime` for that). */
|
|
14
|
+
export declare function ccProcessStartToken(pid: number): Promise<string | undefined>;
|
|
15
|
+
export declare const defaultCcProcessProbe: CcProcessProbe;
|
|
16
|
+
/** Why one registry file was not read into the listing (closed set; reported, never thrown). */
|
|
17
|
+
export type CcPeerRowSkip = "not_regular" | "foreign_owner" | "group_or_world_writable" | "too_large" | "unreadable" | "not_json" | "no_socket" | "not_live" | "invalid_row";
|
|
18
|
+
/** The registry directory failed its vetting: the listing refuses instead of answering empty. */
|
|
19
|
+
export declare class CcPeerDirectoryError extends Error {
|
|
20
|
+
readonly code: PeerRegistryDirectoryRefusal;
|
|
21
|
+
readonly path: string;
|
|
22
|
+
constructor(code: PeerRegistryDirectoryRefusal, path: string);
|
|
23
|
+
}
|
|
24
|
+
export interface CcPeerDirectoryOptions {
|
|
25
|
+
/** The reference's registry directory (`ccPeerDefaultLocations().registryDir`). */
|
|
26
|
+
registryDir: string;
|
|
27
|
+
/** The scope every row of this registry belongs to (the reference is single-user). Default `"default"`. */
|
|
28
|
+
scope?: string;
|
|
29
|
+
probe?: CcProcessProbe;
|
|
30
|
+
/** One call per skipped file. */
|
|
31
|
+
onSkip?: (file: string, reason: CcPeerRowSkip, detail?: string) => void;
|
|
32
|
+
/** Tests: the uid / platform the vetting and the file judgment use. */
|
|
33
|
+
uid?: number;
|
|
34
|
+
platform?: NodeJS.Platform;
|
|
35
|
+
}
|
|
36
|
+
export declare function createCcPeerDirectory(opts: CcPeerDirectoryOptions): PeerDirectory;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { lstat, readdir, readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { normalizePeerName } from "./cross-session-ref.js";
|
|
5
|
+
import { inheritedHostEnv } from "../core/secret-env.js";
|
|
6
|
+
import { CC_PEER_ROW_FILE_RE } from "./cc-peer-wire.js";
|
|
7
|
+
import { judgePeerRecordFile, PEER_PRESENCE_MAX_CHARS, PEER_SESSION_RECORD_SCHEMA_VERSION, readPeerSessionRecord, vetPeerRegistryDirectory, } from "./peer-directory.js";
|
|
8
|
+
export const CC_UNNAMED_SESSION_NAME = "(unnamed session)";
|
|
9
|
+
export function ccProcessStartToken(pid) {
|
|
10
|
+
if (process.platform === "win32" || !Number.isInteger(pid) || pid <= 0)
|
|
11
|
+
return Promise.resolve(undefined);
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
execFile("ps", ["-o", "lstart=", "-p", String(pid)], { timeout: 1_000, env: { ...inheritedHostEnv("scrub"), LC_ALL: "C", TZ: "UTC" } }, (err, stdout) => {
|
|
14
|
+
const token = err === null ? String(stdout).trim() : "";
|
|
15
|
+
resolve(token === "" ? undefined : token);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export const defaultCcProcessProbe = {
|
|
20
|
+
processExists(pid) {
|
|
21
|
+
try {
|
|
22
|
+
process.kill(pid, 0);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
return e.code === "EPERM";
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
processStartToken: ccProcessStartToken,
|
|
30
|
+
};
|
|
31
|
+
export class CcPeerDirectoryError extends Error {
|
|
32
|
+
code;
|
|
33
|
+
path;
|
|
34
|
+
constructor(code, path) {
|
|
35
|
+
super(`the reference agent's session registry is not a directory this engine can trust (${code}: ${path}) — nothing was listed`);
|
|
36
|
+
this.name = "CcPeerDirectoryError";
|
|
37
|
+
this.code = code;
|
|
38
|
+
this.path = path;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const FEATURE_RE = /^[a-z0-9_]{1,32}$/;
|
|
42
|
+
const MAX_FEATURES = 16;
|
|
43
|
+
export function createCcPeerDirectory(opts) {
|
|
44
|
+
const scope = opts.scope ?? "default";
|
|
45
|
+
const probe = opts.probe ?? defaultCcProcessProbe;
|
|
46
|
+
const selfUid = opts.uid ?? (typeof process.getuid === "function" ? process.getuid() : undefined);
|
|
47
|
+
const skip = (file, reason, detail) => {
|
|
48
|
+
try {
|
|
49
|
+
opts.onSkip?.(file, reason, detail);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const readRow = async (file, pid) => {
|
|
55
|
+
const path = join(opts.registryDir, file);
|
|
56
|
+
let text;
|
|
57
|
+
try {
|
|
58
|
+
const st = await lstat(path);
|
|
59
|
+
const judged = judgePeerRecordFile({ uid: st.uid, mode: st.mode, isFile: st.isFile(), size: st.size }, selfUid, opts.platform);
|
|
60
|
+
if (!judged.ok)
|
|
61
|
+
return void skip(file, judged.code);
|
|
62
|
+
text = await readFile(path, "utf8");
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
return void skip(file, "unreadable", e.code);
|
|
66
|
+
}
|
|
67
|
+
let row;
|
|
68
|
+
try {
|
|
69
|
+
row = JSON.parse(text);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return void skip(file, "not_json");
|
|
73
|
+
}
|
|
74
|
+
if (row === null || typeof row !== "object" || Array.isArray(row))
|
|
75
|
+
return void skip(file, "invalid_row", "not an object");
|
|
76
|
+
const r = row;
|
|
77
|
+
const sockPath = r["messagingSocketPath"];
|
|
78
|
+
if (typeof sockPath !== "string" || sockPath === "")
|
|
79
|
+
return void skip(file, "no_socket");
|
|
80
|
+
if (!probe.processExists(pid))
|
|
81
|
+
return void skip(file, "not_live", "no such process");
|
|
82
|
+
const procStart = typeof r["procStart"] === "string" ? r["procStart"] : undefined;
|
|
83
|
+
if (procStart !== undefined) {
|
|
84
|
+
const now = await probe.processStartToken(pid);
|
|
85
|
+
if (now !== undefined && now !== procStart)
|
|
86
|
+
return void skip(file, "not_live", "the pid belongs to another process now");
|
|
87
|
+
}
|
|
88
|
+
const finite = (v) => (typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : undefined);
|
|
89
|
+
const startedAt = finite(r["startedAt"]) ?? 0;
|
|
90
|
+
const name = typeof r["name"] === "string" && normalizePeerName(r["name"]) !== "" ? r["name"] : CC_UNNAMED_SESSION_NAME;
|
|
91
|
+
const features = Array.isArray(r["peerFeatures"]) ? r["peerFeatures"].filter((f) => typeof f === "string" && FEATURE_RE.test(f)).slice(0, MAX_FEATURES) : undefined;
|
|
92
|
+
const tempo = r["tempo"];
|
|
93
|
+
const agent = typeof r["agent"] === "string" && r["agent"].length <= PEER_PRESENCE_MAX_CHARS ? r["agent"] : undefined;
|
|
94
|
+
const read = readPeerSessionRecord({
|
|
95
|
+
schemaVersion: PEER_SESSION_RECORD_SCHEMA_VERSION,
|
|
96
|
+
sessionId: r["sessionId"],
|
|
97
|
+
scope,
|
|
98
|
+
name,
|
|
99
|
+
pid,
|
|
100
|
+
...(typeof r["cwd"] === "string" ? { cwd: r["cwd"] } : {}),
|
|
101
|
+
startedAt,
|
|
102
|
+
updatedAt: finite(r["updatedAt"]) ?? startedAt,
|
|
103
|
+
liveness: "live",
|
|
104
|
+
...(tempo === "active" || tempo === "idle" || tempo === "blocked" ? { tempo } : {}),
|
|
105
|
+
...(agent !== undefined ? { agent } : {}),
|
|
106
|
+
...(typeof r["entrypoint"] === "string" ? { entrypoint: r["entrypoint"] } : {}),
|
|
107
|
+
...(typeof r["peerProtocol"] === "number" ? { peerProtocol: r["peerProtocol"] } : {}),
|
|
108
|
+
...(features !== undefined ? { peerFeatures: features } : {}),
|
|
109
|
+
sockPath,
|
|
110
|
+
});
|
|
111
|
+
if (!read.ok)
|
|
112
|
+
return void skip(file, "invalid_row", read.field !== undefined ? `${read.reason}: ${read.field}` : read.reason);
|
|
113
|
+
return read.record;
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
async listPeerSessions(access) {
|
|
117
|
+
if (access.scope !== scope)
|
|
118
|
+
return [];
|
|
119
|
+
const verdict = await vetPeerRegistryDirectory(opts.registryDir, { ...(selfUid !== undefined ? { uid: selfUid } : {}), ...(opts.platform !== undefined ? { platform: opts.platform } : {}) });
|
|
120
|
+
if (!verdict.ok)
|
|
121
|
+
throw new CcPeerDirectoryError(verdict.code, verdict.path);
|
|
122
|
+
const names = await readdir(opts.registryDir);
|
|
123
|
+
const rows = [];
|
|
124
|
+
for (const file of names.sort()) {
|
|
125
|
+
const m = CC_PEER_ROW_FILE_RE.exec(file);
|
|
126
|
+
if (m === null)
|
|
127
|
+
continue;
|
|
128
|
+
const pid = Number.parseInt(m[1], 10);
|
|
129
|
+
if (String(pid) !== m[1] || pid <= 0)
|
|
130
|
+
continue;
|
|
131
|
+
const record = await readRow(file, pid);
|
|
132
|
+
if (record !== undefined)
|
|
133
|
+
rows.push(record);
|
|
134
|
+
}
|
|
135
|
+
return rows;
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type CcPeerFrameFields } from "./cross-session-envelope.js";
|
|
2
|
+
/** CC `z8t` — a line longer than this (characters, before its newline) drops the connection. */
|
|
3
|
+
export declare const CC_PEER_LINE_MAX_CHARS = 1048576;
|
|
4
|
+
/** CC `f9n` — a connection with no complete line within this is closed. */
|
|
5
|
+
export declare const CC_PEER_FIRST_LINE_DEADLINE_MS = 30000;
|
|
6
|
+
/** CC's sender socket timeout. */
|
|
7
|
+
export declare const CC_PEER_SEND_TIMEOUT_MS = 5000;
|
|
8
|
+
/** CC `z` — the socket path wall (bytes) of `sun_path`. */
|
|
9
|
+
export declare const CC_PEER_SOCKET_PATH_MAX_BYTES = 103;
|
|
10
|
+
/** CC — the read cap of one key file. */
|
|
11
|
+
export declare const CC_PEER_KEY_FILE_MAX_BYTES = 4096;
|
|
12
|
+
/** CC `$vr` — the registration row's protocol word. */
|
|
13
|
+
export declare const CC_PEER_PROTOCOL = 1;
|
|
14
|
+
/** CC `msgV`. */
|
|
15
|
+
export declare const CC_PEER_MESSAGE_VERSION = 1;
|
|
16
|
+
/** CC `C` — a peer token is 16 random bytes, spelled as 32 lowercase hex. */
|
|
17
|
+
export declare const CC_PEER_TOKEN_RE: RegExp;
|
|
18
|
+
/** CC `xjn` — a published key file: `<pid>.<sha256 of the socket path>.key`. */
|
|
19
|
+
export declare const CC_PEER_KEY_FILE_RE: RegExp;
|
|
20
|
+
/** CC — a registration row file is `<pid>.json`, the pid spelled canonically. */
|
|
21
|
+
export declare const CC_PEER_ROW_FILE_RE: RegExp;
|
|
22
|
+
/** This engine's doorbell action. */
|
|
23
|
+
export declare const CC_PEER_NUDGE_ACTION = "mailbox_nudge";
|
|
24
|
+
/** The hash a key file is named by: sha-256 of the socket's resolved path (CC `Z`). */
|
|
25
|
+
export declare function ccPeerSocketDigest(socketPath: string): string;
|
|
26
|
+
/** The key file name a process publishes for the socket it listens on. */
|
|
27
|
+
export declare function ccPeerKeyFileName(pid: number, socketPath: string): string;
|
|
28
|
+
/** The address a frame names its sender by (CC `aV`): `uds:` + the percent-encoded socket path. */
|
|
29
|
+
export declare function ccPeerAddress(socketPath: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Where the reference agent puts its socket and its session registry (CC 2.1.296, `XDG_RUNTIME_DIR` (cli296.js:274840)): the socket at
|
|
32
|
+
* `${XDG_RUNTIME_DIR || CLAUDE_CODE_TMPDIR || /tmp}/cc-socks/<pid>.sock`, falling back to
|
|
33
|
+
* `/tmp/cc-socks-<uid>/<pid>.sock` when that path is past the `sun_path` wall; the registry at
|
|
34
|
+
* `${CLAUDE_CONFIG_DIR || ~/.claude}/sessions`. Pure: the caller hands in the environment it means.
|
|
35
|
+
*/
|
|
36
|
+
export declare function ccPeerDefaultLocations(args: {
|
|
37
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
38
|
+
homedir: string;
|
|
39
|
+
pid: number;
|
|
40
|
+
uid?: number;
|
|
41
|
+
}): {
|
|
42
|
+
socketPath: string;
|
|
43
|
+
registryDir: string;
|
|
44
|
+
};
|
|
45
|
+
/** The auth line (CC `Gbo`). */
|
|
46
|
+
export declare function encodeCcAuthLine(token: string): string;
|
|
47
|
+
/** One message line (CC's sender frame, key order as the reference writes it). `fields` and `body` go
|
|
48
|
+
* through the envelope text codec; `from` is the sender's own address. */
|
|
49
|
+
export declare function encodeCcUserLine(args: {
|
|
50
|
+
fields: CcPeerFrameFields;
|
|
51
|
+
body: string;
|
|
52
|
+
from?: string;
|
|
53
|
+
msgId?: string;
|
|
54
|
+
}): string;
|
|
55
|
+
/** The doorbell line: a control frame that carries nothing — no content, no sender (the record in the box says who). */
|
|
56
|
+
export declare function encodeCcNudgeLine(args?: {
|
|
57
|
+
msgId?: string;
|
|
58
|
+
}): string;
|
|
59
|
+
/** What one wire line is. `toSession` on a message: absent = unaddressed; `null` = present but not a
|
|
60
|
+
* string (never equal to any session id). */
|
|
61
|
+
export type CcPeerLine = {
|
|
62
|
+
kind: "auth";
|
|
63
|
+
token: string | undefined;
|
|
64
|
+
} | {
|
|
65
|
+
kind: "user";
|
|
66
|
+
content: string;
|
|
67
|
+
from?: string;
|
|
68
|
+
toSession?: string | null;
|
|
69
|
+
attachments: boolean;
|
|
70
|
+
} | {
|
|
71
|
+
kind: "nudge";
|
|
72
|
+
} | {
|
|
73
|
+
kind: "unhandled";
|
|
74
|
+
type: string;
|
|
75
|
+
action?: string;
|
|
76
|
+
} | {
|
|
77
|
+
kind: "malformed";
|
|
78
|
+
why: string;
|
|
79
|
+
};
|
|
80
|
+
/** The ONE reader of an untyped wire value (a parsed JSON line). */
|
|
81
|
+
export declare function readCcPeerLine(value: unknown): CcPeerLine;
|
|
82
|
+
/** Parse one line of text; a line that is not JSON is `malformed`. */
|
|
83
|
+
export declare function parseCcPeerLine(line: string): CcPeerLine;
|
|
84
|
+
/** The facts a session of this engine publishes in the reference agent's registry. */
|
|
85
|
+
export interface CcRegistrationFacts {
|
|
86
|
+
pid: number;
|
|
87
|
+
sessionId: string;
|
|
88
|
+
socketPath: string;
|
|
89
|
+
startedAt: number;
|
|
90
|
+
updatedAt: number;
|
|
91
|
+
cwd?: string;
|
|
92
|
+
name?: string;
|
|
93
|
+
entrypoint?: string;
|
|
94
|
+
/** The process start token the reference reads (`ps -o lstart=`, C locale, UTC). Absent = the reference
|
|
95
|
+
* judges the row by its pid alone. */
|
|
96
|
+
procStart?: string;
|
|
97
|
+
/** The identity of the mailbox store this session drains (`MailboxStore.identity`). Absent = the store cannot
|
|
98
|
+
* say, and the row then carries no capability bit: every sender reaches this session over its socket. */
|
|
99
|
+
storeIdentity?: string;
|
|
100
|
+
}
|
|
101
|
+
/** The registration row this engine writes into the reference agent's registry (`<pid>.json`): the
|
|
102
|
+
* reference's field names, the protocol word, and the capability broadcast — `peerFeatures` carries the one
|
|
103
|
+
* bit naming the store this session drains ({@link semaMailboxFeature}) and nothing else (this engine takes
|
|
104
|
+
* none of the reference's socket features: idle subscriptions and artifact yields travel through the box). */
|
|
105
|
+
export declare function ccRegistrationRow(facts: CcRegistrationFacts): Record<string, unknown>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { join, resolve as resolvePath } from "node:path";
|
|
3
|
+
import { encodeCcPeerFrame, encodePeerAddress } from "./cross-session-envelope.js";
|
|
4
|
+
import { semaMailboxFeature } from "./peer-directory.js";
|
|
5
|
+
export const CC_PEER_LINE_MAX_CHARS = 1_048_576;
|
|
6
|
+
export const CC_PEER_FIRST_LINE_DEADLINE_MS = 30_000;
|
|
7
|
+
export const CC_PEER_SEND_TIMEOUT_MS = 5_000;
|
|
8
|
+
export const CC_PEER_SOCKET_PATH_MAX_BYTES = 103;
|
|
9
|
+
export const CC_PEER_KEY_FILE_MAX_BYTES = 4_096;
|
|
10
|
+
export const CC_PEER_PROTOCOL = 1;
|
|
11
|
+
export const CC_PEER_MESSAGE_VERSION = 1;
|
|
12
|
+
export const CC_PEER_TOKEN_RE = /^[0-9a-f]{32}$/;
|
|
13
|
+
export const CC_PEER_KEY_FILE_RE = /^(\d+)\.([0-9a-f]{64})\.key$/;
|
|
14
|
+
export const CC_PEER_ROW_FILE_RE = /^(\d+)\.json$/;
|
|
15
|
+
export const CC_PEER_NUDGE_ACTION = "mailbox_nudge";
|
|
16
|
+
export function ccPeerSocketDigest(socketPath) {
|
|
17
|
+
return createHash("sha256").update(resolvePath(socketPath)).digest("hex");
|
|
18
|
+
}
|
|
19
|
+
export function ccPeerKeyFileName(pid, socketPath) {
|
|
20
|
+
return `${pid}.${ccPeerSocketDigest(socketPath)}.key`;
|
|
21
|
+
}
|
|
22
|
+
export function ccPeerAddress(socketPath) {
|
|
23
|
+
return encodePeerAddress(`uds:${socketPath}`);
|
|
24
|
+
}
|
|
25
|
+
export function ccPeerDefaultLocations(args) {
|
|
26
|
+
const base = args.env["XDG_RUNTIME_DIR"] || args.env["CLAUDE_CODE_TMPDIR"] || "/tmp";
|
|
27
|
+
const primary = resolvePath(base, "cc-socks", `${args.pid}.sock`);
|
|
28
|
+
const socketPath = Buffer.byteLength(primary) <= CC_PEER_SOCKET_PATH_MAX_BYTES ? primary : join("/tmp", `cc-socks-${args.uid ?? 0}`, `${args.pid}.sock`);
|
|
29
|
+
const registryDir = resolvePath(args.env["CLAUDE_CONFIG_DIR"] || join(args.homedir, ".claude"), "sessions");
|
|
30
|
+
return { socketPath, registryDir };
|
|
31
|
+
}
|
|
32
|
+
export function encodeCcAuthLine(token) {
|
|
33
|
+
return `${JSON.stringify({ type: "auth", token })}\n`;
|
|
34
|
+
}
|
|
35
|
+
export function encodeCcUserLine(args) {
|
|
36
|
+
const content = encodeCcPeerFrame(args.fields, args.body);
|
|
37
|
+
return `${JSON.stringify({ msgV: CC_PEER_MESSAGE_VERSION, msg_id: args.msgId ?? randomUUID(), type: "user", message: { role: "user", content }, priority: "next", ...(args.from !== undefined ? { from: args.from } : {}) })}\n`;
|
|
38
|
+
}
|
|
39
|
+
export function encodeCcNudgeLine(args = {}) {
|
|
40
|
+
return `${JSON.stringify({ type: "control", action: CC_PEER_NUDGE_ACTION, msgV: CC_PEER_MESSAGE_VERSION, msg_id: args.msgId ?? randomUUID() })}\n`;
|
|
41
|
+
}
|
|
42
|
+
export function readCcPeerLine(value) {
|
|
43
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
44
|
+
return { kind: "malformed", why: "not an object" };
|
|
45
|
+
const v = value;
|
|
46
|
+
const type = v["type"];
|
|
47
|
+
if (typeof type !== "string")
|
|
48
|
+
return { kind: "malformed", why: "no type" };
|
|
49
|
+
if (type === "auth")
|
|
50
|
+
return { kind: "auth", token: typeof v["token"] === "string" ? v["token"] : undefined };
|
|
51
|
+
if (type === "user") {
|
|
52
|
+
const message = v["message"];
|
|
53
|
+
const content = message !== null && typeof message === "object" && !Array.isArray(message) ? message["content"] : undefined;
|
|
54
|
+
if (typeof content !== "string" || content.length === 0)
|
|
55
|
+
return { kind: "malformed", why: "user frame without text content" };
|
|
56
|
+
const rawTo = v["session_id"];
|
|
57
|
+
return {
|
|
58
|
+
kind: "user",
|
|
59
|
+
content,
|
|
60
|
+
...(typeof v["from"] === "string" ? { from: v["from"] } : {}),
|
|
61
|
+
...(rawTo !== undefined ? { toSession: typeof rawTo === "string" ? rawTo : null } : {}),
|
|
62
|
+
attachments: v["file_attachments"] !== undefined,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (type === "control") {
|
|
66
|
+
const action = v["action"];
|
|
67
|
+
if (action === CC_PEER_NUDGE_ACTION)
|
|
68
|
+
return { kind: "nudge" };
|
|
69
|
+
return { kind: "unhandled", type, ...(typeof action === "string" ? { action } : {}) };
|
|
70
|
+
}
|
|
71
|
+
return { kind: "unhandled", type };
|
|
72
|
+
}
|
|
73
|
+
export function parseCcPeerLine(line) {
|
|
74
|
+
let value;
|
|
75
|
+
try {
|
|
76
|
+
value = JSON.parse(line);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return { kind: "malformed", why: "not JSON" };
|
|
80
|
+
}
|
|
81
|
+
return readCcPeerLine(value);
|
|
82
|
+
}
|
|
83
|
+
export function ccRegistrationRow(facts) {
|
|
84
|
+
return {
|
|
85
|
+
pid: facts.pid,
|
|
86
|
+
sessionId: facts.sessionId,
|
|
87
|
+
...(facts.cwd !== undefined ? { cwd: facts.cwd } : {}),
|
|
88
|
+
startedAt: facts.startedAt,
|
|
89
|
+
...(facts.procStart !== undefined ? { procStart: facts.procStart } : {}),
|
|
90
|
+
kind: "interactive",
|
|
91
|
+
...(facts.entrypoint !== undefined ? { entrypoint: facts.entrypoint } : {}),
|
|
92
|
+
peerProtocol: CC_PEER_PROTOCOL,
|
|
93
|
+
peerFeatures: facts.storeIdentity !== undefined && facts.storeIdentity !== "" ? [semaMailboxFeature(facts.storeIdentity)] : [],
|
|
94
|
+
messagingSocketPath: facts.socketPath,
|
|
95
|
+
...(facts.name !== undefined ? { name: facts.name } : {}),
|
|
96
|
+
updatedAt: facts.updatedAt,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MailboxStore } from "../core/mailbox-store.js";
|
|
2
|
+
import type { PeerChannel } from "../core/peer-channel.js";
|
|
3
|
+
import { type PeerLaneConfig } from "./peer-admission.js";
|
|
4
|
+
import { type PeerRegistryDirectoryRefusal } from "./peer-directory.js";
|
|
5
|
+
import { type CcProcessProbe } from "./cc-peer-directory.js";
|
|
6
|
+
/** Why `listen` refused to bind (closed set): one of the directory-vetting codes, or one of these. */
|
|
7
|
+
export type CcPeerChannelRefusal = PeerRegistryDirectoryRefusal | "unsupported_platform" | "socket_path_too_long" | "address_in_use" | "already_listening" | "publish_failed";
|
|
8
|
+
export declare class CcPeerChannelError extends Error {
|
|
9
|
+
readonly code: CcPeerChannelRefusal;
|
|
10
|
+
readonly path?: string;
|
|
11
|
+
constructor(code: CcPeerChannelRefusal, message: string, path?: string);
|
|
12
|
+
}
|
|
13
|
+
export interface CcUdsPeerChannelOptions {
|
|
14
|
+
/** The store this session's box lives in (inbound frames are appended here). */
|
|
15
|
+
mailbox: MailboxStore;
|
|
16
|
+
/** Where `listen` binds (`ccPeerDefaultLocations().socketPath` puts it beside the reference's own). */
|
|
17
|
+
socketPath: string;
|
|
18
|
+
/** The reference's session registry (`ccPeerDefaultLocations().registryDir`): `listen` publishes this
|
|
19
|
+
* session's key file and row there; `dial` / `nudge` read a peer's key there. */
|
|
20
|
+
registryDir: string;
|
|
21
|
+
/** The peer lane's knob table (`RunnerDeps.peerLane`): `maxQueuedPeerMessages` bounds inbound appends. */
|
|
22
|
+
lane?: Partial<PeerLaneConfig>;
|
|
23
|
+
/** What this session's registry row says about it beyond its ids. */
|
|
24
|
+
registration?: {
|
|
25
|
+
name?: string;
|
|
26
|
+
cwd?: string;
|
|
27
|
+
startedAt?: number;
|
|
28
|
+
entrypoint?: string;
|
|
29
|
+
};
|
|
30
|
+
/** Tests: this process's pid, the start-token reader, the clocks and walls, the uid / platform. */
|
|
31
|
+
pid?: number;
|
|
32
|
+
probe?: Pick<CcProcessProbe, "processStartToken" | "processExists">;
|
|
33
|
+
now?: () => number;
|
|
34
|
+
firstLineDeadlineMs?: number;
|
|
35
|
+
sendTimeoutMs?: number;
|
|
36
|
+
nudgeTimeoutMs?: number;
|
|
37
|
+
uid?: number;
|
|
38
|
+
platform?: NodeJS.Platform;
|
|
39
|
+
}
|
|
40
|
+
export declare function createCcUdsPeerChannel(opts: CcUdsPeerChannelOptions): PeerChannel;
|