@inhuman.tools/turn 0.0.0-stage → 0.1.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/LICENSE.md +7 -0
- package/dist/agent-calls/acceptance.d.ts +12 -0
- package/dist/agent-calls/acceptance.d.ts.map +1 -0
- package/dist/agent-calls/acceptance.js +64 -0
- package/dist/agent-calls/acceptance.js.map +1 -0
- package/dist/agent-calls/callbacks.d.ts +14 -0
- package/dist/agent-calls/callbacks.d.ts.map +1 -0
- package/dist/agent-calls/callbacks.js +59 -0
- package/dist/agent-calls/callbacks.js.map +1 -0
- package/dist/agent-calls/delivery.d.ts +7 -0
- package/dist/agent-calls/delivery.d.ts.map +1 -0
- package/dist/agent-calls/delivery.js +16 -0
- package/dist/agent-calls/delivery.js.map +1 -0
- package/dist/agent-calls/index.d.ts +7 -0
- package/dist/agent-calls/index.d.ts.map +1 -0
- package/dist/agent-calls/index.js +6 -0
- package/dist/agent-calls/index.js.map +1 -0
- package/dist/agent-calls/operator.d.ts +21 -0
- package/dist/agent-calls/operator.d.ts.map +1 -0
- package/dist/agent-calls/operator.js +78 -0
- package/dist/agent-calls/operator.js.map +1 -0
- package/dist/agent-calls/runtime.d.ts +99 -0
- package/dist/agent-calls/runtime.d.ts.map +1 -0
- package/dist/agent-calls/runtime.js +245 -0
- package/dist/agent-calls/runtime.js.map +1 -0
- package/dist/agent-calls/types.d.ts +31 -0
- package/dist/agent-calls/types.d.ts.map +1 -0
- package/dist/agent-calls/types.js +2 -0
- package/dist/agent-calls/types.js.map +1 -0
- package/dist/context/compact-floors.d.ts +43 -0
- package/dist/context/compact-floors.d.ts.map +1 -0
- package/dist/context/compact-floors.js +52 -0
- package/dist/context/compact-floors.js.map +1 -0
- package/dist/context/compact.d.ts +42 -0
- package/dist/context/compact.d.ts.map +1 -0
- package/dist/context/compact.js +155 -0
- package/dist/context/compact.js.map +1 -0
- package/dist/context/delivery.d.ts +13 -0
- package/dist/context/delivery.d.ts.map +1 -0
- package/dist/context/delivery.js +6 -0
- package/dist/context/delivery.js.map +1 -0
- package/dist/context/history.d.ts +66 -0
- package/dist/context/history.d.ts.map +1 -0
- package/dist/context/history.js +573 -0
- package/dist/context/history.js.map +1 -0
- package/dist/context/index.d.ts +10 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +10 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/observations.d.ts +7 -0
- package/dist/context/observations.d.ts.map +1 -0
- package/dist/context/observations.js +11 -0
- package/dist/context/observations.js.map +1 -0
- package/dist/context/retention/defaults.d.ts +10 -0
- package/dist/context/retention/defaults.d.ts.map +1 -0
- package/dist/context/retention/defaults.js +47 -0
- package/dist/context/retention/defaults.js.map +1 -0
- package/dist/context/retention/index.d.ts +14 -0
- package/dist/context/retention/index.d.ts.map +1 -0
- package/dist/context/retention/index.js +21 -0
- package/dist/context/retention/index.js.map +1 -0
- package/dist/context/retention/narrow.d.ts +22 -0
- package/dist/context/retention/narrow.d.ts.map +1 -0
- package/dist/context/retention/narrow.js +140 -0
- package/dist/context/retention/narrow.js.map +1 -0
- package/dist/context/retention/render.d.ts +37 -0
- package/dist/context/retention/render.d.ts.map +1 -0
- package/dist/context/retention/render.js +149 -0
- package/dist/context/retention/render.js.map +1 -0
- package/dist/context/retention/resolve.d.ts +51 -0
- package/dist/context/retention/resolve.d.ts.map +1 -0
- package/dist/context/retention/resolve.js +254 -0
- package/dist/context/retention/resolve.js.map +1 -0
- package/dist/context/retention/schema.d.ts +345 -0
- package/dist/context/retention/schema.d.ts.map +1 -0
- package/dist/context/retention/schema.js +149 -0
- package/dist/context/retention/schema.js.map +1 -0
- package/dist/context/retention/stamp.d.ts +25 -0
- package/dist/context/retention/stamp.d.ts.map +1 -0
- package/dist/context/retention/stamp.js +103 -0
- package/dist/context/retention/stamp.js.map +1 -0
- package/dist/context/retention/step.d.ts +33 -0
- package/dist/context/retention/step.d.ts.map +1 -0
- package/dist/context/retention/step.js +74 -0
- package/dist/context/retention/step.js.map +1 -0
- package/dist/context/retention/view.d.ts +57 -0
- package/dist/context/retention/view.d.ts.map +1 -0
- package/dist/context/retention/view.js +121 -0
- package/dist/context/retention/view.js.map +1 -0
- package/dist/context/squeeze.d.ts +45 -0
- package/dist/context/squeeze.d.ts.map +1 -0
- package/dist/context/squeeze.js +182 -0
- package/dist/context/squeeze.js.map +1 -0
- package/dist/context/tools.d.ts +16 -0
- package/dist/context/tools.d.ts.map +1 -0
- package/dist/context/tools.js +73 -0
- package/dist/context/tools.js.map +1 -0
- package/dist/context/transcript.d.ts +151 -0
- package/dist/context/transcript.d.ts.map +1 -0
- package/dist/context/transcript.js +659 -0
- package/dist/context/transcript.js.map +1 -0
- package/dist/policy-processor/bypass.d.ts +95 -0
- package/dist/policy-processor/bypass.d.ts.map +1 -0
- package/dist/policy-processor/bypass.js +188 -0
- package/dist/policy-processor/bypass.js.map +1 -0
- package/dist/policy-processor/classifier.d.ts +47 -0
- package/dist/policy-processor/classifier.d.ts.map +1 -0
- package/dist/policy-processor/classifier.js +671 -0
- package/dist/policy-processor/classifier.js.map +1 -0
- package/dist/policy-processor/cluster.d.ts +7 -0
- package/dist/policy-processor/cluster.d.ts.map +1 -0
- package/dist/policy-processor/cluster.js +32 -0
- package/dist/policy-processor/cluster.js.map +1 -0
- package/dist/policy-processor/evidence.d.ts +26 -0
- package/dist/policy-processor/evidence.d.ts.map +1 -0
- package/dist/policy-processor/evidence.js +204 -0
- package/dist/policy-processor/evidence.js.map +1 -0
- package/dist/policy-processor/explain.d.ts +59 -0
- package/dist/policy-processor/explain.d.ts.map +1 -0
- package/dist/policy-processor/explain.js +224 -0
- package/dist/policy-processor/explain.js.map +1 -0
- package/dist/policy-processor/index.d.ts +6 -0
- package/dist/policy-processor/index.d.ts.map +1 -0
- package/dist/policy-processor/index.js +6 -0
- package/dist/policy-processor/index.js.map +1 -0
- package/dist/policy-processor/license.d.ts +23 -0
- package/dist/policy-processor/license.d.ts.map +1 -0
- package/dist/policy-processor/license.js +47 -0
- package/dist/policy-processor/license.js.map +1 -0
- package/dist/policy-processor/peel-cwd.d.ts +2 -0
- package/dist/policy-processor/peel-cwd.d.ts.map +1 -0
- package/dist/policy-processor/peel-cwd.js +2 -0
- package/dist/policy-processor/peel-cwd.js.map +1 -0
- package/dist/policy-processor/real-path.d.ts +7 -0
- package/dist/policy-processor/real-path.d.ts.map +1 -0
- package/dist/policy-processor/real-path.js +42 -0
- package/dist/policy-processor/real-path.js.map +1 -0
- package/dist/policy-processor/scope.d.ts +111 -0
- package/dist/policy-processor/scope.d.ts.map +1 -0
- package/dist/policy-processor/scope.js +629 -0
- package/dist/policy-processor/scope.js.map +1 -0
- package/dist/policy-processor/self-protect.d.ts +10 -0
- package/dist/policy-processor/self-protect.d.ts.map +1 -0
- package/dist/policy-processor/self-protect.js +48 -0
- package/dist/policy-processor/self-protect.js.map +1 -0
- package/dist/policy-processor/soft-deny.d.ts +75 -0
- package/dist/policy-processor/soft-deny.d.ts.map +1 -0
- package/dist/policy-processor/soft-deny.js +185 -0
- package/dist/policy-processor/soft-deny.js.map +1 -0
- package/dist/policy-processor/unattended-guard.d.ts +28 -0
- package/dist/policy-processor/unattended-guard.d.ts.map +1 -0
- package/dist/policy-processor/unattended-guard.js +145 -0
- package/dist/policy-processor/unattended-guard.js.map +1 -0
- package/dist/session/cancel.d.ts +14 -0
- package/dist/session/cancel.d.ts.map +1 -0
- package/dist/session/cancel.js +32 -0
- package/dist/session/cancel.js.map +1 -0
- package/dist/session/commands.d.ts +41 -0
- package/dist/session/commands.d.ts.map +1 -0
- package/dist/session/commands.js +241 -0
- package/dist/session/commands.js.map +1 -0
- package/dist/session/compact-actor.d.ts +23 -0
- package/dist/session/compact-actor.d.ts.map +1 -0
- package/dist/session/compact-actor.js +91 -0
- package/dist/session/compact-actor.js.map +1 -0
- package/dist/session/compact-env.d.ts +54 -0
- package/dist/session/compact-env.d.ts.map +1 -0
- package/dist/session/compact-env.js +345 -0
- package/dist/session/compact-env.js.map +1 -0
- package/dist/session/compact.d.ts +42 -0
- package/dist/session/compact.d.ts.map +1 -0
- package/dist/session/compact.js +68 -0
- package/dist/session/compact.js.map +1 -0
- package/dist/session/index.d.ts +9 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +8 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/park.d.ts +16 -0
- package/dist/session/park.d.ts.map +1 -0
- package/dist/session/park.js +73 -0
- package/dist/session/park.js.map +1 -0
- package/dist/session/side-channel-reminder.d.ts +41 -0
- package/dist/session/side-channel-reminder.d.ts.map +1 -0
- package/dist/session/side-channel-reminder.js +132 -0
- package/dist/session/side-channel-reminder.js.map +1 -0
- package/dist/session/types.d.ts +44 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +2 -0
- package/dist/session/types.js.map +1 -0
- package/dist/tool-catalog/catalog.d.ts +77 -0
- package/dist/tool-catalog/catalog.d.ts.map +1 -0
- package/dist/tool-catalog/catalog.js +380 -0
- package/dist/tool-catalog/catalog.js.map +1 -0
- package/dist/tool-catalog/index.d.ts +4 -0
- package/dist/tool-catalog/index.d.ts.map +1 -0
- package/dist/tool-catalog/index.js +3 -0
- package/dist/tool-catalog/index.js.map +1 -0
- package/dist/tool-catalog/recipes.d.ts +36 -0
- package/dist/tool-catalog/recipes.d.ts.map +1 -0
- package/dist/tool-catalog/recipes.js +121 -0
- package/dist/tool-catalog/recipes.js.map +1 -0
- package/dist/tool-catalog/types.d.ts +103 -0
- package/dist/tool-catalog/types.d.ts.map +1 -0
- package/dist/tool-catalog/types.js +5 -0
- package/dist/tool-catalog/types.js.map +1 -0
- package/dist/tool-runtime/approval/approved.d.ts +13 -0
- package/dist/tool-runtime/approval/approved.d.ts.map +1 -0
- package/dist/tool-runtime/approval/approved.js +20 -0
- package/dist/tool-runtime/approval/approved.js.map +1 -0
- package/dist/tool-runtime/approval/dist.d.ts +6 -0
- package/dist/tool-runtime/approval/dist.d.ts.map +1 -0
- package/dist/tool-runtime/approval/dist.js +28 -0
- package/dist/tool-runtime/approval/dist.js.map +1 -0
- package/dist/tool-runtime/approval/inbound.d.ts +7 -0
- package/dist/tool-runtime/approval/inbound.d.ts.map +1 -0
- package/dist/tool-runtime/approval/inbound.js +48 -0
- package/dist/tool-runtime/approval/inbound.js.map +1 -0
- package/dist/tool-runtime/approval/unattended.d.ts +8 -0
- package/dist/tool-runtime/approval/unattended.d.ts.map +1 -0
- package/dist/tool-runtime/approval/unattended.js +23 -0
- package/dist/tool-runtime/approval/unattended.js.map +1 -0
- package/dist/tool-runtime/blob-port.d.ts +46 -0
- package/dist/tool-runtime/blob-port.d.ts.map +1 -0
- package/dist/tool-runtime/blob-port.js +47 -0
- package/dist/tool-runtime/blob-port.js.map +1 -0
- package/dist/tool-runtime/extra-root.d.ts +3 -0
- package/dist/tool-runtime/extra-root.d.ts.map +1 -0
- package/dist/tool-runtime/extra-root.js +14 -0
- package/dist/tool-runtime/extra-root.js.map +1 -0
- package/dist/tool-runtime/handler.d.ts +29 -0
- package/dist/tool-runtime/handler.d.ts.map +1 -0
- package/dist/tool-runtime/handler.js +460 -0
- package/dist/tool-runtime/handler.js.map +1 -0
- package/dist/tool-runtime/index.d.ts +14 -0
- package/dist/tool-runtime/index.d.ts.map +1 -0
- package/dist/tool-runtime/index.js +14 -0
- package/dist/tool-runtime/index.js.map +1 -0
- package/dist/tool-runtime/peel.d.ts +19 -0
- package/dist/tool-runtime/peel.d.ts.map +1 -0
- package/dist/tool-runtime/peel.js +74 -0
- package/dist/tool-runtime/peel.js.map +1 -0
- package/dist/tool-runtime/plugin-context.d.ts +13 -0
- package/dist/tool-runtime/plugin-context.d.ts.map +1 -0
- package/dist/tool-runtime/plugin-context.js +55 -0
- package/dist/tool-runtime/plugin-context.js.map +1 -0
- package/dist/tool-runtime/recall.d.ts +18 -0
- package/dist/tool-runtime/recall.d.ts.map +1 -0
- package/dist/tool-runtime/recall.js +100 -0
- package/dist/tool-runtime/recall.js.map +1 -0
- package/dist/tool-runtime/run-system-tool.d.ts +13 -0
- package/dist/tool-runtime/run-system-tool.d.ts.map +1 -0
- package/dist/tool-runtime/run-system-tool.js +230 -0
- package/dist/tool-runtime/run-system-tool.js.map +1 -0
- package/dist/tool-runtime/tool-error.d.ts +6 -0
- package/dist/tool-runtime/tool-error.d.ts.map +1 -0
- package/dist/tool-runtime/tool-error.js +6 -0
- package/dist/tool-runtime/tool-error.js.map +1 -0
- package/dist/tool-runtime/worker-tools.d.ts +8 -0
- package/dist/tool-runtime/worker-tools.d.ts.map +1 -0
- package/dist/tool-runtime/worker-tools.js +65 -0
- package/dist/tool-runtime/worker-tools.js.map +1 -0
- package/dist/tool-runtime/write-admit.d.ts +21 -0
- package/dist/tool-runtime/write-admit.d.ts.map +1 -0
- package/dist/tool-runtime/write-admit.js +89 -0
- package/dist/tool-runtime/write-admit.js.map +1 -0
- package/package.json +114 -3
- package/policy/auto-mode-ask.scm +201 -0
- package/policy/bypass-detect.prompt +55 -0
- package/policy/classifier-bash-incomplete.prompt +46 -0
- package/policy/classifier-bash.prompt +45 -0
- package/policy/classifier-mcp.prompt +45 -0
- package/policy/classifier-read.prompt +44 -0
- package/policy/classifier-write-outside.prompt +46 -0
- package/policy/classifier-write-risky.prompt +45 -0
- package/policy/classifier-write-workspace.prompt +46 -0
- package/policy/classifier-write.prompt +45 -0
- package/policy/soft-deny-round1.prompt +51 -0
- package/policy/soft-deny-round2.prompt +60 -0
- package/src/agent-calls/acceptance.ts +71 -0
- package/src/agent-calls/callbacks.ts +75 -0
- package/src/agent-calls/delivery.ts +15 -0
- package/src/agent-calls/index.ts +16 -0
- package/src/agent-calls/operator.ts +99 -0
- package/src/agent-calls/runtime.ts +310 -0
- package/src/agent-calls/types.ts +33 -0
- package/src/context/compact-floors.ts +76 -0
- package/src/context/compact.ts +176 -0
- package/src/context/delivery.ts +15 -0
- package/src/context/history.ts +725 -0
- package/src/context/index.ts +35 -0
- package/src/context/observations.ts +13 -0
- package/src/context/retention/defaults.ts +58 -0
- package/src/context/retention/index.ts +45 -0
- package/src/context/retention/narrow.ts +123 -0
- package/src/context/retention/render.ts +177 -0
- package/src/context/retention/resolve.ts +306 -0
- package/src/context/retention/schema.ts +173 -0
- package/src/context/retention/stamp.ts +121 -0
- package/src/context/retention/step.ts +85 -0
- package/src/context/retention/view.ts +161 -0
- package/src/context/squeeze.ts +218 -0
- package/src/context/tools.ts +92 -0
- package/src/context/transcript.ts +705 -0
- package/src/policy-processor/README.md +43 -0
- package/src/policy-processor/bypass.ts +246 -0
- package/src/policy-processor/classifier.ts +711 -0
- package/src/policy-processor/cluster.ts +31 -0
- package/src/policy-processor/evidence.ts +214 -0
- package/src/policy-processor/explain.ts +310 -0
- package/src/policy-processor/index.ts +6 -0
- package/src/policy-processor/license.ts +45 -0
- package/src/policy-processor/peel-cwd.ts +1 -0
- package/src/policy-processor/real-path.ts +41 -0
- package/src/policy-processor/scope.ts +655 -0
- package/src/policy-processor/self-protect.ts +46 -0
- package/src/policy-processor/soft-deny.ts +225 -0
- package/src/policy-processor/unattended-guard.ts +158 -0
- package/src/session/cancel.ts +34 -0
- package/src/session/commands.ts +292 -0
- package/src/session/compact-actor.ts +132 -0
- package/src/session/compact-env.ts +539 -0
- package/src/session/compact.ts +95 -0
- package/src/session/index.ts +18 -0
- package/src/session/park.ts +73 -0
- package/src/session/side-channel-reminder.ts +148 -0
- package/src/session/types.ts +50 -0
- package/src/tool-catalog/catalog.ts +282 -0
- package/src/tool-catalog/index.ts +26 -0
- package/src/tool-catalog/recipes.ts +154 -0
- package/src/tool-catalog/types.ts +110 -0
- package/src/tool-runtime/approval/approved.ts +20 -0
- package/src/tool-runtime/approval/dist.ts +29 -0
- package/src/tool-runtime/approval/inbound.ts +50 -0
- package/src/tool-runtime/approval/unattended.ts +24 -0
- package/src/tool-runtime/blob-port.ts +64 -0
- package/src/tool-runtime/extra-root.ts +16 -0
- package/src/tool-runtime/handler.ts +576 -0
- package/src/tool-runtime/index.ts +21 -0
- package/src/tool-runtime/peel.ts +91 -0
- package/src/tool-runtime/plugin-context.ts +68 -0
- package/src/tool-runtime/recall.ts +104 -0
- package/src/tool-runtime/run-system-tool.ts +273 -0
- package/src/tool-runtime/tool-error.ts +6 -0
- package/src/tool-runtime/worker-tools.ts +76 -0
- package/src/tool-runtime/write-admit.ts +90 -0
- package/README.md +0 -3
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `contextRetention` — JSON-configurable tail retention. Nothing here deletes
|
|
3
|
+
* graph state: a rule decides what a projected item leaves behind once its
|
|
4
|
+
* horizon has passed. Design: `tail-retention-design.md` §3–§4.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
export declare const RETENTION_KINDS: readonly ["image.user", "image.tool", "tool.read", "tool.search", "tool.shell", "tool.write", "tool.args.write", "tool.web.search", "tool.web.fetch", "tool.mcp", "tool.program", "tool.agent", "tool.comm", "tool.other", "thinking", "steer", "approval-note", "notification", "system-note", "error"];
|
|
8
|
+
export type RetentionKind = (typeof RETENTION_KINDS)[number];
|
|
9
|
+
/** Authored by the user. Untrusted layers (project, agent, tool) cannot shorten these. */
|
|
10
|
+
export declare const USER_AUTHORED_KINDS: ReadonlySet<string>;
|
|
11
|
+
/** Kinds whose item is a tool result row. `leave: "none"` is not allowed: every tool_call needs a tool row. */
|
|
12
|
+
export declare const NONE_FORBIDDEN_KINDS: ReadonlySet<string>;
|
|
13
|
+
export declare const horizonSchema: z.ZodUnion<readonly [z.ZodEnum<{
|
|
14
|
+
round: "round";
|
|
15
|
+
turn: "turn";
|
|
16
|
+
compaction: "compaction";
|
|
17
|
+
forever: "forever";
|
|
18
|
+
}>, z.ZodObject<{
|
|
19
|
+
rounds: z.ZodNumber;
|
|
20
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
21
|
+
turns: z.ZodNumber;
|
|
22
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
23
|
+
newest: z.ZodNumber;
|
|
24
|
+
}, z.core.$strict>]>;
|
|
25
|
+
export type Horizon = z.output<typeof horizonSchema>;
|
|
26
|
+
export declare const leaveSchema: z.ZodUnion<readonly [z.ZodEnum<{
|
|
27
|
+
none: "none";
|
|
28
|
+
stub: "stub";
|
|
29
|
+
summary: "summary";
|
|
30
|
+
}>, z.ZodObject<{
|
|
31
|
+
head: z.ZodNumber;
|
|
32
|
+
}, z.core.$strict>]>;
|
|
33
|
+
export type Leave = z.output<typeof leaveSchema>;
|
|
34
|
+
export declare const ruleSchema: z.ZodObject<{
|
|
35
|
+
keep: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodEnum<{
|
|
36
|
+
round: "round";
|
|
37
|
+
turn: "turn";
|
|
38
|
+
compaction: "compaction";
|
|
39
|
+
forever: "forever";
|
|
40
|
+
}>, z.ZodObject<{
|
|
41
|
+
rounds: z.ZodNumber;
|
|
42
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
43
|
+
turns: z.ZodNumber;
|
|
44
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
45
|
+
newest: z.ZodNumber;
|
|
46
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
|
|
47
|
+
round: "round";
|
|
48
|
+
turn: "turn";
|
|
49
|
+
compaction: "compaction";
|
|
50
|
+
forever: "forever";
|
|
51
|
+
}>, z.ZodObject<{
|
|
52
|
+
rounds: z.ZodNumber;
|
|
53
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
54
|
+
turns: z.ZodNumber;
|
|
55
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
56
|
+
newest: z.ZodNumber;
|
|
57
|
+
}, z.core.$strict>]>>]>>;
|
|
58
|
+
leave: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
59
|
+
none: "none";
|
|
60
|
+
stub: "stub";
|
|
61
|
+
summary: "summary";
|
|
62
|
+
}>, z.ZodObject<{
|
|
63
|
+
head: z.ZodNumber;
|
|
64
|
+
}, z.core.$strict>]>>;
|
|
65
|
+
minChars: z.ZodOptional<z.ZodNumber>;
|
|
66
|
+
onError: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
67
|
+
keep: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodEnum<{
|
|
68
|
+
round: "round";
|
|
69
|
+
turn: "turn";
|
|
70
|
+
compaction: "compaction";
|
|
71
|
+
forever: "forever";
|
|
72
|
+
}>, z.ZodObject<{
|
|
73
|
+
rounds: z.ZodNumber;
|
|
74
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
75
|
+
turns: z.ZodNumber;
|
|
76
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
77
|
+
newest: z.ZodNumber;
|
|
78
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
|
|
79
|
+
round: "round";
|
|
80
|
+
turn: "turn";
|
|
81
|
+
compaction: "compaction";
|
|
82
|
+
forever: "forever";
|
|
83
|
+
}>, z.ZodObject<{
|
|
84
|
+
rounds: z.ZodNumber;
|
|
85
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
86
|
+
turns: z.ZodNumber;
|
|
87
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
88
|
+
newest: z.ZodNumber;
|
|
89
|
+
}, z.core.$strict>]>>]>;
|
|
90
|
+
leave: z.ZodUnion<readonly [z.ZodEnum<{
|
|
91
|
+
none: "none";
|
|
92
|
+
stub: "stub";
|
|
93
|
+
summary: "summary";
|
|
94
|
+
}>, z.ZodObject<{
|
|
95
|
+
head: z.ZodNumber;
|
|
96
|
+
}, z.core.$strict>]>;
|
|
97
|
+
}, z.core.$strip>>>;
|
|
98
|
+
}, z.core.$strip>;
|
|
99
|
+
export type RuleInput = z.output<typeof ruleSchema>;
|
|
100
|
+
export declare const stepSchema: z.ZodObject<{
|
|
101
|
+
turnBoundary: z.ZodDefault<z.ZodBoolean>;
|
|
102
|
+
everyRounds: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
103
|
+
minFreedTokens: z.ZodDefault<z.ZodNumber>;
|
|
104
|
+
whenCacheCold: z.ZodDefault<z.ZodBoolean>;
|
|
105
|
+
atCompaction: z.ZodDefault<z.ZodLiteral<true>>;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
export type StepConfig = z.output<typeof stepSchema>;
|
|
108
|
+
export declare const contextRetentionSchema: z.ZodObject<{
|
|
109
|
+
version: z.ZodDefault<z.ZodLiteral<1>>;
|
|
110
|
+
defaults: z.ZodPrefault<z.ZodObject<{
|
|
111
|
+
minChars: z.ZodDefault<z.ZodNumber>;
|
|
112
|
+
}, z.core.$strip>>;
|
|
113
|
+
step: z.ZodPrefault<z.ZodObject<{
|
|
114
|
+
turnBoundary: z.ZodDefault<z.ZodBoolean>;
|
|
115
|
+
everyRounds: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
|
|
116
|
+
minFreedTokens: z.ZodDefault<z.ZodNumber>;
|
|
117
|
+
whenCacheCold: z.ZodDefault<z.ZodBoolean>;
|
|
118
|
+
atCompaction: z.ZodDefault<z.ZodLiteral<true>>;
|
|
119
|
+
}, z.core.$strip>>;
|
|
120
|
+
kinds: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
121
|
+
keep: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodEnum<{
|
|
122
|
+
round: "round";
|
|
123
|
+
turn: "turn";
|
|
124
|
+
compaction: "compaction";
|
|
125
|
+
forever: "forever";
|
|
126
|
+
}>, z.ZodObject<{
|
|
127
|
+
rounds: z.ZodNumber;
|
|
128
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
129
|
+
turns: z.ZodNumber;
|
|
130
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
131
|
+
newest: z.ZodNumber;
|
|
132
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
|
|
133
|
+
round: "round";
|
|
134
|
+
turn: "turn";
|
|
135
|
+
compaction: "compaction";
|
|
136
|
+
forever: "forever";
|
|
137
|
+
}>, z.ZodObject<{
|
|
138
|
+
rounds: z.ZodNumber;
|
|
139
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
140
|
+
turns: z.ZodNumber;
|
|
141
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
142
|
+
newest: z.ZodNumber;
|
|
143
|
+
}, z.core.$strict>]>>]>>;
|
|
144
|
+
leave: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
145
|
+
none: "none";
|
|
146
|
+
stub: "stub";
|
|
147
|
+
summary: "summary";
|
|
148
|
+
}>, z.ZodObject<{
|
|
149
|
+
head: z.ZodNumber;
|
|
150
|
+
}, z.core.$strict>]>>;
|
|
151
|
+
minChars: z.ZodOptional<z.ZodNumber>;
|
|
152
|
+
onError: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
153
|
+
keep: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodEnum<{
|
|
154
|
+
round: "round";
|
|
155
|
+
turn: "turn";
|
|
156
|
+
compaction: "compaction";
|
|
157
|
+
forever: "forever";
|
|
158
|
+
}>, z.ZodObject<{
|
|
159
|
+
rounds: z.ZodNumber;
|
|
160
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
161
|
+
turns: z.ZodNumber;
|
|
162
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
163
|
+
newest: z.ZodNumber;
|
|
164
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
|
|
165
|
+
round: "round";
|
|
166
|
+
turn: "turn";
|
|
167
|
+
compaction: "compaction";
|
|
168
|
+
forever: "forever";
|
|
169
|
+
}>, z.ZodObject<{
|
|
170
|
+
rounds: z.ZodNumber;
|
|
171
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
172
|
+
turns: z.ZodNumber;
|
|
173
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
174
|
+
newest: z.ZodNumber;
|
|
175
|
+
}, z.core.$strict>]>>]>;
|
|
176
|
+
leave: z.ZodUnion<readonly [z.ZodEnum<{
|
|
177
|
+
none: "none";
|
|
178
|
+
stub: "stub";
|
|
179
|
+
summary: "summary";
|
|
180
|
+
}>, z.ZodObject<{
|
|
181
|
+
head: z.ZodNumber;
|
|
182
|
+
}, z.core.$strict>]>;
|
|
183
|
+
}, z.core.$strip>>>;
|
|
184
|
+
}, z.core.$strip>>>;
|
|
185
|
+
tools: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
186
|
+
keep: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodEnum<{
|
|
187
|
+
round: "round";
|
|
188
|
+
turn: "turn";
|
|
189
|
+
compaction: "compaction";
|
|
190
|
+
forever: "forever";
|
|
191
|
+
}>, z.ZodObject<{
|
|
192
|
+
rounds: z.ZodNumber;
|
|
193
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
194
|
+
turns: z.ZodNumber;
|
|
195
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
196
|
+
newest: z.ZodNumber;
|
|
197
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
|
|
198
|
+
round: "round";
|
|
199
|
+
turn: "turn";
|
|
200
|
+
compaction: "compaction";
|
|
201
|
+
forever: "forever";
|
|
202
|
+
}>, z.ZodObject<{
|
|
203
|
+
rounds: z.ZodNumber;
|
|
204
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
205
|
+
turns: z.ZodNumber;
|
|
206
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
207
|
+
newest: z.ZodNumber;
|
|
208
|
+
}, z.core.$strict>]>>]>>;
|
|
209
|
+
leave: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
210
|
+
none: "none";
|
|
211
|
+
stub: "stub";
|
|
212
|
+
summary: "summary";
|
|
213
|
+
}>, z.ZodObject<{
|
|
214
|
+
head: z.ZodNumber;
|
|
215
|
+
}, z.core.$strict>]>>;
|
|
216
|
+
minChars: z.ZodOptional<z.ZodNumber>;
|
|
217
|
+
onError: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
218
|
+
keep: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodEnum<{
|
|
219
|
+
round: "round";
|
|
220
|
+
turn: "turn";
|
|
221
|
+
compaction: "compaction";
|
|
222
|
+
forever: "forever";
|
|
223
|
+
}>, z.ZodObject<{
|
|
224
|
+
rounds: z.ZodNumber;
|
|
225
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
226
|
+
turns: z.ZodNumber;
|
|
227
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
228
|
+
newest: z.ZodNumber;
|
|
229
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
|
|
230
|
+
round: "round";
|
|
231
|
+
turn: "turn";
|
|
232
|
+
compaction: "compaction";
|
|
233
|
+
forever: "forever";
|
|
234
|
+
}>, z.ZodObject<{
|
|
235
|
+
rounds: z.ZodNumber;
|
|
236
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
237
|
+
turns: z.ZodNumber;
|
|
238
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
239
|
+
newest: z.ZodNumber;
|
|
240
|
+
}, z.core.$strict>]>>]>;
|
|
241
|
+
leave: z.ZodUnion<readonly [z.ZodEnum<{
|
|
242
|
+
none: "none";
|
|
243
|
+
stub: "stub";
|
|
244
|
+
summary: "summary";
|
|
245
|
+
}>, z.ZodObject<{
|
|
246
|
+
head: z.ZodNumber;
|
|
247
|
+
}, z.core.$strict>]>;
|
|
248
|
+
}, z.core.$strip>>>;
|
|
249
|
+
}, z.core.$strip>>>;
|
|
250
|
+
dialects: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
251
|
+
keep: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodEnum<{
|
|
252
|
+
round: "round";
|
|
253
|
+
turn: "turn";
|
|
254
|
+
compaction: "compaction";
|
|
255
|
+
forever: "forever";
|
|
256
|
+
}>, z.ZodObject<{
|
|
257
|
+
rounds: z.ZodNumber;
|
|
258
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
259
|
+
turns: z.ZodNumber;
|
|
260
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
261
|
+
newest: z.ZodNumber;
|
|
262
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
|
|
263
|
+
round: "round";
|
|
264
|
+
turn: "turn";
|
|
265
|
+
compaction: "compaction";
|
|
266
|
+
forever: "forever";
|
|
267
|
+
}>, z.ZodObject<{
|
|
268
|
+
rounds: z.ZodNumber;
|
|
269
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
270
|
+
turns: z.ZodNumber;
|
|
271
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
272
|
+
newest: z.ZodNumber;
|
|
273
|
+
}, z.core.$strict>]>>]>>;
|
|
274
|
+
leave: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
275
|
+
none: "none";
|
|
276
|
+
stub: "stub";
|
|
277
|
+
summary: "summary";
|
|
278
|
+
}>, z.ZodObject<{
|
|
279
|
+
head: z.ZodNumber;
|
|
280
|
+
}, z.core.$strict>]>>;
|
|
281
|
+
minChars: z.ZodOptional<z.ZodNumber>;
|
|
282
|
+
onError: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
283
|
+
keep: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodEnum<{
|
|
284
|
+
round: "round";
|
|
285
|
+
turn: "turn";
|
|
286
|
+
compaction: "compaction";
|
|
287
|
+
forever: "forever";
|
|
288
|
+
}>, z.ZodObject<{
|
|
289
|
+
rounds: z.ZodNumber;
|
|
290
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
291
|
+
turns: z.ZodNumber;
|
|
292
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
293
|
+
newest: z.ZodNumber;
|
|
294
|
+
}, z.core.$strict>]>, z.ZodArray<z.ZodUnion<readonly [z.ZodEnum<{
|
|
295
|
+
round: "round";
|
|
296
|
+
turn: "turn";
|
|
297
|
+
compaction: "compaction";
|
|
298
|
+
forever: "forever";
|
|
299
|
+
}>, z.ZodObject<{
|
|
300
|
+
rounds: z.ZodNumber;
|
|
301
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
302
|
+
turns: z.ZodNumber;
|
|
303
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
304
|
+
newest: z.ZodNumber;
|
|
305
|
+
}, z.core.$strict>]>>]>;
|
|
306
|
+
leave: z.ZodUnion<readonly [z.ZodEnum<{
|
|
307
|
+
none: "none";
|
|
308
|
+
stub: "stub";
|
|
309
|
+
summary: "summary";
|
|
310
|
+
}>, z.ZodObject<{
|
|
311
|
+
head: z.ZodNumber;
|
|
312
|
+
}, z.core.$strict>]>;
|
|
313
|
+
}, z.core.$strip>>>;
|
|
314
|
+
}, z.core.$strip>>>;
|
|
315
|
+
}, z.core.$strip>;
|
|
316
|
+
export type ContextRetention = z.output<typeof contextRetentionSchema>;
|
|
317
|
+
/** A rule with every field concrete. This is what R2 stamps on a job. */
|
|
318
|
+
export type ConcreteRule = {
|
|
319
|
+
readonly keep: readonly Horizon[];
|
|
320
|
+
readonly leave: Leave;
|
|
321
|
+
readonly minChars: number;
|
|
322
|
+
readonly onError: {
|
|
323
|
+
readonly keep: readonly Horizon[];
|
|
324
|
+
readonly leave: Leave;
|
|
325
|
+
} | null;
|
|
326
|
+
};
|
|
327
|
+
/** A partial policy as one source wrote it. */
|
|
328
|
+
export type RetentionLayer = {
|
|
329
|
+
readonly defaults?: {
|
|
330
|
+
readonly minChars?: number;
|
|
331
|
+
};
|
|
332
|
+
readonly step?: Partial<StepConfig>;
|
|
333
|
+
readonly kinds?: Readonly<Record<string, RuleInput>>;
|
|
334
|
+
readonly tools?: Readonly<Record<string, RuleInput>>;
|
|
335
|
+
readonly dialects?: Readonly<Record<string, RuleInput>>;
|
|
336
|
+
};
|
|
337
|
+
export declare function horizonList(keep: RuleInput["keep"]): Horizon[];
|
|
338
|
+
/**
|
|
339
|
+
* Tolerant parse of a `contextRetention` block (an object or its JSON text).
|
|
340
|
+
* An invalid field is dropped and never fatal, matching the rest of
|
|
341
|
+
* `config.json`. Only fields the author wrote survive: defaults are the dist
|
|
342
|
+
* layer's business, so the result is a partial layer.
|
|
343
|
+
*/
|
|
344
|
+
export declare function parseRetentionLayer(raw: unknown): RetentionLayer;
|
|
345
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/context/retention/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,eAAe,0SAqBlB,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,0FAA0F;AAC1F,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAAqD,CAAC;AAE1G,+GAA+G;AAC/G,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAanD,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;oBAKxB,CAAC;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AAErD,eAAO,MAAM,WAAW;;;;;;oBAGtB,CAAC;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAIjD,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAOrB,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AA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E,SAAS,CAAC,CAAC,CAAC;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;CACzD,CAAC;AAEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,OAAO,EAAE,CAG9D;AAmBD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CA8BhE"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `contextRetention` — JSON-configurable tail retention. Nothing here deletes
|
|
3
|
+
* graph state: a rule decides what a projected item leaves behind once its
|
|
4
|
+
* horizon has passed. Design: `tail-retention-design.md` §3–§4.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
export const RETENTION_KINDS = [
|
|
8
|
+
"image.user",
|
|
9
|
+
"image.tool",
|
|
10
|
+
"tool.read",
|
|
11
|
+
"tool.search",
|
|
12
|
+
"tool.shell",
|
|
13
|
+
"tool.write",
|
|
14
|
+
"tool.args.write",
|
|
15
|
+
"tool.web.search",
|
|
16
|
+
"tool.web.fetch",
|
|
17
|
+
"tool.mcp",
|
|
18
|
+
"tool.program",
|
|
19
|
+
"tool.agent",
|
|
20
|
+
"tool.comm",
|
|
21
|
+
"tool.other",
|
|
22
|
+
"thinking",
|
|
23
|
+
"steer",
|
|
24
|
+
"approval-note",
|
|
25
|
+
"notification",
|
|
26
|
+
"system-note",
|
|
27
|
+
"error",
|
|
28
|
+
];
|
|
29
|
+
/** Authored by the user. Untrusted layers (project, agent, tool) cannot shorten these. */
|
|
30
|
+
export const USER_AUTHORED_KINDS = new Set(["steer", "approval-note", "image.user"]);
|
|
31
|
+
/** Kinds whose item is a tool result row. `leave: "none"` is not allowed: every tool_call needs a tool row. */
|
|
32
|
+
export const NONE_FORBIDDEN_KINDS = new Set([
|
|
33
|
+
"tool.read",
|
|
34
|
+
"tool.search",
|
|
35
|
+
"tool.shell",
|
|
36
|
+
"tool.write",
|
|
37
|
+
"tool.web.search",
|
|
38
|
+
"tool.web.fetch",
|
|
39
|
+
"tool.mcp",
|
|
40
|
+
"tool.program",
|
|
41
|
+
"tool.agent",
|
|
42
|
+
"tool.comm",
|
|
43
|
+
"tool.other",
|
|
44
|
+
"error",
|
|
45
|
+
]);
|
|
46
|
+
export const horizonSchema = z.union([
|
|
47
|
+
z.enum(["round", "turn", "compaction", "forever"]),
|
|
48
|
+
z.object({ rounds: z.number().int().min(1) }).strict(),
|
|
49
|
+
z.object({ turns: z.number().int().min(1) }).strict(),
|
|
50
|
+
z.object({ newest: z.number().int().min(0) }).strict(),
|
|
51
|
+
]);
|
|
52
|
+
export const leaveSchema = z.union([
|
|
53
|
+
z.enum(["none", "stub", "summary"]),
|
|
54
|
+
z.object({ head: z.number().int().min(0).max(5000) }).strict(),
|
|
55
|
+
]);
|
|
56
|
+
const keepSchema = z.union([horizonSchema, z.array(horizonSchema).min(1)]);
|
|
57
|
+
export const ruleSchema = z.object({
|
|
58
|
+
keep: keepSchema.optional(),
|
|
59
|
+
leave: leaveSchema.optional(),
|
|
60
|
+
/** Never elide below this many painted chars. */
|
|
61
|
+
minChars: z.number().int().min(0).optional(),
|
|
62
|
+
/** Error overlay for this rule. `null` disables it. */
|
|
63
|
+
onError: z.object({ keep: keepSchema, leave: leaveSchema }).nullable().optional(),
|
|
64
|
+
});
|
|
65
|
+
export const stepSchema = z.object({
|
|
66
|
+
turnBoundary: z.boolean().default(true),
|
|
67
|
+
everyRounds: z.number().int().min(1).nullable().default(4),
|
|
68
|
+
minFreedTokens: z.number().int().min(0).default(8000),
|
|
69
|
+
whenCacheCold: z.boolean().default(true),
|
|
70
|
+
atCompaction: z.literal(true).default(true),
|
|
71
|
+
});
|
|
72
|
+
export const contextRetentionSchema = z.object({
|
|
73
|
+
version: z.literal(1).default(1),
|
|
74
|
+
defaults: z.object({ minChars: z.number().int().min(0).default(800) }).prefault({}),
|
|
75
|
+
step: stepSchema.prefault({}),
|
|
76
|
+
kinds: z.record(z.string(), ruleSchema).default({}),
|
|
77
|
+
/** Keys: wire name ("shell"), "mcp:<server>/<tool>", globs ("mcp:github/*", "mcp:*"). */
|
|
78
|
+
tools: z.record(z.string(), ruleSchema).default({}),
|
|
79
|
+
/** Per-dialect thinking override, e.g. {"anthropic": {"keep": "forever"}}. */
|
|
80
|
+
dialects: z.record(z.string(), ruleSchema).default({}),
|
|
81
|
+
});
|
|
82
|
+
export function horizonList(keep) {
|
|
83
|
+
if (keep === undefined)
|
|
84
|
+
return [];
|
|
85
|
+
return Array.isArray(keep) ? [...keep] : [keep];
|
|
86
|
+
}
|
|
87
|
+
function jsonOf(raw) {
|
|
88
|
+
if (typeof raw !== "string")
|
|
89
|
+
return raw;
|
|
90
|
+
if (raw.trim() === "")
|
|
91
|
+
return undefined;
|
|
92
|
+
try {
|
|
93
|
+
return JSON.parse(raw);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const STEP_FIELDS = [
|
|
100
|
+
["turnBoundary", z.boolean()],
|
|
101
|
+
["everyRounds", z.number().int().min(1).nullable()],
|
|
102
|
+
["minFreedTokens", z.number().int().min(0)],
|
|
103
|
+
["whenCacheCold", z.boolean()],
|
|
104
|
+
];
|
|
105
|
+
/**
|
|
106
|
+
* Tolerant parse of a `contextRetention` block (an object or its JSON text).
|
|
107
|
+
* An invalid field is dropped and never fatal, matching the rest of
|
|
108
|
+
* `config.json`. Only fields the author wrote survive: defaults are the dist
|
|
109
|
+
* layer's business, so the result is a partial layer.
|
|
110
|
+
*/
|
|
111
|
+
export function parseRetentionLayer(raw) {
|
|
112
|
+
const value = jsonOf(raw);
|
|
113
|
+
if (value == null || typeof value !== "object" || Array.isArray(value))
|
|
114
|
+
return {};
|
|
115
|
+
const rec = value;
|
|
116
|
+
let layer = {};
|
|
117
|
+
const defaults = z.object({ minChars: z.number().int().min(0).optional() }).safeParse(rec.defaults);
|
|
118
|
+
if (defaults.success && defaults.data.minChars !== undefined) {
|
|
119
|
+
layer = { ...layer, defaults: { minChars: defaults.data.minChars } };
|
|
120
|
+
}
|
|
121
|
+
if (rec.step != null && typeof rec.step === "object" && !Array.isArray(rec.step)) {
|
|
122
|
+
const written = rec.step;
|
|
123
|
+
const step = {};
|
|
124
|
+
for (const [key, schema] of STEP_FIELDS) {
|
|
125
|
+
const parsed = schema.safeParse(written[key]);
|
|
126
|
+
if (parsed.success)
|
|
127
|
+
step[key] = parsed.data;
|
|
128
|
+
}
|
|
129
|
+
if (Object.keys(step).length > 0)
|
|
130
|
+
layer = { ...layer, step: step };
|
|
131
|
+
}
|
|
132
|
+
for (const section of ["kinds", "tools", "dialects"]) {
|
|
133
|
+
const bag = rec[section];
|
|
134
|
+
if (bag == null || typeof bag !== "object" || Array.isArray(bag))
|
|
135
|
+
continue;
|
|
136
|
+
const out = {};
|
|
137
|
+
for (const [key, ruleRaw] of Object.entries(bag)) {
|
|
138
|
+
if (section === "kinds" && !RETENTION_KINDS.includes(key))
|
|
139
|
+
continue;
|
|
140
|
+
const parsed = ruleSchema.safeParse(ruleRaw);
|
|
141
|
+
if (parsed.success)
|
|
142
|
+
out[key] = parsed.data;
|
|
143
|
+
}
|
|
144
|
+
if (Object.keys(out).length > 0)
|
|
145
|
+
layer = { ...layer, [section]: out };
|
|
146
|
+
}
|
|
147
|
+
return layer;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/context/retention/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,aAAa;IACb,YAAY;IACZ,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E,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAA8B,CAAC,EAAE,CAAC;YAC5E,IAAI,OAAO,KAAK,OAAO,IAAI,CAAE,eAAqC,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAAE,SAAS;YAC3F,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAC7C,IAAI,MAAM,CAAC,OAAO;gBAAE,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC;QAC7C,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC;YAAE,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IACxE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* R2: the resolved horizon of one tool job, stamped at admit. The kind comes
|
|
3
|
+
* from catalog facts read once, so later catalog churn cannot reclassify
|
|
4
|
+
* history; the projection reads the stamp and nothing else.
|
|
5
|
+
*/
|
|
6
|
+
import { ProgrammaticJob, ToolCallJob } from "@inhuman.tools/harness-model";
|
|
7
|
+
import { type ResolvedPolicy } from "./resolve.js";
|
|
8
|
+
import { type ConcreteRule, type RetentionKind, type RuleInput } from "./schema.js";
|
|
9
|
+
export declare const WRITE_ARG_TOOLS: ReadonlySet<string>;
|
|
10
|
+
export type RetainedJob = ToolCallJob | ProgrammaticJob;
|
|
11
|
+
export declare function kindOfJob(job: RetainedJob, entryClass?: string): RetentionKind;
|
|
12
|
+
/** `tools` keys that can name this job, most specific first. */
|
|
13
|
+
export declare function namesOfJob(job: RetainedJob): string[];
|
|
14
|
+
export type JobStamp = {
|
|
15
|
+
readonly kind: string;
|
|
16
|
+
readonly rule: ConcreteRule;
|
|
17
|
+
/** The rule for the call's own arguments (`write_file` / `edit_file` content). */
|
|
18
|
+
readonly args?: Pick<ConcreteRule, "keep" | "leave" | "minChars">;
|
|
19
|
+
};
|
|
20
|
+
export declare function stampJobRetention(job: RetainedJob, policy: ResolvedPolicy, opts?: {
|
|
21
|
+
readonly entryClass?: string;
|
|
22
|
+
readonly hint?: RuleInput;
|
|
23
|
+
}): void;
|
|
24
|
+
export declare function parseJobStamp(json: string): JobStamp | null;
|
|
25
|
+
//# sourceMappingURL=stamp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stamp.d.ts","sourceRoot":"","sources":["../../../src/context/retention/stamp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EASL,eAAe,EACf,WAAW,EAGZ,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAA8B,KAAK,YAAY,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAKhH,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,MAAM,CAAwC,CAAC;AAEzF,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,eAAe,CAAC;AAExD,wBAAgB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,aAAa,CAe9E;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,EAAE,CAIrD;AAiBD,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,kFAAkF;IAClF,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC,CAAC;CACnE,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,cAAc,EACtB,IAAI,GAAE;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAA;CAAO,GACrE,IAAI,CAkBN;AAID,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAiB3D"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* R2: the resolved horizon of one tool job, stamped at admit. The kind comes
|
|
3
|
+
* from catalog facts read once, so later catalog churn cannot reclassify
|
|
4
|
+
* history; the projection reads the stamp and nothing else.
|
|
5
|
+
*/
|
|
6
|
+
import { AgentCallbackJob, AgentCallJob, AgentMessageJob, AgentNotifyJob, BotCallJob, ContextNeedToolJob, FileMutateToolJob, MCPToolJob, ProgrammaticJob, ToolCallJob, WebExtractToolJob, WebSearchToolJob, } from "@inhuman.tools/harness-model";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { ruleFor } from "./resolve.js";
|
|
9
|
+
import { horizonSchema, leaveSchema } from "./schema.js";
|
|
10
|
+
const SEARCH_TOOLS = new Set(["grep", "fff_search"]);
|
|
11
|
+
const READ_TOOLS = new Set(["read_file", "list_dir", "glob"]);
|
|
12
|
+
const COMM_TOOLS = new Set(["update_metadata"]);
|
|
13
|
+
export const WRITE_ARG_TOOLS = new Set(["write_file", "edit_file"]);
|
|
14
|
+
export function kindOfJob(job, entryClass) {
|
|
15
|
+
if (job instanceof ProgrammaticJob)
|
|
16
|
+
return "tool.program";
|
|
17
|
+
if (job instanceof MCPToolJob)
|
|
18
|
+
return "tool.mcp";
|
|
19
|
+
if (job instanceof WebSearchToolJob)
|
|
20
|
+
return "tool.web.search";
|
|
21
|
+
if (job instanceof WebExtractToolJob)
|
|
22
|
+
return "tool.web.fetch";
|
|
23
|
+
if (job instanceof FileMutateToolJob)
|
|
24
|
+
return "tool.write";
|
|
25
|
+
if (job instanceof AgentCallJob || job instanceof BotCallJob || job instanceof AgentMessageJob)
|
|
26
|
+
return "tool.agent";
|
|
27
|
+
if (job instanceof AgentCallbackJob || job instanceof AgentNotifyJob || job instanceof ContextNeedToolJob) {
|
|
28
|
+
return "tool.comm";
|
|
29
|
+
}
|
|
30
|
+
if (job.name === "shell")
|
|
31
|
+
return "tool.shell";
|
|
32
|
+
if (SEARCH_TOOLS.has(job.name))
|
|
33
|
+
return "tool.search";
|
|
34
|
+
if (READ_TOOLS.has(job.name) || entryClass === "read")
|
|
35
|
+
return "tool.read";
|
|
36
|
+
if (COMM_TOOLS.has(job.name))
|
|
37
|
+
return "tool.comm";
|
|
38
|
+
return "tool.other";
|
|
39
|
+
}
|
|
40
|
+
/** `tools` keys that can name this job, most specific first. */
|
|
41
|
+
export function namesOfJob(job) {
|
|
42
|
+
if (job instanceof ProgrammaticJob)
|
|
43
|
+
return [job.toolName];
|
|
44
|
+
if (job instanceof MCPToolJob)
|
|
45
|
+
return [`mcp:${job.connectionKey}/${job.serverToolName}`, job.name];
|
|
46
|
+
return [job.name];
|
|
47
|
+
}
|
|
48
|
+
const stampSchema = z.object({
|
|
49
|
+
kind: z.string(),
|
|
50
|
+
keep: z.array(horizonSchema),
|
|
51
|
+
leave: leaveSchema,
|
|
52
|
+
minChars: z.number().int().min(0),
|
|
53
|
+
onError: z.object({ keep: z.array(horizonSchema), leave: leaveSchema }).nullable(),
|
|
54
|
+
args: z
|
|
55
|
+
.object({
|
|
56
|
+
keep: z.array(horizonSchema),
|
|
57
|
+
leave: leaveSchema,
|
|
58
|
+
minChars: z.number().int().min(0),
|
|
59
|
+
})
|
|
60
|
+
.optional(),
|
|
61
|
+
});
|
|
62
|
+
export function stampJobRetention(job, policy, opts = {}) {
|
|
63
|
+
const kind = kindOfJob(job, opts.entryClass);
|
|
64
|
+
const names = namesOfJob(job);
|
|
65
|
+
const rule = ruleFor(policy, { kind, names, ...(opts.hint === undefined ? {} : { hint: opts.hint }) });
|
|
66
|
+
const argsRule = job instanceof ToolCallJob && WRITE_ARG_TOOLS.has(job.name)
|
|
67
|
+
? ruleFor(policy, { kind: "tool.args.write", names: [] })
|
|
68
|
+
: undefined;
|
|
69
|
+
job.retentionJson = JSON.stringify({
|
|
70
|
+
kind,
|
|
71
|
+
keep: rule.keep,
|
|
72
|
+
leave: rule.leave,
|
|
73
|
+
minChars: rule.minChars,
|
|
74
|
+
onError: rule.onError,
|
|
75
|
+
...(argsRule === undefined
|
|
76
|
+
? {}
|
|
77
|
+
: { args: { keep: argsRule.keep, leave: argsRule.leave, minChars: argsRule.minChars } }),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const stamps = new Map();
|
|
81
|
+
export function parseJobStamp(json) {
|
|
82
|
+
if (json === "")
|
|
83
|
+
return null;
|
|
84
|
+
const hit = stamps.get(json);
|
|
85
|
+
if (hit !== undefined)
|
|
86
|
+
return hit;
|
|
87
|
+
let out = null;
|
|
88
|
+
try {
|
|
89
|
+
const parsed = stampSchema.safeParse(JSON.parse(json));
|
|
90
|
+
if (parsed.success) {
|
|
91
|
+
const { kind, args, ...rule } = parsed.data;
|
|
92
|
+
out = { kind, rule, ...(args === undefined ? {} : { args }) };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
out = null;
|
|
97
|
+
}
|
|
98
|
+
if (stamps.size > 512)
|
|
99
|
+
stamps.clear();
|
|
100
|
+
stamps.set(json, out);
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=stamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stamp.js","sourceRoot":"","sources":["../../../src/context/retention/stamp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,8BAA8B,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