pi-harness-runtime 1.1.515 → 1.1.516

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.
Files changed (107) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/harness/approval-decision-store.ts +94 -0
  3. package/harness/delegated-approval-runtime.ts +375 -0
  4. package/harness/delegated-approval-types.ts +179 -0
  5. package/harness/delegation-store.ts +108 -0
  6. package/harness/exploration-checkpoint-tool.ts +216 -0
  7. package/harness/exploration-guard-runtime.ts +23 -0
  8. package/harness/jev-rejection-escalation.ts +248 -0
  9. package/harness/plan-handoff-bridge.ts +27 -6
  10. package/harness/plan-handoff-receiver.ts +258 -0
  11. package/harness/plan-handoff-registration.ts +28 -13
  12. package/index.ts +516 -23
  13. package/package.json +1 -1
  14. package/packages/agent-policy/package.json +1 -1
  15. package/packages/auth/package.json +1 -1
  16. package/packages/autonomous-runtime/package.json +1 -1
  17. package/packages/checkpoint/package.json +1 -1
  18. package/packages/clipboard/package.json +1 -1
  19. package/packages/codex-watcher/package.json +1 -1
  20. package/packages/config-capture/package.json +1 -1
  21. package/packages/contracts/package.json +1 -1
  22. package/packages/cookie-sanitizer/dist/atomic-write.d.ts +16 -0
  23. package/packages/cookie-sanitizer/dist/atomic-write.d.ts.map +1 -1
  24. package/packages/cookie-sanitizer/dist/atomic-write.js +28 -0
  25. package/packages/cookie-sanitizer/dist/atomic-write.js.map +1 -1
  26. package/packages/cookie-sanitizer/dist/index.d.ts +1 -1
  27. package/packages/cookie-sanitizer/dist/index.d.ts.map +1 -1
  28. package/packages/cookie-sanitizer/dist/index.js +1 -1
  29. package/packages/cookie-sanitizer/dist/index.js.map +1 -1
  30. package/packages/cookie-sanitizer/package.json +1 -1
  31. package/packages/cookie-sanitizer/src/atomic-write.ts +29 -0
  32. package/packages/cookie-sanitizer/src/index.ts +1 -0
  33. package/packages/evaluation-engine/package.json +1 -1
  34. package/packages/event-bus/package.json +1 -1
  35. package/packages/event-store/package.json +1 -1
  36. package/packages/experience-replay/package.json +1 -1
  37. package/packages/exploration-guard/dist/checkpoint.d.ts +12 -0
  38. package/packages/exploration-guard/dist/checkpoint.d.ts.map +1 -1
  39. package/packages/exploration-guard/dist/checkpoint.js +33 -1
  40. package/packages/exploration-guard/dist/checkpoint.js.map +1 -1
  41. package/packages/exploration-guard/dist/observation.d.ts +7 -0
  42. package/packages/exploration-guard/dist/observation.d.ts.map +1 -1
  43. package/packages/exploration-guard/dist/observation.js +90 -27
  44. package/packages/exploration-guard/dist/observation.js.map +1 -1
  45. package/packages/exploration-guard/dist/tracker.d.ts.map +1 -1
  46. package/packages/exploration-guard/dist/tracker.js +3 -1
  47. package/packages/exploration-guard/dist/tracker.js.map +1 -1
  48. package/packages/exploration-guard/dist/types.d.ts +1 -1
  49. package/packages/exploration-guard/dist/types.d.ts.map +1 -1
  50. package/packages/exploration-guard/package.json +1 -1
  51. package/packages/exploration-guard/src/checkpoint.ts +44 -1
  52. package/packages/exploration-guard/src/observation.ts +120 -26
  53. package/packages/exploration-guard/src/tracker.ts +3 -1
  54. package/packages/exploration-guard/src/types.ts +1 -1
  55. package/packages/file-copy-helper/package.json +1 -1
  56. package/packages/intent-analyzer/package.json +1 -1
  57. package/packages/jev-judge/dist/continuation-controller.d.ts +43 -0
  58. package/packages/jev-judge/dist/continuation-controller.d.ts.map +1 -1
  59. package/packages/jev-judge/dist/continuation-controller.js +54 -7
  60. package/packages/jev-judge/dist/continuation-controller.js.map +1 -1
  61. package/packages/jev-judge/package.json +1 -1
  62. package/packages/jev-judge/src/continuation-controller.ts +89 -7
  63. package/packages/learning-engine/package.json +1 -1
  64. package/packages/logging/package.json +1 -1
  65. package/packages/memory-engine/package.json +1 -1
  66. package/packages/notification/dist/adapters/telegram-adapter.d.ts.map +1 -1
  67. package/packages/notification/dist/adapters/telegram-adapter.js +1 -0
  68. package/packages/notification/dist/adapters/telegram-adapter.js.map +1 -1
  69. package/packages/notification/dist/notification-center.d.ts.map +1 -1
  70. package/packages/notification/dist/notification-center.js +7 -0
  71. package/packages/notification/dist/notification-center.js.map +1 -1
  72. package/packages/notification/dist/notification-policy.d.ts.map +1 -1
  73. package/packages/notification/dist/notification-policy.js +6 -0
  74. package/packages/notification/dist/notification-policy.js.map +1 -1
  75. package/packages/notification/dist/types.d.ts +9 -1
  76. package/packages/notification/dist/types.d.ts.map +1 -1
  77. package/packages/notification/package.json +1 -1
  78. package/packages/notification/src/adapters/telegram-adapter.ts +1 -0
  79. package/packages/notification/src/notification-center.ts +7 -0
  80. package/packages/notification/src/notification-policy.ts +6 -0
  81. package/packages/notification/src/types.ts +8 -0
  82. package/packages/paperclip-integration/package.json +1 -1
  83. package/packages/performance-optimizer/package.json +1 -1
  84. package/packages/plan-handoff/dist/mailbox.d.ts +7 -0
  85. package/packages/plan-handoff/dist/mailbox.d.ts.map +1 -1
  86. package/packages/plan-handoff/dist/mailbox.js +9 -0
  87. package/packages/plan-handoff/dist/mailbox.js.map +1 -1
  88. package/packages/plan-handoff/package.json +1 -1
  89. package/packages/plan-handoff/src/mailbox.ts +12 -0
  90. package/packages/privilege-broker/package.json +1 -1
  91. package/packages/prompt-compiler/package.json +1 -1
  92. package/packages/providers/package.json +1 -1
  93. package/packages/qdrant-skills/package.json +1 -1
  94. package/packages/quota-manager/package.json +1 -1
  95. package/packages/relay/package.json +1 -1
  96. package/packages/skill-mcp-client/package.json +1 -1
  97. package/packages/skills/package.json +1 -1
  98. package/packages/todo-bd-sync/package.json +1 -1
  99. package/packages/token-estimation/package.json +1 -1
  100. package/packages/tooling-preference/package.json +1 -1
  101. package/packages/trajectory/package.json +1 -1
  102. package/packages/tui/package.json +1 -1
  103. package/packages/two-phase-review/package.json +1 -1
  104. package/packages/types/package.json +1 -1
  105. package/packages/webmcp-tester/package.json +1 -1
  106. package/packages/wiki/package.json +1 -1
  107. package/packages/write-review/package.json +1 -1
@@ -0,0 +1,179 @@
1
+ /**
2
+ * The approval of an operation that the human has to give.
3
+ *
4
+ * The harness asks the human before an operation it may not run on its own:
5
+ * a commit, a push, a deployment, an external write. Two things can end
6
+ * that question: the human answers, or the deadline passes.
7
+ *
8
+ * The deadline is not an answer. When it passes, the operation continues
9
+ * only when the user delegated that outcome in advance, and only for the
10
+ * kinds of operation the delegation names. A delegation is never extended
11
+ * silently to an external or a destructive action.
12
+ *
13
+ * The decision is recorded with the source it really has: a click of the
14
+ * human is `"human"`, a decision of the judge is `"jev"`, and the outcome
15
+ * of a deadline that ran under a delegation is `"delegated-timeout"`.
16
+ */
17
+
18
+ /**
19
+ * The kinds of operation a delegation can cover.
20
+ *
21
+ * The vocabulary is small and closed. A delegation names the kinds it
22
+ * covers, and a delegation for one kind never covers another: a
23
+ * delegation for a commit does not cover a push.
24
+ */
25
+ export const DELEGATED_OPERATION_KINDS = [
26
+ "commit",
27
+ "push",
28
+ "commit-and-push",
29
+ "deploy",
30
+ "external-write",
31
+ ] as const;
32
+
33
+ /** A kind of operation a delegation can cover. */
34
+ export type DelegatedOperationKind = (typeof DELEGATED_OPERATION_KINDS)[number];
35
+
36
+ /**
37
+ * Is this a kind of operation a delegation can cover?
38
+ *
39
+ * A kind that is not in the vocabulary authorizes nothing: an unknown
40
+ * operation is never covered by a delegation.
41
+ */
42
+ export function isDelegatedOperationKind(
43
+ value: unknown,
44
+ ): value is DelegatedOperationKind {
45
+ return (
46
+ typeof value === "string" &&
47
+ (DELEGATED_OPERATION_KINDS as readonly string[]).includes(value)
48
+ );
49
+ }
50
+
51
+ /**
52
+ * An advance delegation of the timeout decision.
53
+ *
54
+ * The user records it before the question: "if I do not answer within five
55
+ * minutes, continue with a commit". The delegation is durable, and it
56
+ * belongs to a workspace: a delegation of one workspace never covers the
57
+ * operation of another one.
58
+ */
59
+ export interface Delegation {
60
+ /** The id of the delegation. */
61
+ id: string;
62
+ /** The workspace the delegation applies to. */
63
+ workspace: string;
64
+ /** The kinds of operation the delegation covers. */
65
+ kinds: DelegatedOperationKind[];
66
+ /** What happens at the deadline. */
67
+ defaultOutcome: "continue" | "block";
68
+ /** When the delegation was recorded. */
69
+ recordedAt: number;
70
+ /** When the delegation stops applying. */
71
+ expiresAt?: number;
72
+ }
73
+
74
+ /**
75
+ * Where a decision came from.
76
+ *
77
+ * The source is part of the decision: a timeout that ran under a
78
+ * delegation is never recorded as a click of the human.
79
+ */
80
+ export type ApprovalSource = "human" | "jev" | "delegated-timeout";
81
+
82
+ /** The answer of a human to a request. */
83
+ export type ApprovalOutcome = "yes" | "no";
84
+
85
+ /**
86
+ * A request for the approval of an operation.
87
+ */
88
+ export interface ApprovalRequest {
89
+ /** The canonical id of the request. It is the id of the pending question. */
90
+ requestId: string;
91
+ /** The workspace of the operation. */
92
+ workspace: string;
93
+ /** The session of the request. */
94
+ sessionId: string;
95
+ /** The generation of the request. */
96
+ generation: number;
97
+ /** The kind of the operation. */
98
+ kind: DelegatedOperationKind;
99
+ /** The exact operation, in the words of the human. */
100
+ operation: string;
101
+ /** What stays blocked while the request is open. */
102
+ blocked: string[];
103
+ /** Why the operation is not simply running. */
104
+ reason?: string;
105
+ /** The deadline of the answer. It is absolute. */
106
+ deadlineAt: number;
107
+ /** The state of the request. */
108
+ state: "pending" | "answered" | "claimed" | "expired";
109
+ /** The answer, when there is one. */
110
+ answer?: { outcome: ApprovalOutcome; source: ApprovalSource; at: number };
111
+ }
112
+
113
+ /**
114
+ * The recorded decision of a request.
115
+ *
116
+ * The record is what makes the decision auditable: it names the source,
117
+ * the delegation it rests on and the moment it was made.
118
+ */
119
+ export interface ApprovalDecision {
120
+ /** The request the decision belongs to. */
121
+ requestId: string;
122
+ /** The outcome of the decision. */
123
+ outcome: ApprovalOutcome;
124
+ /** Where the decision came from. */
125
+ source: ApprovalSource;
126
+ /** The delegation the decision rests on. */
127
+ delegationId?: string;
128
+ /** The reason of the decision. */
129
+ reason?: string;
130
+ /** When the decision was made. */
131
+ at: number;
132
+ }
133
+
134
+ /**
135
+ * The kind of operation of a proposal.
136
+ *
137
+ * The classification is narrow on purpose. A proposal whose kind is not
138
+ * known is not covered by a delegation, so an unknown operation never
139
+ * continues by silence.
140
+ */
141
+ export function operationKindFor(
142
+ text: string | undefined,
143
+ ): DelegatedOperationKind | undefined {
144
+ const value = (text ?? "").toLowerCase();
145
+ if (value.length === 0) return undefined;
146
+ const commit = /\bcommits?\b/.test(value);
147
+ const push = /\bpush(?:ed|es|ing)?\b/.test(value);
148
+ const deploy = /\bdeploy(?:ment|ed|ing)?\b|\bship(?:ped|s|ping)? to production\b/.test(value);
149
+ const external = /\bpublish(?:ed|es|ing)?\b|\bupload(?:ed|s|ing)?\b|\bpost(?:ed|s|ing)? to\b/.test(
150
+ value,
151
+ );
152
+ if (deploy) return "deploy";
153
+ if (external) return "external-write";
154
+ if (commit && push) return "commit-and-push";
155
+ if (commit) return "commit";
156
+ if (push) return "push";
157
+ return undefined;
158
+ }
159
+
160
+ /**
161
+ * Does a delegation cover an operation?
162
+ *
163
+ * The check is exact: the workspace must be the same, the delegation must
164
+ * not have expired, and the kind of the operation must be one the
165
+ * delegation names. A delegation for a commit does not cover a push, and
166
+ * a delegation of one workspace does not cover the operation of another.
167
+ */
168
+ export function delegationCovers(
169
+ delegation: Delegation,
170
+ kind: DelegatedOperationKind,
171
+ workspace: string,
172
+ now: number,
173
+ ): boolean {
174
+ if (delegation.workspace !== workspace) return false;
175
+ if (delegation.expiresAt !== undefined && delegation.expiresAt <= now) {
176
+ return false;
177
+ }
178
+ return delegation.kinds.includes(kind);
179
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * The delegations the user recorded in advance.
3
+ *
4
+ * A delegation says: "if I do not answer within the window, continue with
5
+ * a commit". It is durable, and it belongs to a workspace.
6
+ *
7
+ * The delegations live in one directory per workspace, and every
8
+ * delegation is one file. Two Pi instances therefore never overwrite each
9
+ * other, and a delegation that is recorded twice replaces only itself.
10
+ */
11
+
12
+ import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync } from "node:fs";
13
+ import { join } from "node:path";
14
+ import { atomicWriteFileSync } from "../packages/cookie-sanitizer/dist/index.js";
15
+ import type { DelegatedOperationKind, Delegation } from "./delegated-approval-types.ts";
16
+ import { isDelegatedOperationKind } from "./delegated-approval-types.ts";
17
+
18
+ /** Make a part of a path safe for the file system. */
19
+ function safePart(value: string): string {
20
+ return value.replace(/[^a-zA-Z0-9_.-]/g, "_").slice(-120);
21
+ }
22
+
23
+ /**
24
+ * The delegations of the machine.
25
+ */
26
+ export class DelegationStore {
27
+ /** The root of the store. */
28
+ private readonly root: string;
29
+
30
+ constructor(root: string) {
31
+ this.root = root;
32
+ }
33
+
34
+ /** The directory of the delegations of a workspace. */
35
+ private workspaceDir(workspace: string): string {
36
+ return join(this.root, "delegations", safePart(workspace));
37
+ }
38
+
39
+ /**
40
+ * Record a delegation.
41
+ *
42
+ * The write is atomic: the file is renamed over its target, so a
43
+ * reader never sees a delegation without its kinds.
44
+ */
45
+ record(delegation: Delegation): void {
46
+ const dir = this.workspaceDir(delegation.workspace);
47
+ mkdirSync(dir, { recursive: true });
48
+ atomicWriteFileSync(
49
+ join(dir, `${safePart(delegation.id)}.json`),
50
+ JSON.stringify(delegation, null, 2),
51
+ );
52
+ }
53
+
54
+ /**
55
+ * The delegations of a workspace.
56
+ *
57
+ * A delegation that cannot be read is skipped: a broken record never
58
+ * authorizes anything.
59
+ */
60
+ list(workspace: string): Delegation[] {
61
+ const dir = this.workspaceDir(workspace);
62
+ if (!existsSync(dir)) return [];
63
+ const found: Delegation[] = [];
64
+ for (const name of readdirSync(dir)) {
65
+ if (!name.endsWith(".json")) continue;
66
+ const delegation = readJson<Delegation>(join(dir, name));
67
+ if (!delegation) continue;
68
+ if (delegation.workspace !== workspace) continue;
69
+ if (!Array.isArray(delegation.kinds)) continue;
70
+ if (!delegation.kinds.every(isDelegatedOperationKind)) continue;
71
+ found.push({
72
+ ...delegation,
73
+ kinds: delegation.kinds as DelegatedOperationKind[],
74
+ });
75
+ }
76
+ return found;
77
+ }
78
+
79
+ /**
80
+ * Remove a delegation.
81
+ *
82
+ * The result is true when a delegation was removed.
83
+ */
84
+ remove(id: string): boolean {
85
+ const dir = join(this.root, "delegations");
86
+ if (!existsSync(dir)) return false;
87
+ for (const workspace of readdirSync(dir)) {
88
+ const path = join(dir, workspace, `${safePart(id)}.json`);
89
+ if (!existsSync(path)) continue;
90
+ try {
91
+ unlinkSync(path);
92
+ return true;
93
+ } catch {
94
+ return false;
95
+ }
96
+ }
97
+ return false;
98
+ }
99
+ }
100
+
101
+ /** Read a JSON file, or nothing when it cannot be read. */
102
+ function readJson<T>(path: string): T | undefined {
103
+ try {
104
+ return JSON.parse(readFileSync(path, "utf8")) as T;
105
+ } catch {
106
+ return undefined;
107
+ }
108
+ }
@@ -0,0 +1,216 @@
1
+ /**
2
+ * The tool that records the exploration checkpoint of the agent.
3
+ *
4
+ * The guard watches the reads of the agent, but it does not know what the
5
+ * agent learned from them. Only the agent can say that: the findings, the
6
+ * questions that are still open, the next concrete action and the hash of
7
+ * the files that were read.
8
+ *
9
+ * The tool records that statement beside the coverage of the request, so a
10
+ * compaction does not make the agent find it again.
11
+ *
12
+ * The tool records evidence and authorises nothing. It never writes a file,
13
+ * never changes a branch and never starts another task.
14
+ */
15
+
16
+ import { Type } from "typebox";
17
+ import {
18
+ defineTool,
19
+ type ExtensionAPI,
20
+ type ToolDefinition,
21
+ } from "@earendil-works/pi-coding-agent";
22
+ import type { CheckpointInput } from "../packages/exploration-guard/dist/index.js";
23
+
24
+ /**
25
+ * The recorder of the checkpoint.
26
+ *
27
+ * The runtime of the running request records the checkpoint. The recorder
28
+ * is read when the tool is called, because the request changes while the
29
+ * tool stays registered.
30
+ */
31
+ export interface ExplorationCheckpointRecorder {
32
+ /**
33
+ * Record the checkpoint of the request.
34
+ *
35
+ * The result is true when the checkpoint was written.
36
+ */
37
+ recordCheckpoint(input: CheckpointInput): boolean;
38
+ }
39
+
40
+ /**
41
+ * The options of the tool.
42
+ */
43
+ export interface ExplorationCheckpointToolOptions {
44
+ /**
45
+ * The recorder of the running request.
46
+ *
47
+ * There is no recorder when no request is running, and the tool says
48
+ * so instead of pretending that it recorded something.
49
+ */
50
+ current: () => ExplorationCheckpointRecorder | null;
51
+ }
52
+
53
+ /**
54
+ * The name of the tool.
55
+ */
56
+ export const EXPLORATION_CHECKPOINT_TOOL = "exploration_checkpoint";
57
+
58
+ /**
59
+ * The parameters of the tool.
60
+ */
61
+ const parameters = Type.Object({
62
+ findings: Type.Optional(
63
+ Type.Array(
64
+ Type.Object({
65
+ statement: Type.String({
66
+ description:
67
+ "What was found, in one sentence. A finding names a location when it has one.",
68
+ }),
69
+ locations: Type.Optional(
70
+ Type.Array(
71
+ Type.String({
72
+ description: "Where the finding was found.",
73
+ }),
74
+ ),
75
+ ),
76
+ }),
77
+ { description: "The findings of the investigation so far." },
78
+ ),
79
+ ),
80
+ hypotheses: Type.Optional(
81
+ Type.Array(
82
+ Type.Object({
83
+ statement: Type.String({
84
+ description: "A hypothesis about the cause of the problem.",
85
+ }),
86
+ rejected: Type.Optional(
87
+ Type.Boolean({
88
+ description: "True when the hypothesis was ruled out.",
89
+ }),
90
+ ),
91
+ }),
92
+ { description: "The hypotheses that were narrowed or ruled out." },
93
+ ),
94
+ ),
95
+ openQuestions: Type.Optional(
96
+ Type.Array(
97
+ Type.String({ description: "A question that is still open." }),
98
+ { description: "The questions that are still open." },
99
+ ),
100
+ ),
101
+ nextAction: Type.Optional(
102
+ Type.String({
103
+ description:
104
+ "The next concrete action, in one sentence. It names what to do next, not what to conclude.",
105
+ }),
106
+ ),
107
+ references: Type.Optional(
108
+ Type.Array(
109
+ Type.Object({
110
+ path: Type.String({
111
+ description: "The file the findings refer to.",
112
+ }),
113
+ contentHash: Type.Optional(
114
+ Type.String({
115
+ description:
116
+ "The hash of the content that was observed. A file whose hash changes is read again.",
117
+ }),
118
+ ),
119
+ }),
120
+ { description: "The files the findings refer to." },
121
+ ),
122
+ ),
123
+ });
124
+
125
+ /**
126
+ * The tool that records the exploration checkpoint.
127
+ *
128
+ * The tool never throws: a checkpoint that cannot be written is reported
129
+ * as a failure of the record, and the agent continues.
130
+ */
131
+ export function explorationCheckpointTool(
132
+ options: ExplorationCheckpointToolOptions,
133
+ ): ToolDefinition<typeof parameters> {
134
+ return defineTool({
135
+ name: EXPLORATION_CHECKPOINT_TOOL,
136
+ label: "Exploration checkpoint",
137
+ description:
138
+ "Record the exploration checkpoint of the current request: the findings, the hypotheses that were ruled out, the questions that are still open, the next concrete action and the hash of the files that were read. " +
139
+ "Use it when the investigation has produced an answer that a compaction or a later turn would otherwise lose, and when the guard asks for a checkpoint. " +
140
+ "It records evidence: it does not authorise a change, it does not write anything and it does not start another task.",
141
+ parameters,
142
+ async execute(_toolCallId, params) {
143
+ const recorder = options.current();
144
+ if (!recorder) {
145
+ return {
146
+ content: [
147
+ {
148
+ type: "text",
149
+ text: "There is no running request, so there is no exploration to record.",
150
+ },
151
+ ],
152
+ details: {},
153
+ };
154
+ }
155
+ const recorded = recorder.recordCheckpoint({
156
+ findings: params.findings,
157
+ hypotheses: params.hypotheses,
158
+ openQuestions: params.openQuestions,
159
+ nextAction: params.nextAction,
160
+ references: params.references,
161
+ });
162
+ if (!recorded) {
163
+ return {
164
+ content: [
165
+ {
166
+ type: "text",
167
+ text: "The checkpoint of the request could not be recorded.",
168
+ },
169
+ ],
170
+ details: {},
171
+ };
172
+ }
173
+ // The answer names what was recorded: the agent must be able to
174
+ // see that the record holds its findings, and a record of
175
+ // nothing is a record that says nothing.
176
+ const parts: string[] = [];
177
+ if (params.findings?.length) {
178
+ parts.push(`${params.findings.length} finding(s)`);
179
+ }
180
+ if (params.hypotheses?.length) {
181
+ parts.push(`${params.hypotheses.length} hypothesis(es)`);
182
+ }
183
+ if (params.openQuestions?.length) {
184
+ parts.push(`${params.openQuestions.length} open question(s)`);
185
+ }
186
+ if (params.references?.length) {
187
+ parts.push(`${params.references.length} file reference(s)`);
188
+ }
189
+ if (params.nextAction) {
190
+ parts.push("a next action");
191
+ }
192
+ return {
193
+ content: [
194
+ {
195
+ type: "text",
196
+ text:
197
+ parts.length > 0
198
+ ? `The checkpoint of the request was recorded: ${parts.join(", ")}.`
199
+ : "The checkpoint of the request was recorded, but it was empty.",
200
+ },
201
+ ],
202
+ details: {},
203
+ };
204
+ },
205
+ });
206
+ }
207
+
208
+ /**
209
+ * Register the tool of the exploration checkpoint.
210
+ */
211
+ export function registerExplorationCheckpointTool(
212
+ pi: ExtensionAPI,
213
+ options: ExplorationCheckpointToolOptions,
214
+ ): void {
215
+ pi.registerTool(explorationCheckpointTool(options));
216
+ }
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import type {
15
+ CheckpointInput,
15
16
  ExplorationKey,
16
17
  ExplorationPhase,
17
18
  ExplorationState,
@@ -313,4 +314,26 @@ export class ExplorationGuardRuntime {
313
314
  return "investigating | unknown";
314
315
  }
315
316
  }
317
+
318
+ /**
319
+ * Record the checkpoint that the agent reports.
320
+ *
321
+ * The findings, the questions, the next action and the hashes of the
322
+ * files that were read are written to the state of the request, so a
323
+ * compaction does not make the agent find them again.
324
+ *
325
+ * A checkpoint of a finished request is ignored: the request is over
326
+ * and its record is closed.
327
+ */
328
+ recordCheckpoint(input: CheckpointInput): boolean {
329
+ if (this.inactive) return false;
330
+ try {
331
+ this.tracker.recordCheckpoint(this.key(), input);
332
+ return true;
333
+ } catch {
334
+ // The checkpoint could not be written: the agent continues
335
+ // without it, and the record of the request stays as it was.
336
+ return false;
337
+ }
338
+ }
316
339
  }