maka-agent 0.2.0-dev.44.20260920 → 0.2.0-dev.45.20260921

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 (61) hide show
  1. package/dist/runtime-host-service-manager.js +1 -6
  2. package/dist/runtime-host-update-command.js +39 -27
  3. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  4. package/node_modules/@maka/core/dist/artifacts.js +1 -0
  5. package/node_modules/@maka/core/dist/model-metadata.js +1 -2
  6. package/node_modules/@maka/core/dist/provider-auth.js +1 -7
  7. package/node_modules/@maka/core/dist/provider-registry.js +13 -7
  8. package/node_modules/@maka/core/dist/recall.js +5 -1
  9. package/node_modules/@maka/core/dist/session-start-mode.js +2 -5
  10. package/node_modules/@maka/core/dist/session.js +0 -1
  11. package/node_modules/@maka/core/dist/settings.js +17 -0
  12. package/node_modules/@maka/core/dist/tool-quiet-preview.js +2 -16
  13. package/node_modules/@maka/core/dist/transcript-search.js +46 -0
  14. package/node_modules/@maka/core/package.json +1 -4
  15. package/node_modules/@maka/runtime/dist/model-factory.js +0 -16
  16. package/node_modules/@maka/runtime/dist/model-fetcher.js +1 -4
  17. package/node_modules/@maka/runtime/dist/model-runtime.js +0 -8
  18. package/node_modules/@maka/runtime/dist/recall-tools.js +4 -0
  19. package/node_modules/@maka/runtime/dist/session-manager.js +4 -13
  20. package/node_modules/@maka/runtime/dist/subagent-tools.js +69 -11
  21. package/node_modules/@maka/runtime/dist/test-connection.js +1 -48
  22. package/node_modules/@maka/runtime/package.json +0 -1
  23. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +25 -18
  24. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +3 -1
  25. package/node_modules/@maka/runtime-host/dist/protocol/connection-effects.js +0 -108
  26. package/node_modules/@maka/runtime-host/dist/protocol/index.js +6 -1
  27. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +4 -5
  28. package/node_modules/@maka/runtime-host/dist/protocol/recall.js +270 -0
  29. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -7
  30. package/node_modules/@maka/runtime-host/dist/protocol/usage-screen.js +12 -4
  31. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +4 -0
  32. package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +1 -57
  33. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +11 -33
  34. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +3 -20
  35. package/node_modules/@maka/runtime-host/dist/server/recall-coordinator.js +117 -0
  36. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +0 -4
  37. package/node_modules/@maka/storage/dist/artifact-metadata-codec.js +4 -3
  38. package/node_modules/@maka/storage/dist/artifact-store.js +1 -11
  39. package/node_modules/@maka/storage/dist/process-lifetime-file-update-lock.js +0 -41
  40. package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +0 -28
  41. package/node_modules/@maka/storage/dist/runtime-policy-stores.js +0 -2
  42. package/node_modules/@maka/storage/dist/sqlite-usage-schema.js +29 -5
  43. package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +2 -0
  44. package/node_modules/@maka/storage/dist/storage-writer-composition.js +0 -3
  45. package/node_modules/@maka/storage/dist/telemetry-file-schema.js +5 -3
  46. package/node_modules/@maka/storage/dist/usage-screen.js +5 -6
  47. package/node_modules/@maka/storage/dist/usage-stores.js +14 -4
  48. package/node_modules/@maka/storage/package.json +0 -2
  49. package/package.json +1 -1
  50. package/node_modules/@maka/core/dist/connection-usage.js +0 -27
  51. package/node_modules/@maka/core/dist/deep-research-client-progress.js +0 -132
  52. package/node_modules/@maka/core/dist/deep-research-run.js +0 -625
  53. package/node_modules/@maka/core/dist/deep-research.js +0 -208
  54. package/node_modules/@maka/core/dist/thread-search.js +0 -498
  55. package/node_modules/@maka/runtime/dist/commandcode-cli-language-model.js +0 -837
  56. package/node_modules/@maka/runtime/dist/connection-usage.js +0 -232
  57. package/node_modules/@maka/runtime/dist/deep-research-tools.js +0 -732
  58. package/node_modules/@maka/runtime-host/dist/protocol/deep-research.js +0 -233
  59. package/node_modules/@maka/runtime-host/dist/server/deep-research-coordinator.js +0 -116
  60. package/node_modules/@maka/storage/dist/deep-research-authority.js +0 -129
  61. package/node_modules/@maka/storage/dist/deep-research-store.js +0 -343
@@ -1,625 +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
- /**
20
- * Durable Deep Research workspace contract.
21
- *
22
- * This independently reproduces the central systems idea from FS-Researcher
23
- * (Zhu et al., ACL 2026): evidence collection and report writing share a
24
- * persistent workspace that survives model-context and process boundaries.
25
- * Maka keeps the canonical state as an append-only event ledger and stores
26
- * large source/note/report bodies in the existing ArtifactStore.
27
- *
28
- * Paper: https://arxiv.org/abs/2602.01566
29
- */
30
- import { isFiniteNumber, isRecord } from './record-schema.js';
31
- import { redactSecrets } from './redaction.js';
32
- export const DEEP_RESEARCH_RUN_SCHEMA_VERSION = 1;
33
- export const DEEP_RESEARCH_ACTIVE_STAGES = ['knowledge_base', 'report_writing'];
34
- export const DEEP_RESEARCH_STAGES = [...DEEP_RESEARCH_ACTIVE_STAGES, 'completed'];
35
- export const DEEP_RESEARCH_RUN_STATUSES = ['active', 'blocked', 'completed'];
36
- export const DEEP_RESEARCH_SCOPE_LEVELS = ['quick', 'standard', 'deep'];
37
- export const DEEP_RESEARCH_ARTIFACT_ROLES = [
38
- 'source',
39
- 'evidence_note',
40
- 'outline',
41
- 'report_section',
42
- 'report',
43
- 'handoff',
44
- ];
45
- export const DEEP_RESEARCH_CHECKLIST_STATUSES = [
46
- 'pending',
47
- 'in_progress',
48
- 'blocked',
49
- 'completed',
50
- 'skipped',
51
- ];
52
- export const DEEP_RESEARCH_REPORT_SECTION_KEYS = [
53
- 'conclusion',
54
- 'source_evidence',
55
- 'borrow_diverge_risk_gate',
56
- 'implementation_recommendations',
57
- 'verification',
58
- ];
59
- export const DEEP_RESEARCH_REPORT_SECTION_STATUSES = ['pending', 'drafted', 'completed'];
60
- export const DEEP_RESEARCH_STEP_KINDS = ['local_exploration', 'web_research'];
61
- export const DEEP_RESEARCH_STEP_STATUSES = ['completed', 'blocked', 'stopped'];
62
- export const DEEP_RESEARCH_INSPECTED_REF_KINDS = [
63
- 'file',
64
- 'symbol',
65
- 'config',
66
- 'test',
67
- 'runtime',
68
- 'url',
69
- ];
70
- export const DEEP_RESEARCH_EVENT_TYPES = [
71
- 'research_started',
72
- 'research_artifact_recorded',
73
- 'research_checklist_updated',
74
- 'research_step_recorded',
75
- 'research_checkpoint_recorded',
76
- 'research_completed',
77
- ];
78
- export const DEEP_RESEARCH_OBJECTIVE_MAX_CHARS = 2_000;
79
- export const DEEP_RESEARCH_ARTIFACT_NAME_MAX_CHARS = 240;
80
- export const DEEP_RESEARCH_LOCATOR_MAX_CHARS = 4_096;
81
- export const DEEP_RESEARCH_CHECKPOINT_TEXT_MAX_CHARS = 4_000;
82
- export const DEEP_RESEARCH_CHECKPOINT_ITEM_MAX_CHARS = 1_000;
83
- export const DEEP_RESEARCH_CHECKPOINT_ITEMS_MAX = 50;
84
- export const DEEP_RESEARCH_REFS_MAX = 100;
85
- export const DEEP_RESEARCH_ARTIFACTS_MAX = 2_000;
86
- export const DEEP_RESEARCH_CHECKPOINTS_MAX = 500;
87
- export const DEEP_RESEARCH_CHECKLIST_ITEMS_MAX = 50;
88
- export const DEEP_RESEARCH_STEPS_MAX = 500;
89
- export const DEEP_RESEARCH_STEP_TEXT_MAX_CHARS = 2_000;
90
- export const DEEP_RESEARCH_STEP_LIST_ITEMS_MAX = 50;
91
- export const DEEP_RESEARCH_INSPECTED_REFS_MAX = 200;
92
- export const DEEP_RESEARCH_CLIENT_PROGRESS_MAX_BYTES = 46 * 1024;
93
- export const DEEP_RESEARCH_CLIENT_RECENT_ITEMS_MAX = 8;
94
- export const DEEP_RESEARCH_CLIENT_OBJECTIVE_MAX_BYTES = 4 * 1024;
95
- export const DEEP_RESEARCH_CLIENT_TEXT_MAX_BYTES = 256;
96
- export const DEEP_RESEARCH_CLIENT_IMPLEMENTATION_PROMPT_MAX_BYTES = 16 * 1024;
97
- export const DEEP_RESEARCH_DEFAULT_CHECKLIST = [
98
- { itemId: 'project_entrypoints', title: 'Map project entrypoints and execution setup' },
99
- { itemId: 'core_flow', title: 'Trace the core implementation and data flow' },
100
- { itemId: 'boundaries', title: 'Verify permissions, privacy, failure, and runtime boundaries' },
101
- {
102
- itemId: 'verification_evidence',
103
- title: 'Collect tests, fixtures, and reproducible verification evidence',
104
- },
105
- ];
106
- export function isDeepResearchActiveStage(value) {
107
- return (typeof value === 'string' && DEEP_RESEARCH_ACTIVE_STAGES.includes(value));
108
- }
109
- export function isDeepResearchArtifactRole(value) {
110
- return (typeof value === 'string' && DEEP_RESEARCH_ARTIFACT_ROLES.includes(value));
111
- }
112
- export function isDeepResearchScopeLevel(value) {
113
- return (typeof value === 'string' && DEEP_RESEARCH_SCOPE_LEVELS.includes(value));
114
- }
115
- export function isDeepResearchChecklistStatus(value) {
116
- return (typeof value === 'string' &&
117
- DEEP_RESEARCH_CHECKLIST_STATUSES.includes(value));
118
- }
119
- export function isDeepResearchReportSectionKey(value) {
120
- return (typeof value === 'string' &&
121
- DEEP_RESEARCH_REPORT_SECTION_KEYS.includes(value));
122
- }
123
- export function isDeepResearchReportSectionStatus(value) {
124
- return (typeof value === 'string' &&
125
- DEEP_RESEARCH_REPORT_SECTION_STATUSES.includes(value));
126
- }
127
- export function isDeepResearchStepKind(value) {
128
- return (typeof value === 'string' && DEEP_RESEARCH_STEP_KINDS.includes(value));
129
- }
130
- export function isDeepResearchStepStatus(value) {
131
- return (typeof value === 'string' && DEEP_RESEARCH_STEP_STATUSES.includes(value));
132
- }
133
- export function normalizeDeepResearchObjective(value) {
134
- if (typeof value !== 'string')
135
- return undefined;
136
- const normalized = value.normalize('NFC').replace(/\s+/g, ' ').trim();
137
- if (normalized.length === 0 ||
138
- Array.from(normalized).length > DEEP_RESEARCH_OBJECTIVE_MAX_CHARS) {
139
- return undefined;
140
- }
141
- return normalized;
142
- }
143
- export function isDeepResearchEvent(value) {
144
- if (!isRecord(value) ||
145
- !isStableId(value.eventId) ||
146
- !DEEP_RESEARCH_EVENT_TYPES.includes(value.type) ||
147
- !isStableId(value.sessionId) ||
148
- !isFiniteNumber(value.ts) ||
149
- !isEventRefs(value.refs)) {
150
- return false;
151
- }
152
- switch (value.type) {
153
- case 'research_started':
154
- return (normalizeDeepResearchObjective(value.objective) === value.objective &&
155
- isDeepResearchScopeLevel(value.scopeLevel));
156
- case 'research_artifact_recorded':
157
- return isDeepResearchArtifactRef(value.artifact);
158
- case 'research_checklist_updated':
159
- return isDeepResearchChecklistItem(value.item);
160
- case 'research_step_recorded':
161
- return isDeepResearchStep(value.step);
162
- case 'research_checkpoint_recorded':
163
- return isDeepResearchCheckpoint(value.checkpoint);
164
- case 'research_completed':
165
- return isStableId(value.reportArtifactId) && isDeepResearchHandoff(value.handoff);
166
- default:
167
- return false;
168
- }
169
- }
170
- export function projectDeepResearchEvents(events) {
171
- let run;
172
- const diagnostics = [];
173
- const eventIds = new Set();
174
- const artifactIds = new Set();
175
- const checkpointIds = new Set();
176
- const stepIds = new Set();
177
- for (const event of events) {
178
- if (!isDeepResearchEvent(event)) {
179
- diagnostics.push('invalid deep research event shape');
180
- continue;
181
- }
182
- if (eventIds.has(event.eventId)) {
183
- diagnostics.push(`duplicate deep research event id ${event.eventId}`);
184
- continue;
185
- }
186
- eventIds.add(event.eventId);
187
- if (event.type === 'research_started') {
188
- if (run) {
189
- diagnostics.push(`duplicate research_started for session ${event.sessionId}`);
190
- continue;
191
- }
192
- run = {
193
- schemaVersion: DEEP_RESEARCH_RUN_SCHEMA_VERSION,
194
- sessionId: event.sessionId,
195
- objective: event.objective,
196
- scopeLevel: event.scopeLevel,
197
- status: 'active',
198
- stage: 'knowledge_base',
199
- round: 0,
200
- createdAt: event.ts,
201
- updatedAt: event.ts,
202
- artifacts: [],
203
- checklist: defaultDeepResearchChecklist(event.ts),
204
- steps: [],
205
- reportSections: defaultReportSections(event.ts),
206
- checkpoints: [],
207
- };
208
- continue;
209
- }
210
- if (!run) {
211
- diagnostics.push(`${event.type} appeared before research_started`);
212
- continue;
213
- }
214
- if (event.sessionId !== run.sessionId) {
215
- diagnostics.push(`${event.type} belongs to another session`);
216
- continue;
217
- }
218
- if (run.status === 'completed') {
219
- diagnostics.push(`${event.type} appeared after research_completed`);
220
- continue;
221
- }
222
- switch (event.type) {
223
- case 'research_artifact_recorded': {
224
- if (run.artifacts.length >= DEEP_RESEARCH_ARTIFACTS_MAX) {
225
- diagnostics.push(`deep research artifact cap ${DEEP_RESEARCH_ARTIFACTS_MAX} exceeded`);
226
- break;
227
- }
228
- const artifact = event.artifact;
229
- if (artifactIds.has(artifact.artifactId)) {
230
- diagnostics.push(`duplicate research artifact ${artifact.artifactId}`);
231
- break;
232
- }
233
- const sourceDiagnostic = validateSourceReferences(artifact, run.artifacts);
234
- if (sourceDiagnostic) {
235
- diagnostics.push(sourceDiagnostic);
236
- break;
237
- }
238
- if (artifact.role === 'report_section') {
239
- const currentSection = run.reportSections.find((section) => section.key === artifact.reportSectionKey);
240
- if (currentSection?.status === 'completed' &&
241
- artifact.reportSectionStatus === 'drafted') {
242
- diagnostics.push(`report section ${artifact.reportSectionKey} cannot regress to drafted`);
243
- break;
244
- }
245
- }
246
- artifactIds.add(artifact.artifactId);
247
- const reportSections = artifact.role === 'report_section'
248
- ? applyReportSectionArtifact(run.reportSections, artifact)
249
- : run.reportSections;
250
- run = {
251
- ...run,
252
- artifacts: [
253
- ...run.artifacts,
254
- { ...artifact, sourceArtifactIds: [...artifact.sourceArtifactIds] },
255
- ],
256
- reportSections,
257
- updatedAt: Math.max(run.updatedAt, event.ts),
258
- };
259
- break;
260
- }
261
- case 'research_checklist_updated': {
262
- const item = event.item;
263
- const current = run.checklist.find((candidate) => candidate.itemId === item.itemId);
264
- if (!current || current.title !== item.title) {
265
- diagnostics.push(`research checklist references unknown item ${item.itemId}`);
266
- break;
267
- }
268
- if ((current.status === 'completed' || current.status === 'skipped') &&
269
- current.status !== item.status) {
270
- diagnostics.push(`research checklist item ${item.itemId} is already terminal`);
271
- break;
272
- }
273
- const missingArtifact = item.evidenceArtifactIds.find((id) => !artifactIds.has(id));
274
- if (missingArtifact) {
275
- diagnostics.push(`research checklist item ${item.itemId} references unknown artifact ${missingArtifact}`);
276
- break;
277
- }
278
- if (item.status === 'completed' && item.evidenceArtifactIds.length === 0) {
279
- diagnostics.push(`completed research checklist item ${item.itemId} requires evidence`);
280
- break;
281
- }
282
- if (item.status === 'blocked' && !item.blockedReason) {
283
- diagnostics.push(`blocked research checklist item ${item.itemId} requires a reason`);
284
- break;
285
- }
286
- const checklist = run.checklist.map((candidate) => candidate.itemId === item.itemId ? cloneChecklistItem(item) : candidate);
287
- run = {
288
- ...run,
289
- status: checklist.some((candidate) => candidate.status === 'blocked')
290
- ? 'blocked'
291
- : 'active',
292
- checklist,
293
- updatedAt: Math.max(run.updatedAt, event.ts),
294
- };
295
- break;
296
- }
297
- case 'research_step_recorded': {
298
- if (run.steps.length >= DEEP_RESEARCH_STEPS_MAX) {
299
- diagnostics.push(`deep research step cap ${DEEP_RESEARCH_STEPS_MAX} exceeded`);
300
- break;
301
- }
302
- const step = event.step;
303
- if (stepIds.has(step.stepId)) {
304
- diagnostics.push(`duplicate research step ${step.stepId}`);
305
- break;
306
- }
307
- const missingEvidence = step.evidenceArtifactIds.find((id) => !artifactIds.has(id));
308
- if (missingEvidence) {
309
- diagnostics.push(`research step ${step.stepId} references unknown artifact ${missingEvidence}`);
310
- break;
311
- }
312
- const recordedArtifacts = run.artifacts;
313
- const invalidInspectedSource = step.inspectedRefs.find((ref) => {
314
- if (!ref.sourceArtifactId)
315
- return false;
316
- return (recordedArtifacts.find((artifact) => artifact.artifactId === ref.sourceArtifactId)
317
- ?.role !== 'source');
318
- });
319
- if (invalidInspectedSource?.sourceArtifactId) {
320
- diagnostics.push(`research step ${step.stepId} references non-source artifact ${invalidInspectedSource.sourceArtifactId}`);
321
- break;
322
- }
323
- if (step.status === 'completed' && step.evidenceArtifactIds.length === 0) {
324
- diagnostics.push(`completed research step ${step.stepId} requires evidence artifacts`);
325
- break;
326
- }
327
- if (step.status === 'blocked' && !step.blockedReason) {
328
- diagnostics.push(`blocked research step ${step.stepId} requires a reason`);
329
- break;
330
- }
331
- stepIds.add(step.stepId);
332
- run = {
333
- ...run,
334
- status: step.status === 'blocked' ? 'blocked' : run.status,
335
- steps: [...run.steps, cloneStep(step)],
336
- updatedAt: Math.max(run.updatedAt, event.ts),
337
- };
338
- break;
339
- }
340
- case 'research_checkpoint_recorded': {
341
- if (run.checkpoints.length >= DEEP_RESEARCH_CHECKPOINTS_MAX) {
342
- diagnostics.push(`deep research checkpoint cap ${DEEP_RESEARCH_CHECKPOINTS_MAX} exceeded`);
343
- break;
344
- }
345
- const checkpoint = event.checkpoint;
346
- if (checkpointIds.has(checkpoint.checkpointId)) {
347
- diagnostics.push(`duplicate research checkpoint ${checkpoint.checkpointId}`);
348
- break;
349
- }
350
- if (checkpoint.round < run.round) {
351
- diagnostics.push(`research round regressed from ${run.round} to ${checkpoint.round}`);
352
- break;
353
- }
354
- if (run.stage === 'report_writing' && checkpoint.stage === 'knowledge_base') {
355
- diagnostics.push('deep research stage cannot regress from report_writing to knowledge_base');
356
- break;
357
- }
358
- const missingArtifact = checkpoint.artifactIds.find((id) => !artifactIds.has(id));
359
- if (missingArtifact) {
360
- diagnostics.push(`checkpoint references unknown artifact ${missingArtifact}`);
361
- break;
362
- }
363
- checkpointIds.add(checkpoint.checkpointId);
364
- run = {
365
- ...run,
366
- status: checkpoint.status,
367
- stage: checkpoint.stage,
368
- round: checkpoint.round,
369
- checkpoints: [...run.checkpoints, cloneCheckpoint(checkpoint)],
370
- updatedAt: Math.max(run.updatedAt, event.ts),
371
- };
372
- break;
373
- }
374
- case 'research_completed': {
375
- const report = run.artifacts.find((artifact) => artifact.artifactId === event.reportArtifactId);
376
- if (!report || report.role !== 'report') {
377
- diagnostics.push(`research_completed references missing report artifact ${event.reportArtifactId}`);
378
- break;
379
- }
380
- if (!run.artifacts.some((artifact) => artifact.role === 'source')) {
381
- diagnostics.push('research_completed requires at least one archived source artifact');
382
- break;
383
- }
384
- const handoffArtifact = run.artifacts.find((artifact) => artifact.artifactId === event.handoff.artifactId);
385
- if (!handoffArtifact || handoffArtifact.role !== 'handoff') {
386
- diagnostics.push(`research_completed references missing handoff artifact ${event.handoff.artifactId}`);
387
- break;
388
- }
389
- const incompleteChecklist = run.checklist.find((item) => item.status !== 'completed' && item.status !== 'skipped');
390
- if (incompleteChecklist) {
391
- diagnostics.push(`research_completed requires checklist item ${incompleteChecklist.itemId} to be settled`);
392
- break;
393
- }
394
- const incompleteSection = run.reportSections.find((section) => section.status !== 'completed');
395
- if (incompleteSection) {
396
- diagnostics.push(`research_completed requires report section ${incompleteSection.key}`);
397
- break;
398
- }
399
- run = {
400
- ...run,
401
- status: 'completed',
402
- stage: 'completed',
403
- reportArtifactId: event.reportArtifactId,
404
- handoff: cloneHandoff(event.handoff),
405
- completedAt: event.ts,
406
- updatedAt: Math.max(run.updatedAt, event.ts),
407
- };
408
- break;
409
- }
410
- }
411
- }
412
- return { ...(run ? { run } : {}), diagnostics };
413
- }
414
- function validateSourceReferences(artifact, existing) {
415
- if (artifact.role === 'source') {
416
- if (!artifact.locator)
417
- return `source artifact ${artifact.artifactId} requires a locator`;
418
- return artifact.sourceArtifactIds.length === 0
419
- ? undefined
420
- : `source artifact ${artifact.artifactId} cannot cite another source artifact`;
421
- }
422
- if (artifact.sourceArtifactIds.length === 0) {
423
- return `${artifact.role} artifact ${artifact.artifactId} requires source artifact references`;
424
- }
425
- const invalid = artifact.sourceArtifactIds.find((id) => {
426
- const source = existing.find((item) => item.artifactId === id);
427
- return source?.role !== 'source';
428
- });
429
- return invalid
430
- ? `${artifact.role} artifact ${artifact.artifactId} references non-source artifact ${invalid}`
431
- : undefined;
432
- }
433
- function isDeepResearchArtifactRef(value) {
434
- if (!isRecord(value))
435
- return false;
436
- if (!isStableId(value.artifactId) ||
437
- !isDeepResearchArtifactRole(value.role) ||
438
- !isBoundedText(value.name, DEEP_RESEARCH_ARTIFACT_NAME_MAX_CHARS) ||
439
- !(value.summary === undefined ||
440
- isBoundedText(value.summary, DEEP_RESEARCH_CHECKPOINT_TEXT_MAX_CHARS)) ||
441
- !isFiniteNumber(value.createdAt) ||
442
- !(value.locator === undefined || isBoundedText(value.locator, DEEP_RESEARCH_LOCATOR_MAX_CHARS)) ||
443
- typeof value.contentHash !== 'string' ||
444
- !/^sha256:[a-f0-9]{64}$/.test(value.contentHash) ||
445
- !isStableIdArray(value.sourceArtifactIds, DEEP_RESEARCH_REFS_MAX)) {
446
- return false;
447
- }
448
- if (value.role === 'report_section') {
449
- return (isDeepResearchReportSectionKey(value.reportSectionKey) &&
450
- (value.reportSectionStatus === 'drafted' || value.reportSectionStatus === 'completed'));
451
- }
452
- return value.reportSectionKey === undefined && value.reportSectionStatus === undefined;
453
- }
454
- function isDeepResearchChecklistItem(value) {
455
- return (isRecord(value) &&
456
- isStableId(value.itemId) &&
457
- isBoundedText(value.title, DEEP_RESEARCH_ARTIFACT_NAME_MAX_CHARS) &&
458
- isDeepResearchChecklistStatus(value.status) &&
459
- isStableIdArray(value.evidenceArtifactIds, DEEP_RESEARCH_REFS_MAX) &&
460
- (value.blockedReason === undefined ||
461
- isBoundedText(value.blockedReason, DEEP_RESEARCH_CHECKPOINT_TEXT_MAX_CHARS)) &&
462
- (value.status === 'blocked'
463
- ? value.blockedReason !== undefined
464
- : value.blockedReason === undefined) &&
465
- isFiniteNumber(value.updatedAt));
466
- }
467
- function isDeepResearchStep(value) {
468
- return (isRecord(value) &&
469
- isStableId(value.stepId) &&
470
- isDeepResearchStepKind(value.kind) &&
471
- isDeepResearchStepStatus(value.status) &&
472
- isBoundedText(value.objective, DEEP_RESEARCH_STEP_TEXT_MAX_CHARS) &&
473
- isBoundedText(value.summary, DEEP_RESEARCH_STEP_TEXT_MAX_CHARS) &&
474
- isBoundedTextArray(value.roots, DEEP_RESEARCH_STEP_LIST_ITEMS_MAX, DEEP_RESEARCH_LOCATOR_MAX_CHARS) &&
475
- (value.kind !== 'local_exploration' || value.roots.length > 0) &&
476
- isBoundedTextArray(value.keywords, DEEP_RESEARCH_STEP_LIST_ITEMS_MAX, DEEP_RESEARCH_CHECKPOINT_ITEM_MAX_CHARS) &&
477
- (value.kind !== 'web_research' || value.keywords.length > 0) &&
478
- isBoundedTextArray(value.ignoredPaths, DEEP_RESEARCH_STEP_LIST_ITEMS_MAX, DEEP_RESEARCH_LOCATOR_MAX_CHARS) &&
479
- isBoundedText(value.stoppingCondition, DEEP_RESEARCH_STEP_TEXT_MAX_CHARS) &&
480
- isBoundedText(value.expectedEvidence, DEEP_RESEARCH_STEP_TEXT_MAX_CHARS) &&
481
- isStableIdArray(value.evidenceArtifactIds, DEEP_RESEARCH_REFS_MAX) &&
482
- Array.isArray(value.inspectedRefs) &&
483
- value.inspectedRefs.length <= DEEP_RESEARCH_INSPECTED_REFS_MAX &&
484
- value.inspectedRefs.every(isDeepResearchInspectedRef) &&
485
- isStableIdArray(value.workerRunIds, DEEP_RESEARCH_REFS_MAX) &&
486
- (value.blockedReason === undefined ||
487
- isBoundedText(value.blockedReason, DEEP_RESEARCH_STEP_TEXT_MAX_CHARS)) &&
488
- (value.status === 'blocked'
489
- ? value.blockedReason !== undefined
490
- : value.blockedReason === undefined) &&
491
- isFiniteNumber(value.createdAt));
492
- }
493
- function isDeepResearchInspectedRef(value) {
494
- return (isRecord(value) &&
495
- typeof value.kind === 'string' &&
496
- DEEP_RESEARCH_INSPECTED_REF_KINDS.includes(value.kind) &&
497
- isBoundedText(value.locator, DEEP_RESEARCH_LOCATOR_MAX_CHARS) &&
498
- (value.label === undefined ||
499
- isBoundedText(value.label, DEEP_RESEARCH_CHECKPOINT_ITEM_MAX_CHARS)) &&
500
- (value.sourceArtifactId === undefined || isStableId(value.sourceArtifactId)));
501
- }
502
- function isDeepResearchHandoff(value) {
503
- return (isRecord(value) &&
504
- isStableId(value.artifactId) &&
505
- isBoundedTextArray(value.implementationTasks, DEEP_RESEARCH_CHECKPOINT_ITEMS_MAX, DEEP_RESEARCH_CHECKPOINT_ITEM_MAX_CHARS) &&
506
- value.implementationTasks.length > 0 &&
507
- isBoundedTextArray(value.recommendedIssues, DEEP_RESEARCH_CHECKPOINT_ITEMS_MAX, DEEP_RESEARCH_CHECKPOINT_ITEM_MAX_CHARS) &&
508
- isBoundedTextArray(value.recommendedPullRequests, DEEP_RESEARCH_CHECKPOINT_ITEMS_MAX, DEEP_RESEARCH_CHECKPOINT_ITEM_MAX_CHARS) &&
509
- value.recommendedIssues.length + value.recommendedPullRequests.length > 0 &&
510
- isBoundedTextArray(value.verificationCommands, DEEP_RESEARCH_CHECKPOINT_ITEMS_MAX, DEEP_RESEARCH_CHECKPOINT_ITEM_MAX_CHARS) &&
511
- value.verificationCommands.length > 0);
512
- }
513
- function isDeepResearchCheckpoint(value) {
514
- return (isRecord(value) &&
515
- isStableId(value.checkpointId) &&
516
- Number.isSafeInteger(value.round) &&
517
- value.round >= 1 &&
518
- isDeepResearchActiveStage(value.stage) &&
519
- (value.status === 'active' || value.status === 'blocked') &&
520
- isBoundedText(value.summary, DEEP_RESEARCH_CHECKPOINT_TEXT_MAX_CHARS) &&
521
- isBoundedTextArray(value.openQuestions, DEEP_RESEARCH_CHECKPOINT_ITEMS_MAX, DEEP_RESEARCH_CHECKPOINT_ITEM_MAX_CHARS) &&
522
- isBoundedTextArray(value.nextSteps, DEEP_RESEARCH_CHECKPOINT_ITEMS_MAX, DEEP_RESEARCH_CHECKPOINT_ITEM_MAX_CHARS) &&
523
- isStableIdArray(value.taskIds, DEEP_RESEARCH_REFS_MAX) &&
524
- isStableIdArray(value.artifactIds, DEEP_RESEARCH_REFS_MAX) &&
525
- isFiniteNumber(value.createdAt));
526
- }
527
- function isEventRefs(value) {
528
- if (value === undefined)
529
- return true;
530
- if (!isRecord(value))
531
- return false;
532
- const keys = Object.keys(value);
533
- if (keys.some((key) => !['runId', 'turnId', 'toolCallId'].includes(key)))
534
- return false;
535
- return [value.runId, value.turnId, value.toolCallId].every((item) => item === undefined || isBoundedReference(item));
536
- }
537
- function isBoundedReference(value) {
538
- return typeof value === 'string' && value.length >= 1 && value.length <= 512;
539
- }
540
- function isStableId(value) {
541
- return (typeof value === 'string' &&
542
- value.length >= 1 &&
543
- value.length <= 128 &&
544
- /^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(value) &&
545
- redactSecrets(value) === value);
546
- }
547
- function isStableIdArray(value, max) {
548
- return (Array.isArray(value) &&
549
- value.length <= max &&
550
- new Set(value).size === value.length &&
551
- value.every(isStableId));
552
- }
553
- function isBoundedText(value, max) {
554
- return typeof value === 'string' && value.trim().length > 0 && Array.from(value).length <= max;
555
- }
556
- function isBoundedTextArray(value, maxItems, maxChars) {
557
- return (Array.isArray(value) &&
558
- value.length <= maxItems &&
559
- value.every((item) => isBoundedText(item, maxChars)));
560
- }
561
- function cloneCheckpoint(checkpoint) {
562
- return {
563
- ...checkpoint,
564
- openQuestions: [...checkpoint.openQuestions],
565
- nextSteps: [...checkpoint.nextSteps],
566
- taskIds: [...checkpoint.taskIds],
567
- artifactIds: [...checkpoint.artifactIds],
568
- };
569
- }
570
- function defaultDeepResearchChecklist(ts) {
571
- return DEEP_RESEARCH_DEFAULT_CHECKLIST.map((item) => ({
572
- ...item,
573
- status: 'pending',
574
- evidenceArtifactIds: [],
575
- updatedAt: ts,
576
- }));
577
- }
578
- function defaultReportSections(ts) {
579
- return DEEP_RESEARCH_REPORT_SECTION_KEYS.map((key) => ({
580
- key,
581
- status: 'pending',
582
- updatedAt: ts,
583
- }));
584
- }
585
- function applyReportSectionArtifact(sections, artifact) {
586
- if (artifact.role !== 'report_section' ||
587
- !artifact.reportSectionKey ||
588
- !artifact.reportSectionStatus) {
589
- return [...sections];
590
- }
591
- return sections.map((section) => section.key === artifact.reportSectionKey
592
- ? {
593
- key: section.key,
594
- status: artifact.reportSectionStatus,
595
- artifactId: artifact.artifactId,
596
- updatedAt: artifact.createdAt,
597
- }
598
- : section);
599
- }
600
- function cloneChecklistItem(item) {
601
- return {
602
- ...item,
603
- evidenceArtifactIds: [...item.evidenceArtifactIds],
604
- };
605
- }
606
- function cloneStep(step) {
607
- return {
608
- ...step,
609
- roots: [...step.roots],
610
- keywords: [...step.keywords],
611
- ignoredPaths: [...step.ignoredPaths],
612
- evidenceArtifactIds: [...step.evidenceArtifactIds],
613
- inspectedRefs: step.inspectedRefs.map((ref) => ({ ...ref })),
614
- workerRunIds: [...step.workerRunIds],
615
- };
616
- }
617
- function cloneHandoff(handoff) {
618
- return {
619
- ...handoff,
620
- implementationTasks: [...handoff.implementationTasks],
621
- recommendedIssues: [...handoff.recommendedIssues],
622
- recommendedPullRequests: [...handoff.recommendedPullRequests],
623
- verificationCommands: [...handoff.verificationCommands],
624
- };
625
- }