strands-darwin 0.0.35 → 0.0.36
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/README.md +20 -3
- package/README.zh-CN.md +20 -3
- package/dist/src/agent/prompt-cache.js +15 -2
- package/dist/src/agent/prompt-cache.js.map +1 -1
- package/dist/src/agent/rewind.d.ts +2 -0
- package/dist/src/agent/rewind.js +4 -1
- package/dist/src/agent/rewind.js.map +1 -1
- package/dist/src/agent/runtime.d.ts +64 -10
- package/dist/src/agent/runtime.js +192 -33
- package/dist/src/agent/runtime.js.map +1 -1
- package/dist/src/agent/session.d.ts +96 -4
- package/dist/src/agent/session.js +249 -9
- package/dist/src/agent/session.js.map +1 -1
- package/dist/src/agent/stream-idle.d.ts +16 -0
- package/dist/src/agent/stream-idle.js +127 -0
- package/dist/src/agent/stream-idle.js.map +1 -0
- package/dist/src/agent/working-context.d.ts +21 -1
- package/dist/src/agent/working-context.js +28 -1
- package/dist/src/agent/working-context.js.map +1 -1
- package/dist/src/agent/workspace-trust.d.ts +112 -0
- package/dist/src/agent/workspace-trust.js +207 -0
- package/dist/src/agent/workspace-trust.js.map +1 -0
- package/dist/src/agentcore/auto-policy.d.ts +7 -0
- package/dist/src/agentcore/auto-policy.js +50 -0
- package/dist/src/agentcore/auto-policy.js.map +1 -0
- package/dist/src/agentcore/auto-state.d.ts +43 -0
- package/dist/src/agentcore/auto-state.js +73 -0
- package/dist/src/agentcore/auto-state.js.map +1 -0
- package/dist/src/agentcore/cli.d.ts +2 -0
- package/dist/src/agentcore/cli.js +38 -0
- package/dist/src/agentcore/cli.js.map +1 -0
- package/dist/src/agentcore/config.d.ts +48 -0
- package/dist/src/agentcore/config.js +44 -0
- package/dist/src/agentcore/config.js.map +1 -0
- package/dist/src/agentcore/controller.d.ts +105 -0
- package/dist/src/agentcore/controller.js +979 -0
- package/dist/src/agentcore/controller.js.map +1 -0
- package/dist/src/agentcore/projection.d.ts +2 -0
- package/dist/src/agentcore/projection.js +8 -0
- package/dist/src/agentcore/projection.js.map +1 -0
- package/dist/src/agentcore/records.d.ts +41 -0
- package/dist/src/agentcore/records.js +149 -0
- package/dist/src/agentcore/records.js.map +1 -0
- package/dist/src/agentcore/state.d.ts +16 -0
- package/dist/src/agentcore/state.js +149 -0
- package/dist/src/agentcore/state.js.map +1 -0
- package/dist/src/agentcore/tools.d.ts +3 -0
- package/dist/src/agentcore/tools.js +11 -0
- package/dist/src/agentcore/tools.js.map +1 -0
- package/dist/src/agentcore/transport.d.ts +37 -0
- package/dist/src/agentcore/transport.js +242 -0
- package/dist/src/agentcore/transport.js.map +1 -0
- package/dist/src/agentcore/upload-projection.d.ts +208 -0
- package/dist/src/agentcore/upload-projection.js +823 -0
- package/dist/src/agentcore/upload-projection.js.map +1 -0
- package/dist/src/agents/child-recipe.js +4 -1
- package/dist/src/agents/child-recipe.js.map +1 -1
- package/dist/src/agents/loader.d.ts +12 -0
- package/dist/src/agents/loader.js +15 -1
- package/dist/src/agents/loader.js.map +1 -1
- package/dist/src/agents/subagent-tool.js +2 -4
- package/dist/src/agents/subagent-tool.js.map +1 -1
- package/dist/src/agents/workflow-tool.js +2 -4
- package/dist/src/agents/workflow-tool.js.map +1 -1
- package/dist/src/cli-doctor.js +7 -0
- package/dist/src/cli-doctor.js.map +1 -1
- package/dist/src/cli-import.d.ts +1 -0
- package/dist/src/cli-import.js +26 -0
- package/dist/src/cli-import.js.map +1 -0
- package/dist/src/cli-main.js +60 -10
- package/dist/src/cli-main.js.map +1 -1
- package/dist/src/cli-permissions.d.ts +2 -0
- package/dist/src/cli-permissions.js +20 -0
- package/dist/src/cli-permissions.js.map +1 -0
- package/dist/src/cli-sessions.js +6 -2
- package/dist/src/cli-sessions.js.map +1 -1
- package/dist/src/cli-usage.d.ts +9 -1
- package/dist/src/cli-usage.js +13 -0
- package/dist/src/cli-usage.js.map +1 -1
- package/dist/src/cli.js +19 -2
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/custom-commands.d.ts +1 -1
- package/dist/src/commands/custom-commands.js +14 -6
- package/dist/src/commands/custom-commands.js.map +1 -1
- package/dist/src/commands/review-command.d.ts +10 -0
- package/dist/src/commands/review-command.js +28 -0
- package/dist/src/commands/review-command.js.map +1 -0
- package/dist/src/config-file.d.ts +9 -0
- package/dist/src/config-file.js +82 -0
- package/dist/src/config-file.js.map +1 -0
- package/dist/src/config.d.ts +66 -5
- package/dist/src/config.js +126 -42
- package/dist/src/config.js.map +1 -1
- package/dist/src/dev-repl.js +17 -1
- package/dist/src/dev-repl.js.map +1 -1
- package/dist/src/headless-protocol.d.ts +24 -1
- package/dist/src/headless-protocol.js +18 -0
- package/dist/src/headless-protocol.js.map +1 -1
- package/dist/src/headless-runner.d.ts +8 -0
- package/dist/src/headless-runner.js +37 -1
- package/dist/src/headless-runner.js.map +1 -1
- package/dist/src/hooks/hook-process.js +7 -2
- package/dist/src/hooks/hook-process.js.map +1 -1
- package/dist/src/hooks/lifecycle-hooks.js +3 -1
- package/dist/src/hooks/lifecycle-hooks.js.map +1 -1
- package/dist/src/hooks/tool-hooks.js +3 -1
- package/dist/src/hooks/tool-hooks.js.map +1 -1
- package/dist/src/import-claude-files.d.ts +28 -0
- package/dist/src/import-claude-files.js +227 -0
- package/dist/src/import-claude-files.js.map +1 -0
- package/dist/src/import-claude-snippets.d.ts +2 -0
- package/dist/src/import-claude-snippets.js +105 -0
- package/dist/src/import-claude-snippets.js.map +1 -0
- package/dist/src/import-claude.d.ts +13 -0
- package/dist/src/import-claude.js +287 -0
- package/dist/src/import-claude.js.map +1 -0
- package/dist/src/mcp/registry.d.ts +57 -1
- package/dist/src/mcp/registry.js +78 -6
- package/dist/src/mcp/registry.js.map +1 -1
- package/dist/src/memory/command.d.ts +1 -1
- package/dist/src/memory/command.js +89 -4
- package/dist/src/memory/command.js.map +1 -1
- package/dist/src/memory/controller.d.ts +32 -0
- package/dist/src/memory/controller.js +39 -3
- package/dist/src/memory/controller.js.map +1 -1
- package/dist/src/memory/state.d.ts +6 -0
- package/dist/src/memory/state.js +6 -1
- package/dist/src/memory/state.js.map +1 -1
- package/dist/src/memory/store.d.ts +13 -0
- package/dist/src/memory/store.js +38 -2
- package/dist/src/memory/store.js.map +1 -1
- package/dist/src/memory/tools.d.ts +7 -0
- package/dist/src/memory/tools.js +12 -1
- package/dist/src/memory/tools.js.map +1 -1
- package/dist/src/paths.js +3 -0
- package/dist/src/paths.js.map +1 -1
- package/dist/src/permissions-test.d.ts +18 -0
- package/dist/src/permissions-test.js +207 -0
- package/dist/src/permissions-test.js.map +1 -0
- package/dist/src/pricing/model-prices.d.ts +8 -5
- package/dist/src/pricing/model-prices.js +30 -15
- package/dist/src/pricing/model-prices.js.map +1 -1
- package/dist/src/project-identity.d.ts +3 -0
- package/dist/src/project-identity.js +8 -0
- package/dist/src/project-identity.js.map +1 -0
- package/dist/src/project-overrides.d.ts +57 -0
- package/dist/src/project-overrides.js +79 -0
- package/dist/src/project-overrides.js.map +1 -0
- package/dist/src/skills/builtin/setup-agentcore-memory/SKILL.md +158 -0
- package/dist/src/skills/loader.d.ts +1 -1
- package/dist/src/skills/loader.js +4 -1
- package/dist/src/skills/loader.js.map +1 -1
- package/dist/src/tools/background-bash.d.ts +6 -0
- package/dist/src/tools/background-bash.js +26 -0
- package/dist/src/tools/background-bash.js.map +1 -1
- package/dist/src/tools/shell-env.d.ts +24 -0
- package/dist/src/tools/shell-env.js +34 -0
- package/dist/src/tools/shell-env.js.map +1 -1
- package/dist/src/trajectory/reader.d.ts +1 -1
- package/dist/src/trajectory/reader.js +23 -3
- package/dist/src/trajectory/reader.js.map +1 -1
- package/dist/src/trajectory/resume-recap.d.ts +11 -1
- package/dist/src/trajectory/resume-recap.js +10 -1
- package/dist/src/trajectory/resume-recap.js.map +1 -1
- package/dist/src/trajectory/rewind-history.d.ts +8 -0
- package/dist/src/trajectory/rewind-history.js +81 -0
- package/dist/src/trajectory/rewind-history.js.map +1 -0
- package/dist/src/tui/App.d.ts +5 -1
- package/dist/src/tui/App.js +284 -51
- package/dist/src/tui/App.js.map +1 -1
- package/dist/src/tui/InputBox.d.ts +1 -1
- package/dist/src/tui/InputBox.js +1 -1
- package/dist/src/tui/MessageList.js +1 -1
- package/dist/src/tui/MessageList.js.map +1 -1
- package/dist/src/tui/PermissionPrompt.js +5 -3
- package/dist/src/tui/PermissionPrompt.js.map +1 -1
- package/dist/src/tui/QueuedMessages.js +14 -8
- package/dist/src/tui/QueuedMessages.js.map +1 -1
- package/dist/src/tui/ToolCallPanel.js +2 -2
- package/dist/src/tui/ToolCallPanel.js.map +1 -1
- package/dist/src/tui/WorkspaceTrustPrompt.d.ts +8 -0
- package/dist/src/tui/WorkspaceTrustPrompt.js +37 -0
- package/dist/src/tui/WorkspaceTrustPrompt.js.map +1 -0
- package/dist/src/tui/draft-stash.d.ts +25 -0
- package/dist/src/tui/draft-stash.js +49 -0
- package/dist/src/tui/draft-stash.js.map +1 -0
- package/dist/src/tui/frame-budget.d.ts +2 -2
- package/dist/src/tui/frame-budget.js +3 -3
- package/dist/src/tui/frame-budget.js.map +1 -1
- package/dist/src/tui/help-format.d.ts +2 -2
- package/dist/src/tui/help-format.js +3 -3
- package/dist/src/tui/help-format.js.map +1 -1
- package/dist/src/tui/mcp-format.d.ts +9 -0
- package/dist/src/tui/mcp-format.js +5 -3
- package/dist/src/tui/mcp-format.js.map +1 -1
- package/dist/src/tui/permission-rule-preview.d.ts +23 -0
- package/dist/src/tui/permission-rule-preview.js +38 -0
- package/dist/src/tui/permission-rule-preview.js.map +1 -0
- package/dist/src/tui/prompt-editor.d.ts +12 -0
- package/dist/src/tui/prompt-editor.js +38 -28
- package/dist/src/tui/prompt-editor.js.map +1 -1
- package/dist/src/tui/prompt-history-search.js +3 -2
- package/dist/src/tui/prompt-history-search.js.map +1 -1
- package/dist/src/tui/prompt-queue.d.ts +4 -2
- package/dist/src/tui/prompt-queue.js +18 -3
- package/dist/src/tui/prompt-queue.js.map +1 -1
- package/dist/src/tui/rewind-search.js +4 -3
- package/dist/src/tui/rewind-search.js.map +1 -1
- package/dist/src/tui/search-preview.d.ts +2 -0
- package/dist/src/tui/search-preview.js +9 -0
- package/dist/src/tui/search-preview.js.map +1 -0
- package/dist/src/tui/shell-command.js +4 -1
- package/dist/src/tui/shell-command.js.map +1 -1
- package/dist/src/tui/spinner.d.ts +1 -0
- package/dist/src/tui/spinner.js +6 -0
- package/dist/src/tui/spinner.js.map +1 -0
- package/dist/src/tui/status-format.d.ts +9 -0
- package/dist/src/tui/status-format.js +37 -2
- package/dist/src/tui/status-format.js.map +1 -1
- package/dist/src/tui/subagent-format.js +6 -0
- package/dist/src/tui/subagent-format.js.map +1 -1
- package/dist/src/tui/task-format.d.ts +5 -0
- package/dist/src/tui/task-format.js +15 -0
- package/dist/src/tui/task-format.js.map +1 -1
- package/dist/src/tui/trust-format.d.ts +31 -0
- package/dist/src/tui/trust-format.js +102 -0
- package/dist/src/tui/trust-format.js.map +1 -0
- package/dist/src/tui/turn-state.d.ts +1 -0
- package/dist/src/tui/turn-state.js +2 -0
- package/dist/src/tui/turn-state.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type ProjectHookSourceInventory } from '../config.js';
|
|
2
|
+
import { type ProjectMcpServerInventory } from '../mcp/registry.js';
|
|
3
|
+
export declare const TRUST_FILENAME = "trust.json";
|
|
4
|
+
/** `~/.darwin/projects/<key>/trust.json` — user-owned, outside the repository. */
|
|
5
|
+
export declare function trustDecisionPath(projectRoot: string): string;
|
|
6
|
+
/** The stored decision, exactly the file's shape. */
|
|
7
|
+
export interface TrustDecision {
|
|
8
|
+
readonly trusted: boolean;
|
|
9
|
+
/** ISO 8601 instant of the decision, as written by darwin. */
|
|
10
|
+
readonly decidedAt: string;
|
|
11
|
+
}
|
|
12
|
+
/** Everything the checkout would arm, listed without arming any of it. */
|
|
13
|
+
export interface WorkspaceTrustInventory {
|
|
14
|
+
readonly hookSources: readonly ProjectHookSourceInventory[];
|
|
15
|
+
readonly mcpServers: readonly ProjectMcpServerInventory[];
|
|
16
|
+
readonly legacyRules: {
|
|
17
|
+
readonly file: string;
|
|
18
|
+
readonly allow: number;
|
|
19
|
+
readonly deny: number;
|
|
20
|
+
} | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Repository-supplied files the loaders could not parse, with their own message.
|
|
23
|
+
* Still executable configuration the user should see: a trusted project fails
|
|
24
|
+
* startup on them exactly as before (the loaders' `ConfigError`), an untrusted one
|
|
25
|
+
* never reads them.
|
|
26
|
+
*/
|
|
27
|
+
readonly problems: readonly {
|
|
28
|
+
readonly file: string;
|
|
29
|
+
readonly problem: string;
|
|
30
|
+
}[];
|
|
31
|
+
}
|
|
32
|
+
export type WorkspaceTrustState = 'trusted' | 'untrusted' | 'undecided';
|
|
33
|
+
/** The resolved gate input for one project, as the drivers hand it to the runtime. */
|
|
34
|
+
export interface WorkspaceTrust {
|
|
35
|
+
readonly state: WorkspaceTrustState;
|
|
36
|
+
readonly inventory: WorkspaceTrustInventory;
|
|
37
|
+
/** Set when the stored decision file exists but could not be read as one (bounded). */
|
|
38
|
+
readonly problem?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Nothing to consent to: the ordinary project, which sees nothing new. */
|
|
41
|
+
export declare function inventoryIsEmpty(inventory: WorkspaceTrustInventory): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the interactive driver must ask before creating the runtime: no stored
|
|
44
|
+
* decision and something to decide about. A stored answer — either one — is never
|
|
45
|
+
* asked again; an empty inventory is never asked at all.
|
|
46
|
+
*/
|
|
47
|
+
export declare function needsTrustPrompt(trust: WorkspaceTrust): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the runtime arms the repository-supplied layers. Only an explicit
|
|
50
|
+
* `trusted` answer does; `undecided` (headless, or the interactive Escape) holds them
|
|
51
|
+
* exactly like a stored refusal — the layers are the risk, and "no answer yet" is not
|
|
52
|
+
* consent.
|
|
53
|
+
*/
|
|
54
|
+
export declare function projectLayersArmed(trust: WorkspaceTrust): boolean;
|
|
55
|
+
/** Lists what the checkout would arm. Spawns nothing; a loader refusal becomes a `problems` row. */
|
|
56
|
+
export declare function inventoryWorkspace(projectRoot: string): Promise<WorkspaceTrustInventory>;
|
|
57
|
+
/**
|
|
58
|
+
* Reads the stored decision. Absent → `undefined`; present but not `{ trusted:
|
|
59
|
+
* boolean, decidedAt: string }` → `undefined` plus a bounded `problem`. Never throws:
|
|
60
|
+
* a decision file that cannot be read is "no decision", which holds the layers back
|
|
61
|
+
* and asks again — the safe direction.
|
|
62
|
+
*/
|
|
63
|
+
export declare function readTrustDecision(projectRoot: string): Promise<{
|
|
64
|
+
decision: TrustDecision | undefined;
|
|
65
|
+
problem?: string;
|
|
66
|
+
}>;
|
|
67
|
+
/** Stores the user's answer. Creates the user-owned project directory; never touches the repository. */
|
|
68
|
+
export declare function writeTrustDecision(projectRoot: string, trusted: boolean, now?: () => Date): Promise<TrustDecision>;
|
|
69
|
+
/** The inventory and the stored decision together — what every driver starts from. */
|
|
70
|
+
export declare function resolveWorkspaceTrust(projectRoot: string): Promise<WorkspaceTrust>;
|
|
71
|
+
/** A trust value with a different state and the same inventory — the interactive answer. */
|
|
72
|
+
export declare function withTrustState(trust: WorkspaceTrust, state: WorkspaceTrustState): WorkspaceTrust;
|
|
73
|
+
/**
|
|
74
|
+
* What the runtime reports about the decision it applied: the state and, when the
|
|
75
|
+
* layers were held, exactly which ones. Plain data for `runtime.info`, `/status`,
|
|
76
|
+
* `/mcp`, the transcript notice and the headless `trust:` line / `run.started.trust`.
|
|
77
|
+
* Empty `held` lists for a trusted project or an empty inventory.
|
|
78
|
+
*/
|
|
79
|
+
export interface WorkspaceTrustReport {
|
|
80
|
+
readonly state: WorkspaceTrustState;
|
|
81
|
+
readonly heldHookFiles: readonly string[];
|
|
82
|
+
readonly heldMcpServers: readonly {
|
|
83
|
+
readonly name: string;
|
|
84
|
+
readonly file: string;
|
|
85
|
+
}[];
|
|
86
|
+
readonly heldLegacyRules: {
|
|
87
|
+
readonly file: string;
|
|
88
|
+
readonly allow: number;
|
|
89
|
+
readonly deny: number;
|
|
90
|
+
} | undefined;
|
|
91
|
+
/** Repository-supplied files that were unreadable and therefore also held. */
|
|
92
|
+
readonly heldProblems: readonly {
|
|
93
|
+
readonly file: string;
|
|
94
|
+
readonly problem: string;
|
|
95
|
+
}[];
|
|
96
|
+
readonly problem?: string;
|
|
97
|
+
}
|
|
98
|
+
/** Projects the decision the runtime applied; a caller that passed no decision vouches for the checkout. */
|
|
99
|
+
export declare function workspaceTrustReport(trust: WorkspaceTrust | undefined): WorkspaceTrustReport;
|
|
100
|
+
/** Anything at all held back — the condition for the transcript notice and the headless line. */
|
|
101
|
+
export declare function holdsAnything(report: WorkspaceTrustReport): boolean;
|
|
102
|
+
/** Held items named per list before `… N more` — the `MAX_STATUS_NAMES` rule. */
|
|
103
|
+
export declare const MAX_HELD_NAMES = 6;
|
|
104
|
+
/**
|
|
105
|
+
* The held layers as bounded labels, project-relative: `hooks: .darwin/hooks.json`,
|
|
106
|
+
* `mcp: probe (.mcp.json)`, `rules: .darwin/config.json (2 allow, 1 deny)`,
|
|
107
|
+
* `unreadable: .agents/hooks.json`. One vocabulary for the transcript notice, the
|
|
108
|
+
* headless `trust:` line and `run.started.trust.held`, so the three cannot disagree.
|
|
109
|
+
*/
|
|
110
|
+
export declare function heldLabels(report: WorkspaceTrustReport, projectRoot: string): string[];
|
|
111
|
+
/** One sentence for the drivers: what was held and why, or nothing when nothing was. */
|
|
112
|
+
export declare function describeHeld(report: WorkspaceTrustReport, projectRoot: string): string | undefined;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace trust for repository-supplied executable configuration (SER-090).
|
|
3
|
+
*
|
|
4
|
+
* A checkout can carry three things darwin would otherwise *arm at launch* with no
|
|
5
|
+
* consent step: hook command files (`.darwin/hooks.json`, `.darwin/hooks/*.json`,
|
|
6
|
+
* `.agents/hooks.json`, `.agents/hooks/*.json`, the `hooks` key of a committed
|
|
7
|
+
* `.darwin/config.json`), MCP server definitions (`.darwin/mcp.json` or the root
|
|
8
|
+
* `.mcp.json`, every stdio entry a process spawned before the first prompt) and the
|
|
9
|
+
* legacy `permissionRules` fallback of a committed `.darwin/config.json`. This module
|
|
10
|
+
* is the pure half of the gate: it *inventories* what the checkout would arm without
|
|
11
|
+
* activating any of it, reads and writes the user-owned decision, and projects the
|
|
12
|
+
* result for every driver. It spawns nothing, registers nothing and never imports the
|
|
13
|
+
* runtime; the drivers (`cli-main.ts` interactive, `headless-runner.ts`, the dev REPL)
|
|
14
|
+
* resolve trust here first and hand the decision to `AgentRuntime.create`, which
|
|
15
|
+
* skips the held layers through `loadProjectPolicy`/`loadMcpClients` options.
|
|
16
|
+
*
|
|
17
|
+
* Two boundaries are load-bearing. The inventory shares one parse with activation:
|
|
18
|
+
* `inventoryProjectPolicy` runs the same `loadHookLayer` the policy loads from and
|
|
19
|
+
* `inventoryProjectMcpServers` the same declarative MCP reader, so a file listed here
|
|
20
|
+
* is exactly a file startup would arm and there is no second grammar to drift. And
|
|
21
|
+
* the decision lives in `~/.darwin/projects/<key>/trust.json` — `userProjectDir`, the
|
|
22
|
+
* store every other user-owned project fact uses — so a committed file inside the
|
|
23
|
+
* repository can never grant trust to itself: nothing under the project root is ever
|
|
24
|
+
* read as a decision. A malformed decision file reads as "no decision" with a bounded
|
|
25
|
+
* notice, never a crash and never a grant.
|
|
26
|
+
*
|
|
27
|
+
* User-global layers (`~/.darwin`, `~/.agents`), skills, custom commands and
|
|
28
|
+
* instruction files are prompt content or user-owned and are deliberately not part
|
|
29
|
+
* of the inventory: the gate is about what the *checkout* can execute or
|
|
30
|
+
* pre-authorize, not about what it can say.
|
|
31
|
+
*/
|
|
32
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
33
|
+
import path from 'node:path';
|
|
34
|
+
import { inventoryProjectPolicy, } from '../config.js';
|
|
35
|
+
import { inventoryProjectMcpServers } from '../mcp/registry.js';
|
|
36
|
+
import { userProjectDir } from '../paths.js';
|
|
37
|
+
export const TRUST_FILENAME = 'trust.json';
|
|
38
|
+
/** `~/.darwin/projects/<key>/trust.json` — user-owned, outside the repository. */
|
|
39
|
+
export function trustDecisionPath(projectRoot) {
|
|
40
|
+
return path.join(userProjectDir(projectRoot), TRUST_FILENAME);
|
|
41
|
+
}
|
|
42
|
+
/** Nothing to consent to: the ordinary project, which sees nothing new. */
|
|
43
|
+
export function inventoryIsEmpty(inventory) {
|
|
44
|
+
return (inventory.hookSources.length === 0 &&
|
|
45
|
+
inventory.mcpServers.length === 0 &&
|
|
46
|
+
inventory.legacyRules === undefined &&
|
|
47
|
+
inventory.problems.length === 0);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Whether the interactive driver must ask before creating the runtime: no stored
|
|
51
|
+
* decision and something to decide about. A stored answer — either one — is never
|
|
52
|
+
* asked again; an empty inventory is never asked at all.
|
|
53
|
+
*/
|
|
54
|
+
export function needsTrustPrompt(trust) {
|
|
55
|
+
return trust.state === 'undecided' && !inventoryIsEmpty(trust.inventory);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether the runtime arms the repository-supplied layers. Only an explicit
|
|
59
|
+
* `trusted` answer does; `undecided` (headless, or the interactive Escape) holds them
|
|
60
|
+
* exactly like a stored refusal — the layers are the risk, and "no answer yet" is not
|
|
61
|
+
* consent.
|
|
62
|
+
*/
|
|
63
|
+
export function projectLayersArmed(trust) {
|
|
64
|
+
return trust.state === 'trusted';
|
|
65
|
+
}
|
|
66
|
+
/** Lists what the checkout would arm. Spawns nothing; a loader refusal becomes a `problems` row. */
|
|
67
|
+
export async function inventoryWorkspace(projectRoot) {
|
|
68
|
+
const [policy, mcp] = await Promise.all([
|
|
69
|
+
inventoryProjectPolicy(projectRoot),
|
|
70
|
+
inventoryProjectMcpServers(projectRoot),
|
|
71
|
+
]);
|
|
72
|
+
return {
|
|
73
|
+
hookSources: policy.hookSources,
|
|
74
|
+
mcpServers: mcp.servers,
|
|
75
|
+
legacyRules: policy.legacyRules,
|
|
76
|
+
problems: [...policy.problems, ...(mcp.problem === undefined ? [] : [mcp.problem])],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Longest decision-file problem the notice carries; the rest is the file's own business. */
|
|
80
|
+
const MAX_PROBLEM_CODE_POINTS = 200;
|
|
81
|
+
/**
|
|
82
|
+
* Reads the stored decision. Absent → `undefined`; present but not `{ trusted:
|
|
83
|
+
* boolean, decidedAt: string }` → `undefined` plus a bounded `problem`. Never throws:
|
|
84
|
+
* a decision file that cannot be read is "no decision", which holds the layers back
|
|
85
|
+
* and asks again — the safe direction.
|
|
86
|
+
*/
|
|
87
|
+
export async function readTrustDecision(projectRoot) {
|
|
88
|
+
const file = trustDecisionPath(projectRoot);
|
|
89
|
+
let text;
|
|
90
|
+
try {
|
|
91
|
+
text = await readFile(file, 'utf8');
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (error?.code === 'ENOENT')
|
|
95
|
+
return { decision: undefined };
|
|
96
|
+
return { decision: undefined, problem: `${file} could not be read: ${bounded(describe(error))}` };
|
|
97
|
+
}
|
|
98
|
+
let parsed;
|
|
99
|
+
try {
|
|
100
|
+
parsed = JSON.parse(text);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
return { decision: undefined, problem: `${file} is not valid JSON: ${bounded(describe(error))}` };
|
|
104
|
+
}
|
|
105
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed) ||
|
|
106
|
+
typeof parsed['trusted'] !== 'boolean' ||
|
|
107
|
+
typeof parsed['decidedAt'] !== 'string') {
|
|
108
|
+
return {
|
|
109
|
+
decision: undefined,
|
|
110
|
+
problem: `${file} is not a trust decision (expected { "trusted": boolean, "decidedAt": string }); treated as undecided`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const record = parsed;
|
|
114
|
+
return { decision: { trusted: record['trusted'], decidedAt: record['decidedAt'] } };
|
|
115
|
+
}
|
|
116
|
+
/** Stores the user's answer. Creates the user-owned project directory; never touches the repository. */
|
|
117
|
+
export async function writeTrustDecision(projectRoot, trusted, now = () => new Date()) {
|
|
118
|
+
const decision = { trusted, decidedAt: now().toISOString() };
|
|
119
|
+
const file = trustDecisionPath(projectRoot);
|
|
120
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
121
|
+
await writeFile(file, `${JSON.stringify(decision, null, 2)}\n`, 'utf8');
|
|
122
|
+
return decision;
|
|
123
|
+
}
|
|
124
|
+
/** The inventory and the stored decision together — what every driver starts from. */
|
|
125
|
+
export async function resolveWorkspaceTrust(projectRoot) {
|
|
126
|
+
const [inventory, stored] = await Promise.all([inventoryWorkspace(projectRoot), readTrustDecision(projectRoot)]);
|
|
127
|
+
const state = stored.decision === undefined ? 'undecided' : stored.decision.trusted ? 'trusted' : 'untrusted';
|
|
128
|
+
return { state, inventory, ...(stored.problem === undefined ? {} : { problem: stored.problem }) };
|
|
129
|
+
}
|
|
130
|
+
/** A trust value with a different state and the same inventory — the interactive answer. */
|
|
131
|
+
export function withTrustState(trust, state) {
|
|
132
|
+
return { ...trust, state };
|
|
133
|
+
}
|
|
134
|
+
/** Projects the decision the runtime applied; a caller that passed no decision vouches for the checkout. */
|
|
135
|
+
export function workspaceTrustReport(trust) {
|
|
136
|
+
if (trust === undefined || projectLayersArmed(trust)) {
|
|
137
|
+
return {
|
|
138
|
+
state: 'trusted',
|
|
139
|
+
heldHookFiles: [],
|
|
140
|
+
heldMcpServers: [],
|
|
141
|
+
heldLegacyRules: undefined,
|
|
142
|
+
heldProblems: [],
|
|
143
|
+
...(trust?.problem === undefined ? {} : { problem: trust.problem }),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const { inventory } = trust;
|
|
147
|
+
return {
|
|
148
|
+
state: trust.state,
|
|
149
|
+
heldHookFiles: inventory.hookSources.map((source) => source.file),
|
|
150
|
+
heldMcpServers: inventory.mcpServers.map((server) => ({ name: server.name, file: server.file })),
|
|
151
|
+
heldLegacyRules: inventory.legacyRules,
|
|
152
|
+
heldProblems: inventory.problems,
|
|
153
|
+
...(trust.problem === undefined ? {} : { problem: trust.problem }),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/** Anything at all held back — the condition for the transcript notice and the headless line. */
|
|
157
|
+
export function holdsAnything(report) {
|
|
158
|
+
return (report.heldHookFiles.length > 0 ||
|
|
159
|
+
report.heldMcpServers.length > 0 ||
|
|
160
|
+
report.heldLegacyRules !== undefined ||
|
|
161
|
+
report.heldProblems.length > 0);
|
|
162
|
+
}
|
|
163
|
+
/** Held items named per list before `… N more` — the `MAX_STATUS_NAMES` rule. */
|
|
164
|
+
export const MAX_HELD_NAMES = 6;
|
|
165
|
+
/**
|
|
166
|
+
* The held layers as bounded labels, project-relative: `hooks: .darwin/hooks.json`,
|
|
167
|
+
* `mcp: probe (.mcp.json)`, `rules: .darwin/config.json (2 allow, 1 deny)`,
|
|
168
|
+
* `unreadable: .agents/hooks.json`. One vocabulary for the transcript notice, the
|
|
169
|
+
* headless `trust:` line and `run.started.trust.held`, so the three cannot disagree.
|
|
170
|
+
*/
|
|
171
|
+
export function heldLabels(report, projectRoot) {
|
|
172
|
+
const relative = (file) => {
|
|
173
|
+
const rel = path.relative(projectRoot, file);
|
|
174
|
+
return rel === '' || rel.startsWith('..') || path.isAbsolute(rel) ? file : rel;
|
|
175
|
+
};
|
|
176
|
+
const labels = [];
|
|
177
|
+
labels.push(...bound(report.heldHookFiles.map((file) => `hooks: ${relative(file)}`)));
|
|
178
|
+
labels.push(...bound(report.heldMcpServers.map((server) => `mcp: ${server.name} (${relative(server.file)})`)));
|
|
179
|
+
if (report.heldLegacyRules !== undefined) {
|
|
180
|
+
const { file, allow, deny } = report.heldLegacyRules;
|
|
181
|
+
labels.push(`rules: ${relative(file)} (${allow} allow, ${deny} deny)`);
|
|
182
|
+
}
|
|
183
|
+
labels.push(...bound(report.heldProblems.map((problem) => `unreadable: ${relative(problem.file)}`)));
|
|
184
|
+
return labels;
|
|
185
|
+
}
|
|
186
|
+
/** One sentence for the drivers: what was held and why, or nothing when nothing was. */
|
|
187
|
+
export function describeHeld(report, projectRoot) {
|
|
188
|
+
if (!holdsAnything(report))
|
|
189
|
+
return undefined;
|
|
190
|
+
const why = report.state === 'untrusted'
|
|
191
|
+
? 'project not trusted'
|
|
192
|
+
: 'project trust undecided';
|
|
193
|
+
return `${why} — held back: ${heldLabels(report, projectRoot).join(', ')}`;
|
|
194
|
+
}
|
|
195
|
+
function bound(items) {
|
|
196
|
+
if (items.length <= MAX_HELD_NAMES)
|
|
197
|
+
return [...items];
|
|
198
|
+
return [...items.slice(0, MAX_HELD_NAMES), `… ${items.length - MAX_HELD_NAMES} more`];
|
|
199
|
+
}
|
|
200
|
+
function bounded(text) {
|
|
201
|
+
const points = [...text];
|
|
202
|
+
return points.length <= MAX_PROBLEM_CODE_POINTS ? text : `${points.slice(0, MAX_PROBLEM_CODE_POINTS).join('')}…`;
|
|
203
|
+
}
|
|
204
|
+
function describe(error) {
|
|
205
|
+
return error instanceof Error ? error.message : String(error);
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=workspace-trust.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-trust.js","sourceRoot":"","sources":["../../../src/agent/workspace-trust.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,sBAAsB,GAEvB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,0BAA0B,EAAkC,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAE3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,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC;AACnH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type AgentCoreConfig } from './config.js';
|
|
2
|
+
import type { UploadTurn } from './upload-projection.js';
|
|
3
|
+
import type { TurnSettlement } from '../trajectory/writer.js';
|
|
4
|
+
/** Called only from the existing user TUI management authority. No model tool. */
|
|
5
|
+
export declare function persistUploadMode(root: string, expected: AgentCoreConfig, mode: 'auto' | 'manual', signal: AbortSignal): Promise<AgentCoreConfig>;
|
|
6
|
+
/** No success classifier, sensitivity filter, whitelist or omitted-percent veto. */
|
|
7
|
+
export declare function autoHoldReason(turn: UploadTurn, settlement: TurnSettlement): string | undefined;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { userDarwinDir } from '../paths.js';
|
|
4
|
+
import { projectIdentity } from '../project-identity.js';
|
|
5
|
+
import { updateConfigFile } from '../config-file.js';
|
|
6
|
+
import { cloudBinding, effectiveCloudPolicy, parseProjectOverrides } from '../project-overrides.js';
|
|
7
|
+
import { parseAgentCoreConfig } from './config.js';
|
|
8
|
+
/** Called only from the existing user TUI management authority. No model tool. */
|
|
9
|
+
export async function persistUploadMode(root, expected, mode, signal) {
|
|
10
|
+
return updateConfigFile(path.join(userDarwinDir(), 'config.json'), record => {
|
|
11
|
+
const global = parseAgentCoreConfig(record['agentCoreMemory']);
|
|
12
|
+
if (!global || cloudBinding(global, root) !== cloudBinding(expected, root))
|
|
13
|
+
throw new Error('Cloud scope changed; restart and re-confirm this project');
|
|
14
|
+
if (record['trajectory'] === false)
|
|
15
|
+
throw new Error('Uploads require trajectory recording');
|
|
16
|
+
const overrides = parseProjectOverrides(record['projectOverrides']) ?? Object.create(null);
|
|
17
|
+
const key = projectIdentity(root);
|
|
18
|
+
const prior = overrides[key] ?? {};
|
|
19
|
+
overrides[key] = { ...prior, agentCoreMemory: { ...prior.agentCoreMemory, upload: mode,
|
|
20
|
+
...(mode === 'auto' ? { authorization: { version: 2, epoch: randomUUID(), at: new Date().toISOString(), scope: cloudBinding(global, root), project: key } } : {}),
|
|
21
|
+
} };
|
|
22
|
+
if (mode === 'manual')
|
|
23
|
+
delete overrides[key].agentCoreMemory.authorization;
|
|
24
|
+
parseProjectOverrides(overrides); // Includes the bound after insertion.
|
|
25
|
+
record['projectOverrides'] = overrides;
|
|
26
|
+
return effectiveCloudPolicy(global, overrides, root);
|
|
27
|
+
}, signal);
|
|
28
|
+
}
|
|
29
|
+
/** No success classifier, sensitivity filter, whitelist or omitted-percent veto. */
|
|
30
|
+
export function autoHoldReason(turn, settlement) {
|
|
31
|
+
if (!settlement.durable)
|
|
32
|
+
return 'Turn close not durable';
|
|
33
|
+
if (settlement.failure || settlement.partial || settlement.stopReason !== 'endTurn')
|
|
34
|
+
return 'Cancelled, incomplete or provider-failed turn; manual review required';
|
|
35
|
+
if (turn.observerErrors || turn.unmatchedResults || turn.backgroundResultsDropped)
|
|
36
|
+
return 'Serious collection loss or ambiguous pairing; manual review required';
|
|
37
|
+
const integrity = turn.integrity;
|
|
38
|
+
if (integrity.identityAmbiguous || integrity.lateOriginsOverflow)
|
|
39
|
+
return 'Source identity/attribution loss; manual review required';
|
|
40
|
+
if (integrity.sourceUnavailable)
|
|
41
|
+
return 'Source collection unavailable; manual review required';
|
|
42
|
+
if (integrity.unresolvedResults || integrity.resultUnavailable)
|
|
43
|
+
return 'Missing or ambiguous results; manual review required';
|
|
44
|
+
if (!integrity.completedResults)
|
|
45
|
+
return 'No traceable action/result; management or acknowledgement-only turn';
|
|
46
|
+
if (!turn.goal.retainedBytes && !integrity.lateResults)
|
|
47
|
+
return 'No goal or traceable original late result';
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=auto-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-policy.js","sourceRoot":"","sources":["../../../src/agentcore/auto-policy.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAAE,oBAAoB,EAAwB,MAAM,aAAa,CAAC;AAIzE,kFAAkF;AAClF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAY,EAAE,QAAyB,EAAE,IAAuB,EAAE,MAAmB;IAC3H,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,EAAE;QAC1E,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAC/D,IAAI,CAAC,MAAM,IAAI,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QACxJ,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAC5F,MAAM,SAAS,GAAG,qBAAqB,CAAC,MAAM,CAAC,kBAAkB,CAAC,C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BAAgB,IAAI,IAAI,CAAC,wBAAwB;QAAE,OAAO,sEAAsE,CAAC;IACjK,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;IACjC,IAAI,SAAS,CAAC,iBAAiB,IAAI,SAAS,CAAC,mBAAmB;QAAE,OAAO,0DAA0D,CAAC;IACpI,IAAI,SAAS,CAAC,iBAAiB;QAAE,OAAO,uDAAuD,CAAC;IAChG,IAAI,SAAS,CAAC,iBAAiB,IAAI,SAAS,CAAC,iBAAiB;QAAE,OAAO,sDAAsD,CAAC;IAC9H,IAAI,CAAC,SAAS,CAAC,gBAAgB;QAAE,OAAO,qEAAqE,CAAC;IAC9G,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,SAAS,CAAC,WAAW;QAAE,OAAO,2CAA2C,CAAC;IAC3G,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type AgentCoreConfig } from './config.js';
|
|
3
|
+
export declare const MAX_OUTBOX_FILES = 32768;
|
|
4
|
+
export declare const MAX_OUTBOX_BODIES = 4096;
|
|
5
|
+
export declare const MAX_PENDING_BODIES = 512;
|
|
6
|
+
export declare const AUTO_RETENTION_MS: number;
|
|
7
|
+
export declare const autoProofSchema: z.ZodObject<{
|
|
8
|
+
version: z.ZodLiteral<1>;
|
|
9
|
+
hash: z.ZodString;
|
|
10
|
+
authorization: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
11
|
+
epoch: z.ZodString;
|
|
12
|
+
at: z.ZodString;
|
|
13
|
+
scope: z.ZodString;
|
|
14
|
+
version: z.ZodLiteral<1>;
|
|
15
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
16
|
+
epoch: z.ZodString;
|
|
17
|
+
at: z.ZodString;
|
|
18
|
+
scope: z.ZodString;
|
|
19
|
+
version: z.ZodLiteral<2>;
|
|
20
|
+
project: z.ZodString;
|
|
21
|
+
}, z.core.$strict>], "version">;
|
|
22
|
+
session: z.ZodString;
|
|
23
|
+
turn: z.ZodNumber;
|
|
24
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
export type AutoProof = z.infer<typeof autoProofSchema>;
|
|
27
|
+
export declare function receiptFile(directory: string, token: string): string;
|
|
28
|
+
export declare function tokenReceipt(directory: string, token: string): Promise<{
|
|
29
|
+
token: string;
|
|
30
|
+
disposition: "accepted" | "discarded";
|
|
31
|
+
at: string;
|
|
32
|
+
} | undefined>;
|
|
33
|
+
export declare function receiptCapacity(directory: string, tokens: string[]): Promise<void>;
|
|
34
|
+
export declare function saveReceipt(directory: string, token: string, disposition: 'accepted' | 'discarded', signal?: AbortSignal): Promise<void>;
|
|
35
|
+
export declare function quotaDirectory(root: string, config?: AgentCoreConfig): string;
|
|
36
|
+
export declare function quotaUsage(root: string, now?: Date, config?: AgentCoreConfig): Promise<{
|
|
37
|
+
day: string;
|
|
38
|
+
events: number;
|
|
39
|
+
bytes: number;
|
|
40
|
+
}>;
|
|
41
|
+
/** A reservation is one network attempt, not one extracted memory or unique event.
|
|
42
|
+
* Exact Smithy-serialized request body bytes; crashes/unknown acks consume budget. */
|
|
43
|
+
export declare function reserveQuota(root: string, config: AgentCoreConfig, bytes: number, signal: AbortSignal, now?: Date): Promise<void>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { userDarwinDir } from '../paths.js';
|
|
4
|
+
import { projectIdentity } from '../project-identity.js';
|
|
5
|
+
import { authorizationSchema } from './config.js';
|
|
6
|
+
import { readState, stateNames, withStateLock, writeState } from './state.js';
|
|
7
|
+
export const MAX_OUTBOX_FILES = 32768;
|
|
8
|
+
export const MAX_OUTBOX_BODIES = 4096;
|
|
9
|
+
export const MAX_PENDING_BODIES = 512;
|
|
10
|
+
export const AUTO_RETENTION_MS = 7 * 86400000;
|
|
11
|
+
const hash = z.string().regex(/^[a-f0-9]{64}$/);
|
|
12
|
+
export const autoProofSchema = z.object({ version: z.literal(1), hash, authorization: authorizationSchema,
|
|
13
|
+
session: z.string().max(128), turn: z.number().int().positive(), reason: z.string().max(240).optional(),
|
|
14
|
+
}).strict();
|
|
15
|
+
const receiptSchema = z.object({ token: hash, disposition: z.enum(['accepted', 'discarded']), at: z.string().datetime() }).strict();
|
|
16
|
+
export function receiptFile(directory, token) {
|
|
17
|
+
hash.parse(token);
|
|
18
|
+
return path.join(directory, 'receipts', token.slice(0, 2), `${token}.json`);
|
|
19
|
+
}
|
|
20
|
+
export async function tokenReceipt(directory, token) {
|
|
21
|
+
const value = await readState(receiptFile(directory, token));
|
|
22
|
+
if (value === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
const receipt = receiptSchema.parse(value);
|
|
25
|
+
if (receipt.token !== token)
|
|
26
|
+
throw new Error('Receipt identity mismatch');
|
|
27
|
+
return receipt;
|
|
28
|
+
}
|
|
29
|
+
export async function receiptCapacity(directory, tokens) {
|
|
30
|
+
const shards = new Map();
|
|
31
|
+
for (const token of tokens) {
|
|
32
|
+
const file = receiptFile(directory, token);
|
|
33
|
+
const shard = path.dirname(file);
|
|
34
|
+
if (!shards.has(shard))
|
|
35
|
+
shards.set(shard, new Set(await stateNames(shard, 4096)));
|
|
36
|
+
shards.get(shard).add(path.basename(file));
|
|
37
|
+
if (shards.get(shard).size > 4096)
|
|
38
|
+
throw new Error('Receipt partition full (4096); paused without removing data');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export async function saveReceipt(directory, token, disposition, signal) {
|
|
42
|
+
const prior = await tokenReceipt(directory, token);
|
|
43
|
+
if (prior) {
|
|
44
|
+
if (prior.disposition !== disposition)
|
|
45
|
+
throw new Error('Receipt disposition cannot change');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
await receiptCapacity(directory, [token]);
|
|
49
|
+
await writeState(receiptFile(directory, token), { token, disposition, at: new Date().toISOString() }, true, signal);
|
|
50
|
+
}
|
|
51
|
+
const quotaSchema = z.object({ day: z.string().regex(/^\d{4}-\d{2}-\d{2}$/), events: z.number().int().nonnegative().max(100000), bytes: z.number().int().nonnegative().max(107374182400) }).strict();
|
|
52
|
+
export function quotaDirectory(root, config) { return path.join(userDarwinDir(), 'agentcore', 'auto-quota', projectIdentity(root, config?.projectId)); }
|
|
53
|
+
export async function quotaUsage(root, now = new Date(), config) {
|
|
54
|
+
const day = now.toISOString().slice(0, 10);
|
|
55
|
+
const value = await readState(path.join(quotaDirectory(root, config), 'usage.json'));
|
|
56
|
+
const usage = value === undefined ? { day, events: 0, bytes: 0 } : quotaSchema.parse(value);
|
|
57
|
+
if (usage.day > day)
|
|
58
|
+
throw new Error('Quota clock moved backwards; auto paused');
|
|
59
|
+
return usage.day === day ? usage : { day, events: 0, bytes: 0 };
|
|
60
|
+
}
|
|
61
|
+
/** A reservation is one network attempt, not one extracted memory or unique event.
|
|
62
|
+
* Exact Smithy-serialized request body bytes; crashes/unknown acks consume budget. */
|
|
63
|
+
export async function reserveQuota(root, config, bytes, signal, now = new Date()) {
|
|
64
|
+
if (!Number.isSafeInteger(bytes) || bytes < 1 || bytes > 262144)
|
|
65
|
+
throw new Error('Invalid wire request size');
|
|
66
|
+
await withStateLock(quotaDirectory(root, config), async () => {
|
|
67
|
+
const usage = await quotaUsage(root, now, config);
|
|
68
|
+
if (usage.events + 1 > config.autoDailyEvents || usage.bytes + bytes > config.autoDailyBytes)
|
|
69
|
+
throw new Error('Auto paused: daily budget exhausted; pending retained until next ordinary authorized activity');
|
|
70
|
+
await writeState(path.join(quotaDirectory(root, config), 'usage.json'), { day: usage.day, events: usage.events + 1, bytes: usage.bytes + bytes }, false, signal);
|
|
71
|
+
}, signal);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=auto-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-state.js","sourceRoot":"","sources":["../../../src/agentcore/auto-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9G,MAAM,aAAa,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,KAAK,IAAI,EAAE;QAC3D,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QAClD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,eAAe,IAAI,KAAK,CAAC,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC,cAAc;YAAE,MAAM,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAAC;QAC/M,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACnK,CAAC,EAAE,MAAM,CAAC,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { loadConfig } from '../config.js';
|
|
3
|
+
import { AGENTCORE_CLI_PATH_NOTICE } from './config.js';
|
|
4
|
+
import { CloudMemory, cloudReadArguments, CLOUD_READ_USAGE } from './controller.js';
|
|
5
|
+
/** Routed before runtime imports: SDK bash installs exit(0) signal handlers. */
|
|
6
|
+
export async function runCloudMemoryCli(root, args) {
|
|
7
|
+
const input = args.join(' ');
|
|
8
|
+
if (!cloudReadArguments(input)) {
|
|
9
|
+
process.stderr.write(`Headless mutations unavailable; use user-submitted TUI management. ${CLOUD_READ_USAGE}\n`);
|
|
10
|
+
process.exitCode = 1;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const config = await loadConfig(root);
|
|
14
|
+
if (config.agentCoreMemory === undefined) {
|
|
15
|
+
process.stdout.write('AgentCore: disabled (local project memory unchanged)\n');
|
|
16
|
+
if (input !== '' && input !== 'status')
|
|
17
|
+
process.exitCode = 1;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (config.agentCoreMemory.cliPath !== undefined)
|
|
21
|
+
process.stderr.write(`${AGENTCORE_CLI_PATH_NOTICE}\n`);
|
|
22
|
+
const memory = new CloudMemory(config.agentCoreMemory, root, 'management');
|
|
23
|
+
const cancel = () => { process.exitCode = 1; memory.cancel(); };
|
|
24
|
+
process.once('SIGINT', cancel);
|
|
25
|
+
process.once('SIGTERM', cancel);
|
|
26
|
+
try {
|
|
27
|
+
const result = await memory.commandResult(input);
|
|
28
|
+
process.stdout.write(`${result.text}\n`);
|
|
29
|
+
if (!result.ok)
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
process.off('SIGINT', cancel);
|
|
34
|
+
process.off('SIGTERM', cancel);
|
|
35
|
+
await memory.close();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/agentcore/cli.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEpF,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAY,EAAE,IAAc;IAClE,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,s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C,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC9D,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const agentCoreConfigSchema: z.ZodObject<{
|
|
3
|
+
enabled: z.ZodLiteral<true>;
|
|
4
|
+
region: z.ZodString;
|
|
5
|
+
memoryId: z.ZodString;
|
|
6
|
+
episodicStrategyId: z.ZodString;
|
|
7
|
+
preferenceStrategyId: z.ZodString;
|
|
8
|
+
actorId: z.ZodString;
|
|
9
|
+
projectId: z.ZodOptional<z.ZodString>;
|
|
10
|
+
cliPath: z.ZodOptional<z.ZodString>;
|
|
11
|
+
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
12
|
+
preferences: z.ZodDefault<z.ZodBoolean>;
|
|
13
|
+
upload: z.ZodDefault<z.ZodEnum<{
|
|
14
|
+
auto: "auto";
|
|
15
|
+
manual: "manual";
|
|
16
|
+
off: "off";
|
|
17
|
+
}>>;
|
|
18
|
+
autoDailyEvents: z.ZodDefault<z.ZodNumber>;
|
|
19
|
+
autoDailyBytes: z.ZodDefault<z.ZodNumber>;
|
|
20
|
+
}, z.core.$strict>;
|
|
21
|
+
export declare const authorizationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
22
|
+
epoch: z.ZodString;
|
|
23
|
+
at: z.ZodString;
|
|
24
|
+
scope: z.ZodString;
|
|
25
|
+
version: z.ZodLiteral<1>;
|
|
26
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
27
|
+
epoch: z.ZodString;
|
|
28
|
+
at: z.ZodString;
|
|
29
|
+
scope: z.ZodString;
|
|
30
|
+
version: z.ZodLiteral<2>;
|
|
31
|
+
project: z.ZodString;
|
|
32
|
+
}, z.core.$strict>], "version">;
|
|
33
|
+
export type AutoAuthorization = z.infer<typeof authorizationSchema>;
|
|
34
|
+
export type AgentCoreConfig = z.infer<typeof agentCoreConfigSchema> & {
|
|
35
|
+
/** Derived only by the project registry; never accepted at the global root. */
|
|
36
|
+
authorization?: AutoAuthorization;
|
|
37
|
+
autoProblem?: string;
|
|
38
|
+
projectOverride?: boolean;
|
|
39
|
+
};
|
|
40
|
+
export declare const AGENTCORE_CLI_PATH_NOTICE = "agentCoreMemory.cliPath is deprecated and ignored; runtime memory uses the AWS SDK. Remove cliPath from your private config; retain all other memory settings.";
|
|
41
|
+
export declare function parseAgentCoreConfig(value: unknown): AgentCoreConfig | undefined;
|
|
42
|
+
export declare function scopeFor(config: AgentCoreConfig, root: string): {
|
|
43
|
+
projectId: string;
|
|
44
|
+
project: string;
|
|
45
|
+
episodes: string;
|
|
46
|
+
preferences: string;
|
|
47
|
+
};
|
|
48
|
+
export declare function digest(value: unknown): string;
|