maka-agent 0.2.0-dev.30.20260912 → 0.2.0-dev.31.20260913

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 (194) hide show
  1. package/THIRD_PARTY_NOTICES.txt +392 -0
  2. package/dist/acp/maka-acp-agent.js +8 -2
  3. package/dist/acp/prompt-content.js +225 -0
  4. package/dist/acp/session-event-mapper.js +103 -0
  5. package/dist/acp/session-registry.js +654 -17
  6. package/dist/acp/stdio-server.js +10 -1
  7. package/dist/cli-core.js +1 -1
  8. package/dist/pi-transcript-tools.js +3 -2
  9. package/dist/pi-transcript.js +12 -2
  10. package/dist/runtime-host-session-channel.js +63 -9
  11. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  12. package/node_modules/@maka/core/dist/artifacts.js +6 -0
  13. package/node_modules/@maka/core/dist/attachments.js +7 -2
  14. package/node_modules/@maka/core/dist/durable-tool-result-projection.js +3 -1
  15. package/node_modules/@maka/core/dist/events.js +21 -0
  16. package/node_modules/@maka/core/dist/goal.js +44 -2
  17. package/node_modules/@maka/core/dist/permission.js +0 -1
  18. package/node_modules/@maka/core/dist/runtime-boundary.js +73 -29
  19. package/node_modules/@maka/core/dist/runtime-event.js +6 -3
  20. package/node_modules/@maka/core/dist/runtime-handoff.js +10 -2
  21. package/node_modules/@maka/core/dist/runtime-logical-execution.js +39 -14
  22. package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +3 -1
  23. package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
  24. package/node_modules/@maka/core/dist/unified-diff.js +33 -26
  25. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +49 -178
  26. package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +7 -2
  27. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +15 -53
  28. package/node_modules/@maka/runtime/dist/bash-model-output.js +7 -1
  29. package/node_modules/@maka/runtime/dist/bash-tail-buffer.js +13 -52
  30. package/node_modules/@maka/runtime/dist/builtin-tools.js +59 -111
  31. package/node_modules/@maka/runtime/dist/child-fd-input.js +3 -2
  32. package/node_modules/@maka/runtime/dist/context-budget-policy.js +1 -11
  33. package/node_modules/@maka/runtime/dist/context-budget.js +12 -1
  34. package/node_modules/@maka/runtime/dist/conversation-copy.js +104 -9
  35. package/node_modules/@maka/runtime/dist/filesystem-executor.js +10 -6
  36. package/node_modules/@maka/runtime/dist/filesystem-worker/client.js +77 -19
  37. package/node_modules/@maka/runtime/dist/filesystem-worker/launch-spec.js +66 -55
  38. package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +34 -97
  39. package/node_modules/@maka/runtime/dist/filesystem-worker/protocol.js +25 -10
  40. package/node_modules/@maka/runtime/dist/filesystem-worker/worker-entry.js +2 -0
  41. package/node_modules/@maka/runtime/dist/glob-search.js +74 -0
  42. package/node_modules/@maka/runtime/dist/goal-continuation.js +78 -8
  43. package/node_modules/@maka/runtime/dist/goal-state.js +7 -0
  44. package/node_modules/@maka/runtime/dist/grep-search.js +155 -0
  45. package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +84 -94
  46. package/node_modules/@maka/runtime/dist/model-history.js +25 -3
  47. package/node_modules/@maka/runtime/dist/pipe-tail-collector.js +6 -9
  48. package/node_modules/@maka/runtime/dist/read-page.js +231 -0
  49. package/node_modules/@maka/runtime/dist/request-projection.js +2 -15
  50. package/node_modules/@maka/runtime/dist/ripgrep-executable.js +62 -0
  51. package/node_modules/@maka/runtime/dist/ripgrep-guidance.js +81 -0
  52. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +187 -20
  53. package/node_modules/@maka/runtime/dist/runtime-read-model.js +2 -1
  54. package/node_modules/@maka/runtime/dist/sandbox/linux-profile-path.js +7 -1
  55. package/node_modules/@maka/runtime/dist/sandbox/linux-sandbox.js +20 -5
  56. package/node_modules/@maka/runtime/dist/session-manager.js +6 -6
  57. package/node_modules/@maka/runtime/dist/session-recap.js +9 -5
  58. package/node_modules/@maka/runtime/dist/shell-exec.js +7 -25
  59. package/node_modules/@maka/runtime/dist/shell-run-manager.js +1 -1
  60. package/node_modules/@maka/runtime/dist/shell-run-tool-result.js +1 -1
  61. package/node_modules/@maka/runtime/dist/shell-tools.js +6 -12
  62. package/node_modules/@maka/runtime/dist/tool-availability.js +0 -1
  63. package/node_modules/@maka/runtime/dist/tool-output.js +1 -1
  64. package/node_modules/@maka/runtime/dist/tool-result-archive-capability.js +24 -36
  65. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +32 -527
  66. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +17 -119
  67. package/node_modules/@maka/runtime/dist/tool-result-archive.js +7 -25
  68. package/node_modules/@maka/runtime/dist/tool-runtime.js +7 -5
  69. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +6933 -3681
  70. package/node_modules/@maka/runtime/dist/workspace-executor.js +20 -24
  71. package/node_modules/@maka/runtime/package.json +2 -0
  72. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +185 -191
  73. package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +3 -0
  74. package/node_modules/@maka/runtime-host/dist/protocol/index.js +5 -1
  75. package/node_modules/@maka/runtime-host/dist/protocol/message.js +2 -2
  76. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
  77. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +2 -2
  78. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +10 -2
  79. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +38 -0
  80. package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +2 -8
  81. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +2 -0
  82. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +81 -7
  83. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +13 -13
  84. package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +65 -0
  85. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +1 -0
  86. package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +5 -2
  87. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +88 -72
  88. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +21 -4
  89. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +145 -1
  90. package/node_modules/@maka/storage/dist/agent-run-store.js +5 -2
  91. package/node_modules/@maka/storage/dist/execution-stores.js +2 -1
  92. package/node_modules/@maka/storage/dist/runtime-transcript-query.js +27 -14
  93. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +69 -3
  94. package/node_modules/balanced-match/LICENSE.md +23 -0
  95. package/node_modules/balanced-match/README.md +57 -0
  96. package/node_modules/balanced-match/dist/commonjs/index.js +59 -0
  97. package/node_modules/balanced-match/dist/commonjs/package.json +3 -0
  98. package/node_modules/balanced-match/dist/esm/index.js +54 -0
  99. package/node_modules/balanced-match/dist/esm/package.json +3 -0
  100. package/node_modules/balanced-match/package.json +68 -0
  101. package/node_modules/brace-expansion/LICENSE +23 -0
  102. package/node_modules/brace-expansion/README.md +105 -0
  103. package/node_modules/brace-expansion/dist/commonjs/index.js +289 -0
  104. package/node_modules/brace-expansion/dist/commonjs/package.json +3 -0
  105. package/node_modules/brace-expansion/dist/esm/index.js +285 -0
  106. package/node_modules/brace-expansion/dist/esm/package.json +3 -0
  107. package/node_modules/brace-expansion/package.json +64 -0
  108. package/node_modules/glob/LICENSE.md +63 -0
  109. package/node_modules/glob/README.md +1203 -0
  110. package/node_modules/glob/dist/commonjs/glob.js +248 -0
  111. package/node_modules/glob/dist/commonjs/has-magic.js +27 -0
  112. package/node_modules/glob/dist/commonjs/ignore.js +119 -0
  113. package/node_modules/glob/dist/commonjs/index.js +68 -0
  114. package/node_modules/glob/dist/commonjs/index.min.js +4 -0
  115. package/node_modules/glob/dist/commonjs/package.json +3 -0
  116. package/node_modules/glob/dist/commonjs/pattern.js +223 -0
  117. package/node_modules/glob/dist/commonjs/processor.js +301 -0
  118. package/node_modules/glob/dist/commonjs/walker.js +387 -0
  119. package/node_modules/glob/dist/esm/glob.js +244 -0
  120. package/node_modules/glob/dist/esm/has-magic.js +23 -0
  121. package/node_modules/glob/dist/esm/ignore.js +115 -0
  122. package/node_modules/glob/dist/esm/index.js +55 -0
  123. package/node_modules/glob/dist/esm/index.min.js +4 -0
  124. package/node_modules/glob/dist/esm/package.json +3 -0
  125. package/node_modules/glob/dist/esm/pattern.js +219 -0
  126. package/node_modules/glob/dist/esm/processor.js +294 -0
  127. package/node_modules/glob/dist/esm/walker.js +381 -0
  128. package/node_modules/glob/package.json +98 -0
  129. package/node_modules/minimatch/LICENSE.md +55 -0
  130. package/node_modules/minimatch/README.md +528 -0
  131. package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
  132. package/node_modules/minimatch/dist/commonjs/ast.js +845 -0
  133. package/node_modules/minimatch/dist/commonjs/brace-expressions.js +150 -0
  134. package/node_modules/minimatch/dist/commonjs/escape.js +30 -0
  135. package/node_modules/minimatch/dist/commonjs/index.js +1127 -0
  136. package/node_modules/minimatch/dist/commonjs/package.json +3 -0
  137. package/node_modules/minimatch/dist/commonjs/unescape.js +38 -0
  138. package/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
  139. package/node_modules/minimatch/dist/esm/ast.js +841 -0
  140. package/node_modules/minimatch/dist/esm/brace-expressions.js +146 -0
  141. package/node_modules/minimatch/dist/esm/escape.js +26 -0
  142. package/node_modules/minimatch/dist/esm/index.js +1114 -0
  143. package/node_modules/minimatch/dist/esm/package.json +3 -0
  144. package/node_modules/minimatch/dist/esm/unescape.js +34 -0
  145. package/node_modules/minimatch/package.json +73 -0
  146. package/node_modules/minipass/LICENSE.md +55 -0
  147. package/node_modules/minipass/README.md +825 -0
  148. package/node_modules/minipass/dist/commonjs/index.js +1038 -0
  149. package/node_modules/minipass/dist/commonjs/package.json +3 -0
  150. package/node_modules/minipass/dist/esm/index.js +1020 -0
  151. package/node_modules/minipass/dist/esm/package.json +3 -0
  152. package/node_modules/minipass/package.json +77 -0
  153. package/node_modules/path-scurry/LICENSE.md +55 -0
  154. package/node_modules/path-scurry/README.md +636 -0
  155. package/node_modules/path-scurry/dist/commonjs/index.js +2018 -0
  156. package/node_modules/path-scurry/dist/commonjs/package.json +3 -0
  157. package/node_modules/path-scurry/dist/esm/index.js +1983 -0
  158. package/node_modules/path-scurry/dist/esm/package.json +3 -0
  159. package/node_modules/path-scurry/node_modules/lru-cache/LICENSE.md +55 -0
  160. package/node_modules/path-scurry/node_modules/lru-cache/README.md +469 -0
  161. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
  162. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
  163. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
  164. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
  165. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
  166. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
  167. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +1726 -0
  168. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +2 -0
  169. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.js +9 -0
  170. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js +1726 -0
  171. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js +2 -0
  172. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js +10 -0
  173. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/package.json +3 -0
  174. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js +10 -0
  175. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
  176. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js +1722 -0
  177. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
  178. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js +7 -0
  179. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.d.mts.map +1 -0
  180. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
  181. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +1722 -0
  182. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +2 -0
  183. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +6 -0
  184. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js +1722 -0
  185. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
  186. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js +7 -0
  187. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/package.json +3 -0
  188. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js +7 -0
  189. package/node_modules/path-scurry/node_modules/lru-cache/package.json +154 -0
  190. package/node_modules/path-scurry/package.json +72 -0
  191. package/package.json +1 -1
  192. package/node_modules/@maka/runtime/dist/active-tool-result-prune.js +0 -248
  193. package/node_modules/@maka/runtime/dist/active-tool-result-working-set.js +0 -218
  194. package/node_modules/@maka/runtime/dist/archive-read-tool.js +0 -115
@@ -1,218 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
- const MAX_NEWER_READ_CANDIDATES_PER_PATH = 64;
20
- /**
21
- * Select provider-visible results that a strictly newer completed step makes
22
- * redundant. The planner is intentionally deterministic and conservative:
23
- * parallel calls in one step never supersede each other, error results never
24
- * replace successful evidence, and unknown tools only participate in exact
25
- * input-and-output deduplication.
26
- */
27
- export function planActiveToolResultSupersession(observations) {
28
- const decisions = new Map();
29
- const newestExact = new Map();
30
- const newerReads = new Map();
31
- const newestSnapshots = new Map();
32
- for (let index = observations.length - 1; index >= 0; index -= 1) {
33
- const observation = observations[index];
34
- const exactKey = exactObservationKey(observation);
35
- const exactReplacement = newestExact.get(exactKey);
36
- if (observation.eligible &&
37
- exactReplacement &&
38
- exactReplacement.stepNumber > observation.stepNumber) {
39
- decisions.set(observation.toolCallId, {
40
- reason: 'exact_duplicate',
41
- supersededByToolCallId: exactReplacement.toolCallId,
42
- });
43
- }
44
- const descriptor = describeObservation(observation.toolName, observation.input);
45
- if (observation.eligible && !decisions.has(observation.toolCallId) && descriptor) {
46
- const replacement = findSemanticReplacement(observation, descriptor, newerReads, newestSnapshots);
47
- if (replacement)
48
- decisions.set(observation.toolCallId, replacement);
49
- }
50
- if (!newestExact.has(exactKey))
51
- newestExact.set(exactKey, observation);
52
- if (observation.isError || !descriptor)
53
- continue;
54
- if (descriptor.kind === 'read') {
55
- const reads = newerReads.get(descriptor.path) ?? [];
56
- if (reads.length < MAX_NEWER_READ_CANDIDATES_PER_PATH)
57
- reads.push(observation);
58
- newerReads.set(descriptor.path, reads);
59
- }
60
- else if (!newestSnapshots.has(descriptor.key)) {
61
- newestSnapshots.set(descriptor.key, observation);
62
- }
63
- }
64
- return decisions;
65
- }
66
- function findSemanticReplacement(observation, descriptor, newerReads, newestSnapshots) {
67
- let replacement;
68
- if (descriptor.kind === 'read') {
69
- replacement = newerReads.get(descriptor.path)?.find((candidate) => {
70
- if (candidate.stepNumber <= observation.stepNumber)
71
- return false;
72
- const candidateDescriptor = describeRead(candidate.input);
73
- return Boolean(candidateDescriptor && readCovers(candidateDescriptor, descriptor));
74
- });
75
- }
76
- else {
77
- const candidate = newestSnapshots.get(descriptor.key);
78
- if (candidate && candidate.stepNumber > observation.stepNumber)
79
- replacement = candidate;
80
- }
81
- if (!replacement)
82
- return undefined;
83
- return {
84
- reason: observation.isError
85
- ? 'failure_resolved'
86
- : descriptor.kind === 'read'
87
- ? 'newer_read_covers_range'
88
- : 'newer_snapshot',
89
- supersededByToolCallId: replacement.toolCallId,
90
- ...(observation.isError ? { failureBodySha256: observation.bodySha256 } : {}),
91
- };
92
- }
93
- function exactObservationKey(observation) {
94
- return `${observation.toolName}\u0000${stableStringify(observation.input)}\u0000${observation.isError ? 'error' : 'success'}\u0000${observation.bodySha256}`;
95
- }
96
- function describeObservation(toolName, input) {
97
- if (toolName === 'Read')
98
- return describeRead(input);
99
- if (toolName === 'Glob')
100
- return describeGlob(input);
101
- if (toolName === 'Grep')
102
- return describeGrep(input);
103
- if (toolName === 'Bash')
104
- return describeBash(input);
105
- return undefined;
106
- }
107
- function describeRead(input) {
108
- const record = asRecord(input);
109
- if (!record || typeof record.path !== 'string' || record.path.length === 0) {
110
- return undefined;
111
- }
112
- const start = nonNegativeInteger(record.offset) ?? 0;
113
- const limit = positiveInteger(record.limit);
114
- return {
115
- kind: 'read',
116
- path: normalizeSubjectPath(record.path),
117
- start,
118
- end: limit === undefined ? Number.POSITIVE_INFINITY : start + limit,
119
- };
120
- }
121
- function describeGlob(input) {
122
- const record = asRecord(input);
123
- if (!record || typeof record.pattern !== 'string')
124
- return undefined;
125
- if (record.cwd !== undefined && typeof record.cwd !== 'string')
126
- return undefined;
127
- return {
128
- kind: 'snapshot',
129
- key: `Glob\u0000${stableStringify({
130
- pattern: record.pattern,
131
- cwd: normalizeSubjectPath(record.cwd ?? '.'),
132
- })}`,
133
- };
134
- }
135
- function describeGrep(input) {
136
- const record = asRecord(input);
137
- if (!record || typeof record.pattern !== 'string')
138
- return undefined;
139
- if (record.path !== undefined && typeof record.path !== 'string')
140
- return undefined;
141
- if (record.glob !== undefined && typeof record.glob !== 'string')
142
- return undefined;
143
- return {
144
- kind: 'snapshot',
145
- key: `Grep\u0000${stableStringify({
146
- pattern: record.pattern,
147
- path: normalizeSubjectPath(record.path ?? '.'),
148
- glob: record.glob ?? null,
149
- })}`,
150
- };
151
- }
152
- function describeBash(input) {
153
- const record = asRecord(input);
154
- if (!record || typeof record.command !== 'string')
155
- return undefined;
156
- if ((record.run_in_background !== undefined && typeof record.run_in_background !== 'boolean') ||
157
- (record.pty !== undefined && typeof record.pty !== 'boolean')) {
158
- return undefined;
159
- }
160
- // Background and PTY results are process handles or terminal snapshots, not
161
- // newer observations of a foreground command. Keep each one independently
162
- // visible; exact input-and-output deduplication still handles true repeats.
163
- if (record.run_in_background === true || record.pty === true)
164
- return undefined;
165
- const command = record.command.trim();
166
- if (!isSupportedGitSnapshotCommand(command))
167
- return undefined;
168
- return { kind: 'snapshot', key: `Bash\u0000${command}` };
169
- }
170
- function isSupportedGitSnapshotCommand(command) {
171
- if (command.length === 0 || /[;&|<>`\n\r]/.test(command) || command.includes('$('))
172
- return false;
173
- // Executable test/build output is evidence from a particular run, not a
174
- // snapshot of current state: an incremental rerun can omit an earlier
175
- // warning, and a passing rerun must not erase a flaky failure. Those calls
176
- // remain eligible for exact input-and-output deduplication only.
177
- return /^git(?:\s+-C\s+\S+)?\s+(?:status|diff|log|show|branch|rev-parse)(?:\s|$)/.test(command);
178
- }
179
- function readCovers(candidate, original) {
180
- return candidate.start <= original.start && candidate.end >= original.end;
181
- }
182
- function normalizeSubjectPath(value) {
183
- // Keep identity lexical and platform-independent. Leading whitespace and
184
- // backslashes are valid POSIX filename characters, repeated leading slashes
185
- // can carry implementation-defined meaning, and a Windows UNC prefix must
186
- // not collapse into a POSIX-looking path. Removing an explicit leading `./`
187
- // segment is the only equivalence shared by the supported executors. Prefer
188
- // false negatives here: semantic supersession must never merge distinct
189
- // filesystem subjects.
190
- let normalized = value;
191
- while (normalized.startsWith('./'))
192
- normalized = normalized.slice(2);
193
- return normalized.length === 0 ? '.' : normalized;
194
- }
195
- function asRecord(value) {
196
- return value && typeof value === 'object' && !Array.isArray(value)
197
- ? value
198
- : undefined;
199
- }
200
- function nonNegativeInteger(value) {
201
- return typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : undefined;
202
- }
203
- function positiveInteger(value) {
204
- return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined;
205
- }
206
- function stableStringify(value) {
207
- if (value === undefined)
208
- return '';
209
- if (value === null || typeof value !== 'object')
210
- return JSON.stringify(value) ?? '';
211
- if (Array.isArray(value))
212
- return `[${value.map(stableStringify).join(',')}]`;
213
- const record = value;
214
- return `{${Object.keys(record)
215
- .sort()
216
- .map((key) => `${JSON.stringify(key)}:${stableStringify(record[key])}`)
217
- .join(',')}}`;
218
- }
@@ -1,115 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
- import { jsonSchema, zodSchema } from 'ai';
20
- import { z } from 'zod';
21
- import { readToolResultArchiveResource, TOOL_RESULT_ARCHIVE_MAX_LIMIT, } from './tool-result-archive-resource.js';
22
- export const ARCHIVE_READ_TOOL_NAME = 'ArchiveRead';
23
- export function buildArchiveReadTool(reader) {
24
- const parameters = z.preprocess(cleanArchiveReadInput, z
25
- .object({
26
- ref: z
27
- .string()
28
- .describe('The exact resourceRef returned in an archived tool-result placeholder (ledger or legacy archive)'),
29
- operation: z
30
- .enum(['inspect', 'read', 'query', 'search'])
31
- .default('inspect')
32
- .describe('inspect lists archive metadata/items and a preview; query reads one structured item; read returns one bounded page (by character or line); search locates a substring'),
33
- unit: z
34
- .enum(['char', 'line'])
35
- .default('char')
36
- .describe('For read: whether offset/limit count characters (default) or whole lines'),
37
- offset: z
38
- .number()
39
- .int()
40
- .nonnegative()
41
- .optional()
42
- .describe('Zero-based start for pagination: character or line offset for read (per unit), character offset for query, or the character position to resume search from'),
43
- limit: z
44
- .number()
45
- .int()
46
- .positive()
47
- .max(TOOL_RESULT_ARCHIVE_MAX_LIMIT)
48
- .optional()
49
- .describe(`Maximum returned characters (or lines when unit is "line"), capped at ${TOOL_RESULT_ARCHIVE_MAX_LIMIT}`),
50
- itemId: z
51
- .string()
52
- .min(1)
53
- .max(256)
54
- .optional()
55
- .describe('Structured item id returned by inspect; required for query'),
56
- pattern: z
57
- .string()
58
- .min(1)
59
- .max(256)
60
- .optional()
61
- .describe('Literal, case-insensitive substring to locate; required for search'),
62
- })
63
- .strip()
64
- .superRefine((value, ctx) => {
65
- if (value.operation === 'query' && !value.itemId) {
66
- ctx.addIssue({
67
- code: 'custom',
68
- path: ['itemId'],
69
- message: 'itemId is required for query',
70
- });
71
- }
72
- if (value.operation === 'search' && !value.pattern) {
73
- ctx.addIssue({
74
- code: 'custom',
75
- path: ['pattern'],
76
- message: 'pattern is required for search',
77
- });
78
- }
79
- }));
80
- const providerSchema = zodSchema(parameters);
81
- return {
82
- name: ARCHIVE_READ_TOOL_NAME,
83
- displayName: 'Read archived result',
84
- activityKind: 'read',
85
- description: 'Inspect, search, or page through a tool-result archive using its exact resourceRef. Both ledger and legacy archive references are supported. Start with inspect for a preview and the char/line coordinate space. Use operation "search" with a pattern to locate text, operation "read" with unit "line" for line-oriented terminal output, or operation "query" with an itemId for one agent_swarm item. Results are strictly bounded so reading an archive cannot immediately trigger another archive.',
86
- parameters: jsonSchema(async () => await providerSchema.jsonSchema, {
87
- validate: async (value) => {
88
- const result = await parameters.safeParseAsync(value);
89
- return result.success
90
- ? { success: true, value: result.data }
91
- : { success: false, error: result.error };
92
- },
93
- }),
94
- impl: async (input, ctx) =>
95
- // Detach bounded slices before active tool settlements retain their archive backing.
96
- structuredClone(await readToolResultArchiveResource(reader, ctx.sessionId, input, ctx.abortSignal)),
97
- };
98
- }
99
- function cleanArchiveReadInput(input) {
100
- if (!input || typeof input !== 'object' || Array.isArray(input))
101
- return input;
102
- const cleaned = { ...input };
103
- const operation = cleaned.operation ?? 'inspect';
104
- if (operation !== 'query')
105
- delete cleaned.itemId;
106
- if (operation !== 'search')
107
- delete cleaned.pattern;
108
- if (operation !== 'read')
109
- delete cleaned.unit;
110
- if (operation === 'inspect') {
111
- delete cleaned.offset;
112
- delete cleaned.limit;
113
- }
114
- return cleaned;
115
- }