@sema-agent/core 5.19.0 → 5.21.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 +102 -4
- package/dist/agents/agent-definition.d.ts +7 -0
- package/dist/agents/agent-transcript-tool.d.ts +30 -0
- package/dist/agents/builtin-agents.d.ts +60 -0
- package/dist/agents/cascade.d.ts +107 -0
- package/dist/agents/cumulative-stats.d.ts +56 -0
- package/dist/agents/observer.d.ts +162 -0
- package/dist/agents/peer-admission.d.ts +95 -0
- package/dist/agents/repair-loop.d.ts +226 -0
- package/dist/agents/retain-ledger.d.ts +141 -0
- package/dist/agents/roster-store.d.ts +105 -0
- package/dist/agents/roster-store.js +3 -0
- package/dist/agents/send-message-tool.d.ts +92 -0
- package/dist/agents/session-util.d.ts +5 -0
- package/dist/agents/subagent-steps.d.ts +66 -0
- package/dist/agents/subagent.d.ts +600 -0
- package/dist/agents/suspend-guard.d.ts +29 -0
- package/dist/agents/teacher.d.ts +75 -0
- package/dist/agents/team.d.ts +120 -1
- package/dist/agents/tool-filter.d.ts +34 -0
- package/dist/agents/verify.d.ts +198 -0
- package/dist/bench/metrics.d.ts +455 -0
- package/dist/brain/anthropic.d.ts +30 -0
- package/dist/brain/circuit-breaker.d.ts +33 -0
- package/dist/brain/circuit-breaker.js +14 -3
- package/dist/brain/context-overflow.d.ts +60 -3
- package/dist/brain/degrading.d.ts +67 -0
- package/dist/brain/errors.d.ts +42 -0
- package/dist/brain/failover.d.ts +15 -0
- package/dist/brain/media-degrade.d.ts +39 -0
- package/dist/brain/model-presets.d.ts +31 -0
- package/dist/brain/open-responses.d.ts +19 -0
- package/dist/brain/openai.d.ts +46 -0
- package/dist/brain/reasoning.d.ts +106 -1
- package/dist/brain/repetition.d.ts +83 -0
- package/dist/brain/request-params.d.ts +56 -0
- package/dist/brain/retry.d.ts +46 -0
- package/dist/brain/routing.d.ts +12 -0
- package/dist/brain/status-sink.d.ts +30 -1
- package/dist/brain/stream-engine.d.ts +147 -0
- package/dist/brain/stream-shared.d.ts +34 -0
- package/dist/brain/terminal-cause.d.ts +31 -0
- package/dist/brain/timeout.d.ts +108 -0
- package/dist/brain/timeout.js +11 -0
- package/dist/brain/tool-call-id.d.ts +20 -0
- package/dist/brain/tool-call-repair.d.ts +13 -0
- package/dist/config/catalog.d.ts +47 -0
- package/dist/config/defaults.d.ts +33 -0
- package/dist/core/a2a-task-state.d.ts +53 -0
- package/dist/core/a2a.d.ts +51 -0
- package/dist/core/arg-summary.d.ts +62 -0
- package/dist/core/ask-question.d.ts +272 -2
- package/dist/core/auto-compaction.d.ts +467 -0
- package/dist/core/auto-compaction.js +20 -6
- package/dist/core/auto-mode-prompt-assets.d.ts +8 -0
- package/dist/core/auto-mode-prompt.d.ts +27 -0
- package/dist/core/auto-mode.d.ts +54 -3
- package/dist/core/auto-promote.d.ts +100 -0
- package/dist/core/background-agent-store.d.ts +293 -0
- package/dist/core/background-agent-store.js +5 -0
- package/dist/core/background-shell.d.ts +110 -0
- package/dist/core/cache-break-detector.d.ts +34 -0
- package/dist/core/canonical-json.d.ts +57 -0
- package/dist/core/checkpoint-store.d.ts +1574 -16
- package/dist/core/compliance.d.ts +30 -0
- package/dist/core/consolidate-scope.d.ts +75 -0
- package/dist/core/context-edit.d.ts +99 -0
- package/dist/core/context-guard.d.ts +46 -0
- package/dist/core/exec-gate.d.ts +44 -0
- package/dist/core/exec-output-tail.d.ts +61 -0
- package/dist/core/file-snapshot-store.d.ts +104 -0
- package/dist/core/fs-write-gate-policy.d.ts +36 -0
- package/dist/core/git-worktree-env.d.ts +31 -0
- package/dist/core/governance-codes.d.ts +19 -0
- package/dist/core/hooks.d.ts +609 -1
- package/dist/core/human-input-projection.d.ts +37 -0
- package/dist/core/human-input-projection.js +13 -0
- package/dist/core/image-downsample.d.ts +74 -0
- package/dist/core/locked-config.d.ts +37 -0
- package/dist/core/lsp-diagnostics.d.ts +77 -0
- package/dist/core/lsp-protocol.d.ts +29 -0
- package/dist/core/lsp-session.d.ts +60 -1
- package/dist/core/lsp.d.ts +150 -1
- package/dist/core/mailbox-store.d.ts +57 -0
- package/dist/core/mailbox-store.js +2 -0
- package/dist/core/mcp.d.ts +385 -0
- package/dist/core/mcp.js +58 -11
- package/dist/core/media-byte-cap.d.ts +21 -0
- package/dist/core/memory-admission.d.ts +71 -0
- package/dist/core/memory-engine/content-origin.d.ts +64 -0
- package/dist/core/memory-engine/data-plane.d.ts +43 -0
- package/dist/core/memory-engine/dual-root.d.ts +24 -0
- package/dist/core/memory-engine/engine.d.ts +230 -0
- package/dist/core/memory-engine/engine.js +103 -35
- package/dist/core/memory-engine/file-backend.d.ts +155 -0
- package/dist/core/memory-engine/frontmatter.d.ts +16 -0
- package/dist/core/memory-engine/layout.d.ts +217 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +12 -0
- package/dist/core/memory-engine/migrate.d.ts +9 -0
- package/dist/core/memory-engine/scan.d.ts +12 -0
- package/dist/core/memory-engine/scope-contract.d.ts +61 -1
- package/dist/core/memory-engine/sync-client.d.ts +87 -0
- package/dist/core/memory-engine/sync.d.ts +60 -0
- package/dist/core/memory-engine/tools.d.ts +41 -0
- package/dist/core/memory-engine/types.d.ts +188 -0
- package/dist/core/memory-recall.d.ts +141 -0
- package/dist/core/memory-vector.d.ts +20 -0
- package/dist/core/memory.d.ts +458 -0
- package/dist/core/message-utils.d.ts +6 -0
- package/dist/core/oracle-isolation.d.ts +69 -0
- package/dist/core/permission-rule-consent.d.ts +138 -0
- package/dist/core/permission-rule-model.d.ts +122 -0
- package/dist/core/permission-rule-store.d.ts +119 -3
- package/dist/core/permission-rules.d.ts +87 -1
- package/dist/core/present-plan-tool.d.ts +20 -0
- package/dist/core/pricing.d.ts +26 -0
- package/dist/core/property-harness.d.ts +86 -0
- package/dist/core/protocol-naming.d.ts +38 -0
- package/dist/core/protocol-table.d.ts +61 -0
- package/dist/core/push-queue.d.ts +1 -0
- package/dist/core/remote-env.d.ts +383 -1
- package/dist/core/retention-policy.d.ts +40 -0
- package/dist/core/retention-policy.js +21 -0
- package/dist/core/retention.d.ts +51 -0
- package/dist/core/roles.d.ts +59 -0
- package/dist/core/runner/active-skill-scope.d.ts +34 -0
- package/dist/core/runner/assemble-result.d.ts +134 -0
- package/dist/core/runner/compaction-call-options.d.ts +97 -1
- package/dist/core/runner/grounding-signal.d.ts +10 -0
- package/dist/core/runner/image.d.ts +17 -0
- package/dist/core/runner/image.js +29 -15
- package/dist/core/runner/memory-consolidation.d.ts +60 -0
- package/dist/core/runner/prepare-memory.d.ts +59 -0
- package/dist/core/runner/prepare-task.d.ts +1011 -2
- package/dist/core/runner/prepare-task.js +51 -14
- package/dist/core/runner/prompt-suggestions.d.ts +7 -0
- package/dist/core/runner/runtask.d.ts +304 -3
- package/dist/core/runner/runtask.js +17 -2
- package/dist/core/runner/session-file-state-replay.d.ts +49 -0
- package/dist/core/runner/session-rule-policy.d.ts +58 -0
- package/dist/core/runner/strict-output-schema.d.ts +18 -3
- package/dist/core/runner/synthetic-tools.d.ts +113 -0
- package/dist/core/runner/teardown-bounded.d.ts +34 -0
- package/dist/core/runner/tool-disclosure.d.ts +227 -0
- package/dist/core/runner/tool-output-projection.d.ts +6 -0
- package/dist/core/runner/turn-attachments.d.ts +634 -0
- package/dist/core/runner/usage-accounting.d.ts +32 -0
- package/dist/core/runtime.d.ts +9 -0
- package/dist/core/safe-notify.d.ts +64 -0
- package/dist/core/safety-axis-vocab.d.ts +23 -0
- package/dist/core/safety-merge-corpus.d.ts +37 -0
- package/dist/core/scheduler.d.ts +121 -0
- package/dist/core/secret-env.d.ts +32 -0
- package/dist/core/select-model.d.ts +15 -0
- package/dist/core/sensitive-path-policy.d.ts +42 -0
- package/dist/core/session-policy-store.d.ts +94 -0
- package/dist/core/session-reconcile.d.ts +80 -0
- package/dist/core/session-store.d.ts +85 -0
- package/dist/core/session.d.ts +153 -0
- package/dist/core/shared-memory/contract.d.ts +22 -0
- package/dist/core/shared-memory/normalize.d.ts +123 -2
- package/dist/core/shared-memory/tools.d.ts +14 -0
- package/dist/core/shared-memory/types.d.ts +105 -0
- package/dist/core/shutdown-debug.d.ts +6 -0
- package/dist/core/side-query.d.ts +38 -0
- package/dist/core/side-query.js +6 -1
- package/dist/core/skill-tool-specifier.d.ts +72 -0
- package/dist/core/skills-directory.d.ts +100 -1
- package/dist/core/spec-contract.d.ts +89 -0
- package/dist/core/store-contracts/background-agent-store-contract.d.ts +31 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +26 -0
- package/dist/core/store-contracts/contract-harness.d.ts +20 -0
- package/dist/core/store-contracts/contract-kit-version.d.ts +27 -0
- package/dist/core/store-contracts/file-snapshot-store-contract.d.ts +8 -0
- package/dist/core/store-contracts/mailbox-store-contract.d.ts +42 -0
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +13 -0
- package/dist/core/strategy-store.d.ts +37 -0
- package/dist/core/stub-env.d.ts +7 -0
- package/dist/core/surrogate-safe-slice.d.ts +35 -0
- package/dist/core/task-notification.d.ts +202 -0
- package/dist/core/task-outcome.d.ts +53 -0
- package/dist/core/task-registry-agent.d.ts +337 -1
- package/dist/core/task-registry-agent.js +2 -0
- package/dist/core/task-registry-monitor.d.ts +12 -0
- package/dist/core/task-registry-shared.d.ts +540 -0
- package/dist/core/task-registry.d.ts +343 -0
- package/dist/core/task-registry.js +13 -2
- package/dist/core/task-tool-shape.d.ts +44 -0
- package/dist/core/tighten-task-spec.d.ts +21 -0
- package/dist/core/tool-detach.d.ts +21 -0
- package/dist/core/tool-errors.d.ts +131 -0
- package/dist/core/tool-errors.js +4 -0
- package/dist/core/tool-name-aliases.d.ts +27 -0
- package/dist/core/tool-policy.d.ts +555 -0
- package/dist/core/tool-policy.js +3 -0
- package/dist/core/tool-result-budget.d.ts +32 -0
- package/dist/core/tool-result-store.d.ts +174 -1
- package/dist/core/tools.d.ts +45 -0
- package/dist/core/trace.d.ts +323 -0
- package/dist/core/types.d.ts +3859 -2
- package/dist/core/untrusted-egress.d.ts +8 -0
- package/dist/core/untrusted-text.d.ts +156 -0
- package/dist/core/usage-window-store.d.ts +95 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/warm-resume.d.ts +17 -0
- package/dist/core/wiring-manifest.d.ts +169 -0
- package/dist/core/with-retry.d.ts +24 -0
- package/dist/core/workflow-journal-store.d.ts +160 -0
- package/dist/core/workflow-run-store-contract.d.ts +25 -0
- package/dist/core/workflow-run-store.d.ts +119 -0
- package/dist/core/workflow-run-store.js +2 -0
- package/dist/engine/compaction/compaction.d.ts +256 -1
- package/dist/engine/compaction/utils.d.ts +94 -0
- package/dist/engine/execution-env/kill-tree.d.ts +29 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +94 -0
- package/dist/engine/harness/agent-harness.d.ts +116 -0
- package/dist/engine/harness/agent-harness.js +3 -14
- package/dist/engine/harness/messages.d.ts +15 -0
- package/dist/engine/harness/types.d.ts +464 -2
- package/dist/engine/llm/diagnostics.d.ts +4 -0
- package/dist/engine/llm/event-stream.d.ts +3 -0
- package/dist/engine/llm/index.d.ts +7 -0
- package/dist/engine/llm/types.d.ts +500 -3
- package/dist/engine/llm/validation.d.ts +3 -0
- package/dist/engine/loop/agent-loop.d.ts +87 -2
- package/dist/engine/loop/runtime-deps.d.ts +7 -0
- package/dist/engine/loop/types.d.ts +424 -0
- package/dist/engine/lsp/frame-decoder.d.ts +13 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts +107 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts +7 -0
- package/dist/engine/session/import-validate.d.ts +27 -0
- package/dist/engine/session/log-digest.d.ts +93 -0
- package/dist/engine/session/memory-repo.d.ts +6 -0
- package/dist/engine/session/memory-storage.d.ts +2 -0
- package/dist/engine/session/session.d.ts +75 -0
- package/dist/engine/session/storage-base.d.ts +8 -0
- package/dist/fixtures/index.d.ts +36 -0
- package/dist/index.d.ts +17 -2
- package/dist/index.js +1 -2
- package/dist/internal/harness-types.d.ts +6 -0
- package/dist/internal/harness.d.ts +11 -0
- package/dist/internal/llm.d.ts +6 -0
- package/dist/orchestration/builtin-workflows.d.ts +53 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts +19 -0
- package/dist/orchestration/goal.d.ts +57 -0
- package/dist/orchestration/goal.js +3 -0
- package/dist/orchestration/run-spec.d.ts +42 -0
- package/dist/orchestration/run-spec.js +4 -0
- package/dist/orchestration/run-workflow-tool.d.ts +169 -0
- package/dist/orchestration/workflow-governance.d.ts +61 -0
- package/dist/orchestration/workflow-meta.d.ts +28 -0
- package/dist/orchestration/workflow-observe.d.ts +60 -0
- package/dist/orchestration/workflow-primitives.d.ts +23 -1
- package/dist/orchestration/workflow-sandbox-conformance.d.ts +38 -0
- package/dist/orchestration/workflow-script-runner.d.ts +88 -0
- package/dist/orchestration/workflow-script-store.d.ts +98 -0
- package/dist/orchestration/workflow-size-guideline.d.ts +67 -0
- package/dist/orchestration/workflow-types.d.ts +169 -2
- package/dist/orchestration/workflow.d.ts +358 -0
- package/dist/orchestration/workflow.js +13 -2
- package/dist/prompt-assembly/artifact-store.d.ts +33 -0
- package/dist/prompt-assembly/artifact.d.ts +25 -0
- package/dist/prompt-assembly/assemble.d.ts +20 -0
- package/dist/prompt-assembly/composer.d.ts +29 -0
- package/dist/prompt-assembly/epoch.d.ts +55 -1
- package/dist/prompt-assembly/event-registry.d.ts +35 -0
- package/dist/prompt-assembly/explain.d.ts +12 -0
- package/dist/prompt-assembly/tool-catalog.d.ts +38 -0
- package/dist/prompt-assembly/turn-snapshot.d.ts +40 -0
- package/dist/prompt-assembly/types.d.ts +115 -0
- package/dist/prompts/coordinator.d.ts +27 -0
- package/dist/prompts/default.d.ts +539 -0
- package/dist/prompts/simple-sections.d.ts +45 -0
- package/dist/prompts/supervisor.d.ts +66 -0
- package/dist/scenarios/env.d.ts +28 -0
- package/dist/scenarios/full-body.d.ts +50 -0
- package/dist/scenarios/scenario-registry.d.ts +60 -0
- package/dist/scenarios/teacher-quickstart.d.ts +27 -0
- package/dist/server/http.d.ts +17 -0
- package/dist/stores/cc/lockfile.d.ts +6 -0
- package/dist/stores/cc/mailbox-store.d.ts +8 -0
- package/dist/stores/cc/roster-adapter.d.ts +4 -0
- package/dist/stores/cc/sidecar-transcript.d.ts +66 -0
- package/dist/stores/file/background-agent-store.d.ts +24 -0
- package/dist/stores/file/background-agent-store.js +2 -1
- package/dist/stores/file/checkpoint-store.d.ts +38 -0
- package/dist/stores/file/file-snapshot-store.d.ts +25 -0
- package/dist/stores/file/fs-atomic.d.ts +155 -0
- package/dist/stores/file/index.d.ts +89 -0
- package/dist/stores/file/mailbox-store.d.ts +36 -0
- package/dist/stores/file/mailbox-store.js +2 -0
- package/dist/stores/file/memory-store.d.ts +82 -0
- package/dist/stores/file/permission-rule-store.d.ts +79 -0
- package/dist/stores/file/session-policy-store.d.ts +28 -0
- package/dist/stores/file/session-store.d.ts +40 -0
- package/dist/stores/file/shared-ledger.d.ts +83 -0
- package/dist/stores/file/tool-result-store.d.ts +11 -0
- package/dist/stores/file/usage-window-store.d.ts +18 -0
- package/dist/stores/file/workflow-journal-store.d.ts +100 -0
- package/dist/stores/file/workflow-run-store.d.ts +11 -0
- package/dist/stores/file/workflow-run-store.js +2 -0
- package/dist/tools/fs/bash-readonly-classifier.d.ts +282 -0
- package/dist/tools/fs/encoding.d.ts +60 -0
- package/dist/tools/fs/fs-bash.d.ts +133 -0
- package/dist/tools/fs/fs-pdf.d.ts +28 -0
- package/dist/tools/fs/fs-search-tools.d.ts +5 -0
- package/dist/tools/fs/fs-shared.d.ts +360 -0
- package/dist/tools/fs/fs-write.d.ts +16 -0
- package/dist/tools/fs/gh-rate-limit.d.ts +22 -0
- package/dist/tools/fs/index.d.ts +79 -0
- package/dist/tools/fs/notebook.d.ts +56 -0
- package/dist/tools/fs/pdf.d.ts +70 -0
- package/dist/tools/fs/pdf.js +8 -2
- package/dist/tools/fs/repo-map.d.ts +10 -0
- package/dist/tools/fs/safety.d.ts +376 -0
- package/dist/tools/fs/search.d.ts +131 -0
- package/dist/tools/loop-tick.d.ts +24 -0
- package/dist/tools/monitor.d.ts +55 -0
- package/dist/tools/scheduler-tools.d.ts +51 -0
- package/dist/tools/sql-adapters.d.ts +18 -0
- package/dist/tools/sql.d.ts +25 -0
- package/dist/tools/task-list.d.ts +77 -0
- package/dist/tools/todo.d.ts +8 -0
- package/dist/tools/web.d.ts +184 -0
- package/dist/tools/web.js +32 -5
- package/dist/tools/worktree.d.ts +81 -0
- package/package.json +2 -2
- package/dist/tools/gitea-issue.d.ts +0 -13
- package/dist/tools/gitea-issue.js +0 -75
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
import type { TaskResult } from "../core/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* design/45 §11 Q6 — the **durable-suspend hard boundary** (v1). A `status:"suspended"` result is only
|
|
4
|
+
* safe to handle at the **top-level `runTask`** boundary: the orchestrators (cascade / verify / teacher /
|
|
5
|
+
* team) run their work as *nested* `runTask`s, and none of them can drive a resume from the inside. If a
|
|
6
|
+
* nested task suspends on a durable approval gate, the orchestrator must **fail fast** — not silently
|
|
7
|
+
* treat it as an ordinary failure (which would escalate/re-run side effects) and not release its pinned
|
|
8
|
+
* session (which would orphan the checkpoint). It maps `suspended → failed` + `errorCode:
|
|
9
|
+
* "unexpected.suspended"` and **passes the `checkpointToken`/`checkpointGate` straight through** (via the
|
|
10
|
+
* spread) so the top-level caller can still resume.
|
|
11
|
+
*
|
|
12
|
+
* The structural prevention is upstream — an orchestrator should run nested tasks under a **non-durable**
|
|
13
|
+
* approval policy (e.g. the verifier already forces `handsReadOnly` + headless auto-deny, DESIGN#5) so a
|
|
14
|
+
* suspension can't arise. This mapping is the defense-in-depth the council made a must-fix: "write it as
|
|
15
|
+
* a hard boundary, or a deployment wires durable-suspend into verify and produces silent errors."
|
|
16
|
+
*/
|
|
2
17
|
export declare const UNEXPECTED_SUSPENDED = "unexpected.suspended";
|
|
18
|
+
/** design/80 D-B: the `needs_review` durable-pause family (dry-run `needs_review` AND `plan_review`) hits the
|
|
19
|
+
* SAME nested hard boundary as `suspended` — a distinct code so a caller can tell a review pause from an approval. */
|
|
3
20
|
export declare const UNEXPECTED_NEEDS_REVIEW = "unexpected.needs_review";
|
|
21
|
+
/**
|
|
22
|
+
* design/80 D-B: the durable-pause hard boundary covers BOTH `suspended` (an approval gate) AND `needs_review`
|
|
23
|
+
* (a dry-run review OR a `plan_review` plan-gate). Both persist a checkpoint + PIN their session
|
|
24
|
+
* (prepare-task.ts), and a nested orchestrator can't drive their resume — so it must surface the
|
|
25
|
+
* `checkpointToken` and NOT release the pinned session (releasing it orphans the checkpoint). The `types.ts`
|
|
26
|
+
* TaskStatus doc mandates orchestrators map an unexpected `needs_review` the same hard-boundary way as `suspended`.
|
|
27
|
+
*/
|
|
4
28
|
export declare function isDurablePause(status: TaskResult["status"]): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* If `result` durably paused (suspended OR needs_review), return it mapped to a `failed` result carrying the
|
|
31
|
+
* checkpoint token; otherwise return it unchanged. The orchestrator should also **stop** (not escalate/re-run)
|
|
32
|
+
* and **not release** the session when this maps a pause — the checkpoint still references that session.
|
|
33
|
+
*/
|
|
5
34
|
export declare function mapNestedSuspend(result: TaskResult): TaskResult;
|
package/dist/agents/teacher.d.ts
CHANGED
|
@@ -1,23 +1,59 @@
|
|
|
1
1
|
import type { Runner } from "../core/runner/runtask.js";
|
|
2
2
|
import type { StrategyStore } from "../core/strategy-store.js";
|
|
3
3
|
import type { ModelRef, TaskResult, TaskSpec } from "../core/types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Teacher mode (escalation cascade): a cheap "student" does the work; a strong "teacher" is consulted
|
|
6
|
+
* only when the student is *detectably* stuck or wrong, then withdraws.
|
|
7
|
+
*
|
|
8
|
+
* APPLICABILITY — teacher mode assumes the task has a **decidable verify signal**: escalation only fires
|
|
9
|
+
* when we can tell the student is failing (Tier 0 same-tool/same-error stuck, Tier 1 rubric verifier on
|
|
10
|
+
* the final output, or a `blocked`/`failed` terminal). It pays off when "wrong" is observable.
|
|
11
|
+
*
|
|
12
|
+
* It does NOT fit **open-ended completeness/quality judgement** — e.g. code-review "find ALL the bugs",
|
|
13
|
+
* creative quality — because there is no oracle for *completeness*: the verifier can't know how many bugs
|
|
14
|
+
* the code has or which one was missed, so a student that finds one obvious issue passes the rubric while
|
|
15
|
+
* silently missing others, and the escalation machinery idles (verified in practice: 0 escalations, the
|
|
16
|
+
* verifier becomes pure added cost). Such tasks are solved by **breadth + adversarial debate** (a `team`
|
|
17
|
+
* council), not by **depth escalation** — the two are orthogonal. See design/12 §六 for the full reasoning.
|
|
18
|
+
*/
|
|
19
|
+
/** Default teacher (advisor) system prompt — returns ONLY structured JSON guidance. */
|
|
4
20
|
export declare const TEACHER_PROMPT = "You are an expert advisor to a less-capable \"student\" agent that got stuck.\nYou receive the task and the student's recent failed attempts. Your job is to help the student RECOVER,\nnot to do the work for it.\n\nReturn ONLY one valid JSON object (no markdown, no prose outside it):\n{\n \"strategy\": \"<general approach for this CLASS of problem, 1-2 sentences>\",\n \"correction\": \"<specifically what the student did wrong>\",\n \"nextStep\": \"<one concrete action the student should take now>\",\n \"takeover\": <true ONLY if the student is hopelessly stuck and you must do it yourself>,\n \"confidence\": <0=low .. 3=high, how sure you are this guidance is correct>\n}\n\nBe terse. Do NOT solve the whole task unless takeover=true. If you are unsure, set confidence=0 and takeover=false.";
|
|
5
21
|
export interface TeacherConfig {
|
|
22
|
+
/** Teacher model (overrides the `advisor` role). Default: resolve the `advisor` role. */
|
|
6
23
|
model?: ModelRef;
|
|
24
|
+
/** Cheap helper model for the stuck-monitor and verifier. Default: the student's own model. */
|
|
7
25
|
helperModel?: ModelRef;
|
|
26
|
+
/** Max escalations per run. Default 3. */
|
|
8
27
|
maxEscalations?: number;
|
|
28
|
+
/** Stop escalating once cumulative teacher tokens exceed this fraction of student tokens. Default 0.4. */
|
|
9
29
|
teacherSpendRatioCap?: number;
|
|
30
|
+
/** Consecutive same-tool failures before "suspected stuck". Default 3. */
|
|
10
31
|
stuckThreshold?: number;
|
|
32
|
+
/** Cumulative same-tool failures that force escalation regardless of the monitor. Default 5. */
|
|
11
33
|
stuckHardOverride?: number;
|
|
34
|
+
/** Second-guess a suspected stall with a cheap stuck-monitor call. Default true. */
|
|
12
35
|
useStuckMonitor?: boolean;
|
|
36
|
+
/** Run a rubric verifier on a completed student output. Default true. */
|
|
13
37
|
verifyOutput?: boolean;
|
|
38
|
+
/** After this many corrections fail, the teacher takes over instead of correcting again. Default 2. */
|
|
14
39
|
takeoverAfter?: number;
|
|
40
|
+
/** Prompt overrides (instruction text) for the teacher, the rubric verifier, and the stuck-monitor. */
|
|
15
41
|
prompts?: {
|
|
16
42
|
teacher?: string;
|
|
17
43
|
verifier?: string;
|
|
18
44
|
monitor?: string;
|
|
19
45
|
};
|
|
46
|
+
/** Per-escalation progress callback. */
|
|
20
47
|
onEscalation?: (e: EscalationRecord) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Decoupled escalation decision (Intent-monitor pattern, design/15). Called after a trigger fires
|
|
50
|
+
* and the cost guards pass, but before actually consulting the teacher. Return `false` to **skip**
|
|
51
|
+
* this escalation (the current — unresolved — result is returned). Default: always escalate. A
|
|
52
|
+
* throw fails open (escalates), so a broken policy can't strand the student; but a policy that
|
|
53
|
+
* always vetoes makes *you* responsible for the task ever resolving. (No internal timeout — wrap
|
|
54
|
+
* your own if the policy may hang.) Use it to plug in a separate monitor (a cheap model or rules)
|
|
55
|
+
* that decides whether escalating is worth it.
|
|
56
|
+
*/
|
|
21
57
|
escalationPolicy?: (info: {
|
|
22
58
|
trigger: EscalationTrigger;
|
|
23
59
|
attempt: number;
|
|
@@ -25,11 +61,29 @@ export interface TeacherConfig {
|
|
|
25
61
|
recent: string[];
|
|
26
62
|
verifyReason?: string;
|
|
27
63
|
}) => boolean | Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* Self-consistency for the rubric verifier (design/15). When ≥2, the verifier runs this many times
|
|
66
|
+
* (cheap helper model) and **majority-votes** pass/fail — less noisy than a single call, so the
|
|
67
|
+
* verify-fail escalation decision is better-calibrated. Default 1.
|
|
68
|
+
*/
|
|
28
69
|
verifierSamples?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Optional strategy repository (design/14). When set **with `scope`**, relevant past strategies are
|
|
72
|
+
* retrieved into the student's objective before the run, and the final escalation's strategy is
|
|
73
|
+
* stored on success — so similar problems can be solved without re-consulting the teacher.
|
|
74
|
+
*/
|
|
29
75
|
strategyStore?: StrategyStore;
|
|
76
|
+
/** Tenant/isolation scope for `strategyStore` (REQUIRED to enable it — strategies never cross scope). */
|
|
30
77
|
scope?: string;
|
|
78
|
+
/**
|
|
79
|
+
* How many strategies to retrieve. Default 3. Must be a non-negative integer, or `Infinity` for "no
|
|
80
|
+
* cap" — the store refuses anything else (ruled 2026-08-04) instead of folding it into 0, which used
|
|
81
|
+
* to make a fumbled value look identical to "this scope has no strategies".
|
|
82
|
+
*/
|
|
31
83
|
retrieveK?: number;
|
|
84
|
+
/** Minimum teacher confidence to store a strategy. Default 2. */
|
|
32
85
|
minConfidenceToStore?: number;
|
|
86
|
+
/** Inject retrieved strategies into the objective. Default true when a store+scope are set. */
|
|
33
87
|
injectStrategies?: boolean;
|
|
34
88
|
}
|
|
35
89
|
export type EscalationTrigger = "stuck" | "blocked" | "failed" | "verify-fail";
|
|
@@ -39,6 +93,7 @@ export interface TeacherAdvice {
|
|
|
39
93
|
nextStep?: string;
|
|
40
94
|
takeover: boolean;
|
|
41
95
|
confidence: number;
|
|
96
|
+
/** Raw text when the JSON could not be parsed. */
|
|
42
97
|
raw?: string;
|
|
43
98
|
}
|
|
44
99
|
export interface EscalationRecord {
|
|
@@ -48,13 +103,33 @@ export interface EscalationRecord {
|
|
|
48
103
|
tookOver: boolean;
|
|
49
104
|
}
|
|
50
105
|
export interface TeacherRunResult extends TaskResult {
|
|
106
|
+
/** Escalations that occurred during this run (empty if the student succeeded alone). */
|
|
51
107
|
escalations: EscalationRecord[];
|
|
108
|
+
/** Usage spent on the teacher (advisor), separate from the student's `stats` (which includes the
|
|
109
|
+
* cheap helper monitor/verifier calls). `tasks` = teacher runs (escalation asks + any takeover).
|
|
110
|
+
* `humanReview` = the HITL-gate burden of the teacher's runs (notably a takeover that hit an approval
|
|
111
|
+
* gate) — kept here, not in the student `stats`, since it is teacher work (mirrors the cost split). */
|
|
52
112
|
teacherStats: {
|
|
53
113
|
tokens: number;
|
|
54
114
|
tasks: number;
|
|
55
115
|
costMicroUsd?: number;
|
|
116
|
+
/** REF-D16: the CANONICAL burden shape from {@link TaskResult}, not a re-typed narrowing. The entries
|
|
117
|
+
* pushed here are the teacher runs' own `stats.humanReview.gates` verbatim, so a locally declared
|
|
118
|
+
* 3-field element (the pre-fix shape) was a type-face NARROWER than the values actually present —
|
|
119
|
+
* a consumer reading `gates[i].toolName` (design/99 MF-24) got a type error on a field that is there. */
|
|
56
120
|
humanReview?: NonNullable<TaskResult["stats"]["humanReview"]>;
|
|
57
121
|
};
|
|
58
122
|
}
|
|
123
|
+
/** Best-effort parse of the teacher's JSON advice; on failure, keep the raw text as a low-confidence correction. */
|
|
59
124
|
export declare function parseTeacherAdvice(text: string): TeacherAdvice;
|
|
125
|
+
/**
|
|
126
|
+
* Run a task with a cheap "student" model that escalates to a strong "teacher" (advisor) when it gets
|
|
127
|
+
* stuck or produces a wrong answer — the escalation cascade / teacher mode (design/13).
|
|
128
|
+
*
|
|
129
|
+
* The teacher runs in an isolated session (its dialogue is discarded; only its structured JSON advice
|
|
130
|
+
* is injected back into the student's session, so the student's prefix cache survives). Triggers:
|
|
131
|
+
* Tier 0 — repeated same-tool failures (aborts the stuck run early); Tier 1 — a rubric verifier on a
|
|
132
|
+
* completed output (catches "passes but semantically wrong"). Correction-then-takeover, with hard
|
|
133
|
+
* cost guards (escalation cap, teacher-spend ratio, bounded teacher turns).
|
|
134
|
+
*/
|
|
60
135
|
export declare function runWithTeacher(runner: Runner, studentSpec: TaskSpec, teacher?: TeacherConfig): Promise<TeacherRunResult>;
|
package/dist/agents/team.d.ts
CHANGED
|
@@ -1,19 +1,38 @@
|
|
|
1
1
|
import type { Runner } from "../core/runner/runtask.js";
|
|
2
2
|
import type { McpServerSpec, ModelRef, ModelRole, TaskResult, ToolSpec } from "../core/types.js";
|
|
3
3
|
export interface TeamMember {
|
|
4
|
+
/** The member's role / specialty, e.g. "安全评审" or "performance". */
|
|
4
5
|
role: string;
|
|
6
|
+
/** Optional per-member model (falls back to the team default). */
|
|
5
7
|
model?: ModelRef;
|
|
8
|
+
/** Optional per-member model **role** (when `model` is omitted) — for per-member cost tiering, e.g.
|
|
9
|
+
* a "researcher" on `"subagent"` (cheap) and a "critic" on `"default"`. Default `"team"`. */
|
|
6
10
|
modelRole?: ModelRole;
|
|
11
|
+
/** Optional persona / standing instructions for this member. */
|
|
7
12
|
systemPrompt?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Tools this member may use mid-debate to **ground or verify** a claim against the real artifacts
|
|
15
|
+
* (e.g. a read-only repo tool) instead of speculating — tool-augmented debate (the "Tool-MAD"
|
|
16
|
+
* pattern). Falls back to the team's shared {@link TeamDiscussionOptions.tools}. A member's turn
|
|
17
|
+
* becomes a full agent loop, so it is bounded by `limits` (and core's default turn cap).
|
|
18
|
+
*/
|
|
8
19
|
tools?: ToolSpec[];
|
|
20
|
+
/**
|
|
21
|
+
* Per-member tool allow/deny (design/38 1A), applied to this member's resolved tools (own or the
|
|
22
|
+
* team default): `allowTools` keeps only the named tools (`["*"]` = all), then `denyTools` removes.
|
|
23
|
+
* Lets a "researcher" be read-only and an "implementer" carry write tools without separate roles.
|
|
24
|
+
*/
|
|
9
25
|
allowTools?: string[];
|
|
10
26
|
denyTools?: string[];
|
|
27
|
+
/** Task-scoped MCP servers for this member; falls back to the team's shared `mcp`. */
|
|
11
28
|
mcp?: McpServerSpec[];
|
|
12
29
|
}
|
|
13
30
|
export interface TeamTurn {
|
|
14
31
|
round: number;
|
|
15
32
|
role: string;
|
|
16
33
|
text: string;
|
|
34
|
+
/** True when this member turn failed (retries exhausted). Surfaced in the result for visibility,
|
|
35
|
+
* but **excluded from every prompt** so an `[unavailable]` marker can't pollute the discussion. */
|
|
17
36
|
failed?: boolean;
|
|
18
37
|
}
|
|
19
38
|
export type TeamEvent = {
|
|
@@ -25,7 +44,10 @@ export type TeamEvent = {
|
|
|
25
44
|
round: number;
|
|
26
45
|
role: string;
|
|
27
46
|
text: string;
|
|
28
|
-
}
|
|
47
|
+
}
|
|
48
|
+
/** [571]③ budget axes: the cumulative team budget was exhausted after this member's turn settled —
|
|
49
|
+
* remaining rounds/members are skipped and the discussion goes straight to synthesis. */
|
|
50
|
+
| {
|
|
29
51
|
type: "budget_stop";
|
|
30
52
|
axis: "maxTokens" | "maxCostUsd";
|
|
31
53
|
round: number;
|
|
@@ -37,55 +59,152 @@ export type TeamEvent = {
|
|
|
37
59
|
};
|
|
38
60
|
export interface TeamDiscussionOptions {
|
|
39
61
|
runner: Runner;
|
|
62
|
+
/** Default model for members / synthesizer without their own. If omitted, members resolve the
|
|
63
|
+
* `team` role and the synthesizer the `synthesize` role (both fall back to `default`). */
|
|
40
64
|
model?: ModelRef;
|
|
65
|
+
/** The participants. */
|
|
41
66
|
members: TeamMember[];
|
|
67
|
+
/** What the team is discussing / deciding. */
|
|
42
68
|
topic: string;
|
|
69
|
+
/** Number of discussion rounds before synthesis. Default 2. */
|
|
43
70
|
rounds?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Cap on the shared transcript embedded in each prompt. When the running transcript exceeds
|
|
73
|
+
* this many estimated tokens, the oldest statements are summarized into a running summary
|
|
74
|
+
* (keeping prompts bounded over many rounds). Omit to disable.
|
|
75
|
+
*/
|
|
44
76
|
maxTranscriptTokens?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Default tools for members that don't declare their own — e.g. a read-only repo tool so the
|
|
79
|
+
* debate can **verify claims against the real artifacts** rather than argue over unseen code.
|
|
80
|
+
* Members without tools simply reason over the shared transcript (the convergence layer).
|
|
81
|
+
*/
|
|
45
82
|
tools?: ToolSpec[];
|
|
83
|
+
/** Default MCP servers for members without their own. */
|
|
46
84
|
mcp?: McpServerSpec[];
|
|
85
|
+
/**
|
|
86
|
+
* Who synthesizes the conclusion (default: a neutral facilitator on the default model). The
|
|
87
|
+
* synthesizer may carry its own `tools`/`mcp` to spot-check a disputed point before deciding; by
|
|
88
|
+
* default it has none (it converges over the transcript, it doesn't re-explore).
|
|
89
|
+
*/
|
|
47
90
|
synthesizer?: {
|
|
48
91
|
role?: string;
|
|
49
92
|
model?: ModelRef;
|
|
50
93
|
modelRole?: ModelRole;
|
|
51
94
|
systemPrompt?: string;
|
|
95
|
+
/** Tools specific to the synthesizer; does NOT fall back to the team-level `opts.tools`. */
|
|
52
96
|
tools?: ToolSpec[];
|
|
97
|
+
/** Per-agent tool allow/deny (design/38 1A), applied to the synthesizer's `tools`. */
|
|
53
98
|
allowTools?: string[];
|
|
54
99
|
denyTools?: string[];
|
|
55
100
|
mcp?: McpServerSpec[];
|
|
56
101
|
};
|
|
102
|
+
/** Progress callback. */
|
|
57
103
|
onEvent?: (e: TeamEvent) => void;
|
|
104
|
+
/**
|
|
105
|
+
* `maxWalltimeMs`/`maxTurns` are PER-RUN caps forwarded to every member/summary/synthesizer run.
|
|
106
|
+
*
|
|
107
|
+
* `maxTokens`/`maxCostUsd` ([571]③, CollabTemplate.budget mid-flight enforcement) are CUMULATIVE
|
|
108
|
+
* team budgets over member + summary + synthesizer spend (nested/delegated spend included, same
|
|
109
|
+
* coordinate as the `stats` totals). Enforcement is checked after each member turn settles and is
|
|
110
|
+
* booked — the crossing member is never killed in flight — and once a budget is exhausted
|
|
111
|
+
* (running total ≥ budget) no further member turn or round is dispatched. The transcript produced
|
|
112
|
+
* so far still goes through the NORMAL synthesis close-out (money already spent must yield a
|
|
113
|
+
* conclusion), so the synthesizer always runs; its spend is booked but not gated. Attribution
|
|
114
|
+
* lands in {@link TeamResult.budgetStop} plus a `budget_stop` event. `maxCostUsd` is compared in
|
|
115
|
+
* integer micro-USD (the engine's `stats.costMicroUsd` coordinate — no float equality); runs that
|
|
116
|
+
* report no cost (no `model.cost`/pricing) book 0 toward it. Both optional — omitted ⇒ prior
|
|
117
|
+
* behavior byte-for-byte. The budget axes are NOT forwarded to the nested member specs (a
|
|
118
|
+
* member's own per-task budget is `TaskSpec.maxTokens`/`maxCostUsd`, a different contract).
|
|
119
|
+
*/
|
|
58
120
|
limits?: {
|
|
59
121
|
maxWalltimeMs?: number;
|
|
60
122
|
maxTurns?: number;
|
|
61
123
|
maxTokens?: number;
|
|
62
124
|
maxCostUsd?: number;
|
|
63
125
|
};
|
|
126
|
+
/**
|
|
127
|
+
* External cancellation. When it aborts, in-flight member/synthesizer/summary runs are cancelled
|
|
128
|
+
* (each member turn is a nested `runTask` given this signal) — so a team abort cascades to members
|
|
129
|
+
* instead of each running to its own `timeoutSec`. Pass a parent tool's `ToolExecuteContext.signal`.
|
|
130
|
+
*/
|
|
64
131
|
signal?: AbortSignal;
|
|
132
|
+
/**
|
|
133
|
+
* Authenticated end-user {@link TaskSpec.principal} (design/62) propagated to every member / summarizer /
|
|
134
|
+
* synthesizer run, so their MCP tools carry the per-user identity. The orchestrator sets it from the trusted
|
|
135
|
+
* task context (a team is a control-plane composition, so it is set here rather than auto-inherited).
|
|
136
|
+
*/
|
|
65
137
|
principal?: string;
|
|
66
138
|
}
|
|
67
139
|
export interface TeamResult {
|
|
140
|
+
/**
|
|
141
|
+
* design/80 D-G data contract: the UNIFORM orchestrator-outcome projection. `team` was the only
|
|
142
|
+
* orchestrator exit whose result didn't expose `status`/`errorCode`/`result` (cascade/teacher/verify
|
|
143
|
+
* all `extends TaskResult`), forcing aggregators onto a special-case code path. These three projection
|
|
144
|
+
* fields close that gap so a consumer can read the SAME failure-class fields off every orchestrator exit
|
|
145
|
+
* (e.g. `errorClassOf(r.errorCode)`).
|
|
146
|
+
*
|
|
147
|
+
* This is a PROJECTION, not `extends TaskResult`: a team is a multi-member discussion with **no single**
|
|
148
|
+
* `taskId`/`sessionId`/`stats` shape (its `stats` is `{tokens,turns}` only, and the rich per-task
|
|
149
|
+
* `costMicroUsd`/`nested`/`humanReview` lines have no team-level meaning), so forcing those required
|
|
150
|
+
* TaskResult fields would invent semantically-wrong values. We project ONLY the three fields aggregators
|
|
151
|
+
* read. All are purely ADDITIVE — existing consumers (`conclusion`/`conclusionValid`/`transcript`/`stats`)
|
|
152
|
+
* are untouched.
|
|
153
|
+
*
|
|
154
|
+
* `status` is `"completed"` on a valid synthesis, `"failed"` when synthesis failed or a member durably
|
|
155
|
+
* paused; `result` mirrors `conclusion`; `errorCode` is set only on the durable-pause exit
|
|
156
|
+
* (`unexpected.suspended` / `unexpected.needs_review`, the same hard-boundary codes the other
|
|
157
|
+
* orchestrators use via {@link mapNestedSuspend}).
|
|
158
|
+
*/
|
|
68
159
|
status: "completed" | "failed";
|
|
160
|
+
/** Mirrors {@link conclusion} — the TaskResult-shaped `result` accessor for uniform aggregation. */
|
|
69
161
|
result: string;
|
|
162
|
+
/** The failure CLASS code (foldable with `errorClassOf`); set only when a member durably paused
|
|
163
|
+
* (`unexpected.suspended` / `unexpected.needs_review`). Undefined on a normal completion/synthesis fail. */
|
|
70
164
|
errorCode?: string;
|
|
71
165
|
conclusion: string;
|
|
166
|
+
/** False when the synthesizer failed and `conclusion` is an `[unavailable…]` marker, not a real
|
|
167
|
+
* conclusion — so callers can tell a junk conclusion from a legitimate one. */
|
|
72
168
|
conclusionValid: boolean;
|
|
73
169
|
transcript: TeamTurn[];
|
|
170
|
+
/** `costMicroUsd` ([571]③): cumulative team LLM spend in integer micro-USD (member + summary +
|
|
171
|
+
* synthesizer, nested included) — the same engine coordinate as `TaskResult.stats.costMicroUsd`.
|
|
172
|
+
* Always set (0 when no run reported cost); optional only for type-level back-compat. */
|
|
74
173
|
stats: {
|
|
75
174
|
tokens: number;
|
|
76
175
|
turns: number;
|
|
77
176
|
costMicroUsd?: number;
|
|
78
177
|
};
|
|
178
|
+
/**
|
|
179
|
+
* [571]③ budget-stop attribution: set when a cumulative budget axis was exhausted and the
|
|
180
|
+
* discussion stopped dispatching further members/rounds early. `round`/`role`/`memberIndex`
|
|
181
|
+
* identify the LAST member turn that ran (the one whose settled totals crossed the budget);
|
|
182
|
+
* everything scheduled after it was skipped and the transcript went straight to synthesis.
|
|
183
|
+
* NOT set when the budget was only crossed by the final scheduled member turn (nothing was
|
|
184
|
+
* skipped) or by the synthesizer itself — compare `stats` against the budget for that readout.
|
|
185
|
+
*/
|
|
79
186
|
budgetStop?: {
|
|
80
187
|
axis: "maxTokens" | "maxCostUsd";
|
|
81
188
|
round: number;
|
|
82
189
|
role: string;
|
|
83
190
|
memberIndex: number;
|
|
84
191
|
};
|
|
192
|
+
/** Number of member/synth turns that failed even after a retry (surfaced, not silent). */
|
|
85
193
|
failures: number;
|
|
194
|
+
/** How many times the shared transcript was summarized to stay under maxTranscriptTokens. */
|
|
86
195
|
transcriptCompactions: number;
|
|
196
|
+
/** design/80 D-B (codex review): set when a member durably PAUSED (suspended/needs_review) on a HITL gate —
|
|
197
|
+
* the discussion STOPS (no synthesis on a half-done team) and surfaces the resume capability so the caller
|
|
198
|
+
* can resume the paused member via the token, then re-run. `conclusionValid` is false in this case. */
|
|
87
199
|
durablePause?: boolean;
|
|
88
200
|
checkpointToken?: TaskResult["checkpointToken"];
|
|
89
201
|
checkpointGate?: TaskResult["checkpointGate"];
|
|
90
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Run a multi-round team discussion across several role-specialized agents, then synthesize a conclusion.
|
|
205
|
+
*
|
|
206
|
+
* Each member is shown the shared transcript (quoted as data) plus an explicit instruction block stating
|
|
207
|
+
* the discussion context, its role, and who else is present. Members are stateless per round (the shared
|
|
208
|
+
* transcript carries continuity), which keeps the orchestration simple and isolated.
|
|
209
|
+
*/
|
|
91
210
|
export declare function runTeamDiscussion(opts: TeamDiscussionOptions): Promise<TeamResult>;
|
|
@@ -1,3 +1,37 @@
|
|
|
1
1
|
import type { ToolSpec } from "../core/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Per-agent tool allow/deny (design/38 1A). Statically narrows a tool POOL to the subset a delegated
|
|
4
|
+
* sub-agent / team member may use — assembly-time filtering (the tool simply never appears in the
|
|
5
|
+
* child's `tools[]`), distinct from design/37's execution-time policy interception.
|
|
6
|
+
*
|
|
7
|
+
* Resolution order (council finding 6): `pool → ∩ allowTools → − denyTools`.
|
|
8
|
+
* - `allowTools` undefined OR contains `"*"` → start from the whole pool; otherwise keep only the named
|
|
9
|
+
* tools (an explicit allowlist; `[]` means "no work tools", which is intentional, not a mistake).
|
|
10
|
+
* - `denyTools` then removes named tools from whatever remains (a denied tool always loses).
|
|
11
|
+
*
|
|
12
|
+
* Allowlist is the security-recommended shape (finding 5): a denylist-only config silently exposes any
|
|
13
|
+
* newly-added sensitive tool to every agent. Names not present in the pool are ignored (no error) — an
|
|
14
|
+
* allow/deny list is a filter over what's available, not an assertion that those tools exist.
|
|
15
|
+
*
|
|
16
|
+
* [901] anchor ruling (dual-leg verified, adversarially reviewed): this spawn-time item-level filter IS
|
|
17
|
+
* the upstream shape for allow entries — CC's resolveAgentTools partitions unknown names into an
|
|
18
|
+
* `invalidTools` bucket nobody consumes at runtime (88 readable source), and a live 2.1.207 probe shows
|
|
19
|
+
* the agent stays listed/delegable with the unknown item silently dropped, zero warnings. The [876]
|
|
20
|
+
* "rejected at startup" posture this replaced had no verbatim anchor and did not survive verification.
|
|
21
|
+
* The asymmetric prepare-time fail-loud for `TaskSpec.agents` DENY entries is a deliberate sema
|
|
22
|
+
* extension (no upstream deny-list exists): an allow-typo silently narrows (safe direction), a
|
|
23
|
+
* deny-typo silently widens (unacceptable) — each face follows its own failure direction.
|
|
24
|
+
*
|
|
25
|
+
* Note: `"*"` in `allowTools` is the "allow all" sentinel, so a tool literally NAMED `"*"` cannot be
|
|
26
|
+
* the sole allowed tool via this path (tool names are conventionally identifiers, so this is moot).
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Membership check for ONE tool name under the same allow/deny semantics as {@link resolveToolSubset}
|
|
30
|
+
* (canonicalized both sides; `"*"` allow sentinel; deny wins). Used by the delegation tool to decide
|
|
31
|
+
* whether a chosen agent DEFINITION may re-delegate: a per-agent allow/deny that excludes the delegation
|
|
32
|
+
* tool's own name suppresses the nested delegation tool (CC 2.1.198 parity — Explore/Plan
|
|
33
|
+
* `disallowedTools` include Agent, pretty.js:409189/486948; CC filters the Agent tool like any other).
|
|
34
|
+
* The TOOL-level allow/deny deliberately keeps its old semantics (delegation governed by `maxDepth`).
|
|
35
|
+
*/
|
|
2
36
|
export declare function toolNameAllowed(name: string, allowTools?: ReadonlyArray<string>, denyTools?: ReadonlyArray<string>): boolean;
|
|
3
37
|
export declare function resolveToolSubset(pool: ReadonlyArray<ToolSpec>, allowTools?: ReadonlyArray<string>, denyTools?: ReadonlyArray<string>): ToolSpec[];
|