@orion-agents/orion-code 0.4.4 → 0.4.5

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 (51) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +4 -4
  3. package/README.zh-CN.md +4 -4
  4. package/dist/core/tool-artifacts.js +17 -4
  5. package/dist/framework/query.js +150 -16
  6. package/dist/framework/tool-state.d.ts +4 -0
  7. package/dist/harness/context-harness.d.ts +6 -2
  8. package/dist/harness/context-harness.js +221 -47
  9. package/dist/harness/contract.js +3 -1
  10. package/dist/harness/drift-guard.js +67 -17
  11. package/dist/harness/goal-verification.d.ts +11 -0
  12. package/dist/harness/goal-verification.js +62 -0
  13. package/dist/harness/ledger.js +16 -3
  14. package/dist/harness/state.js +3 -0
  15. package/dist/harness/task-checklist.d.ts +11 -1
  16. package/dist/harness/task-checklist.js +48 -4
  17. package/dist/harness/types.d.ts +10 -0
  18. package/dist/harness/verification.d.ts +11 -1
  19. package/dist/harness/verification.js +47 -2
  20. package/dist/runtime/agent-loop.js +4 -1
  21. package/dist/runtime/batch-read-service.js +21 -4
  22. package/dist/runtime/goal-runtime-coordinator.js +1 -0
  23. package/dist/runtime/product-orion-runtime.js +24 -2
  24. package/dist/runtime/task-context-recovery.js +21 -5
  25. package/dist/runtime/task-context-service.d.ts +3 -1
  26. package/dist/runtime/task-context-service.js +3 -0
  27. package/dist/runtime/workspace-verification.d.ts +2 -2
  28. package/dist/runtime/workspace-verification.js +24 -9
  29. package/dist/services/chat-completion-sse.d.ts +9 -0
  30. package/dist/services/chat-completion-sse.js +50 -0
  31. package/dist/services/compact/summary-generator.d.ts +1 -1
  32. package/dist/services/compact/summary-generator.js +12 -0
  33. package/dist/services/llm.d.ts +1 -1
  34. package/dist/services/llm.js +165 -292
  35. package/dist/services/provider-diagnostics.d.ts +1 -1
  36. package/dist/services/provider-diagnostics.js +7 -2
  37. package/dist/services/provider-resilience/error-classifier.d.ts +3 -0
  38. package/dist/services/provider-resilience/error-classifier.js +14 -0
  39. package/dist/tools/core/common.d.ts +0 -11
  40. package/dist/tools/core/common.js +0 -18
  41. package/dist/tools/core/edit-file.js +57 -86
  42. package/dist/tools/core/exec-command.js +61 -80
  43. package/dist/tools/core/grep.js +84 -24
  44. package/dist/tools/core/read-file.js +3 -2
  45. package/dist/tools/todo.d.ts +2 -2
  46. package/dist/tools/todo.js +13 -10
  47. package/dist/utils/utf8.d.ts +6 -0
  48. package/dist/utils/utf8.js +14 -0
  49. package/docs/cli-guide.md +7 -2
  50. package/npm-shrinkwrap.json +2 -2
  51. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -22,6 +22,14 @@ which is **not** a pass.
22
22
 
23
23
  ## [Unreleased]
24
24
 
25
+ ## [0.4.5] — UNRELEASED
26
+
27
+ - Recover stale checklist entries and keep path-scoped writes and verification separately accountable (#388, #389, #391, #392).
28
+ - Tie staged checks to Git index content, identify the exact failed check, and avoid repeating repair feedback for an unchanged failure (#390, #393, #402).
29
+ - Persist explicit live corrections to a Goal's required verification across turns and process restarts (#401).
30
+ - Fix fuzzy edit placement, retain failed command output, count actual grep matches, preserve bounded batch results, and report MCP tool failures (#394–#398).
31
+ - Detect incomplete provider streams and use deterministic fallback when a context summary is incomplete (#399, #400).
32
+
25
33
  ## [0.4.4] — UNRELEASED
26
34
 
27
35
  - Invalidate verification after shell or external edits. A matching fresh check is required to complete the task (#372).
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Local-first, goal-driven coding agent for the terminal (CLI/TUI).
4
4
 
5
- > v0.4.4 is a candidate for Goal recovery and Harness evidence fixes.
5
+ > v0.4.5 is a candidate for checklist, verification, and tool reliability fixes.
6
6
  > Web Workbench and desktop product surfaces are retired. Configuration is `orion.yaml`;
7
7
  > old-version data compatibility and migration are not part of this release.
8
8
  > A version number or local installation is not proof of release qualification or npm publication.
@@ -30,7 +30,7 @@ The exact package qualification floors are 22.12.0 / 24.0.0 / 26.0.0.
30
30
  Install a local candidate from the exact tested tarball, substituting its actual path:
31
31
 
32
32
  ```bash
33
- npm install -g /absolute/path/orion-agents-orion-code-0.4.4.tgz
33
+ npm install -g /absolute/path/orion-agents-orion-code-0.4.5.tgz
34
34
  orion --version
35
35
  orion doctor
36
36
  ```
@@ -38,7 +38,7 @@ orion doctor
38
38
  Only after npm publication has been separately verified, use the pinned registry install:
39
39
 
40
40
  ```bash
41
- npm install -g @orion-agents/orion-code@0.4.4
41
+ npm install -g @orion-agents/orion-code@0.4.5
42
42
  ```
43
43
 
44
44
  From a checkout of the candidate branch:
@@ -108,7 +108,7 @@ npm run format:check
108
108
  npm run build
109
109
  npm run test:coverage -- --runInBand
110
110
  npm run test:harness-confluence
111
- npm run release:check -- --expected-version 0.4.4
111
+ npm run release:check -- --expected-version 0.4.5
112
112
  ```
113
113
 
114
114
  Qualification binds one exact tarball's SHA-256 and source identity to installed CLI, TUI, terminal,
package/README.zh-CN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  面向终端、本地优先的目标驱动 Coding Agent(CLI/TUI)。
4
4
 
5
- > v0.4.4 是 Goal 续跑与 Harness 证据修复的候选版本。
5
+ > v0.4.5 是清单、验证回执和工具可靠性修复的候选版本。
6
6
  > Web Workbench 与桌面产品链已退役,全局配置统一为 `orion.yaml`。
7
7
  > 源码版本号、本地可运行、候选包验收与 npm 发布分别记录,不互相替代。
8
8
 
@@ -28,7 +28,7 @@
28
28
  本地候选使用实际被测的同一包安装,请替换为实际路径:
29
29
 
30
30
  ```bash
31
- npm install -g /absolute/path/orion-agents-orion-code-0.4.4.tgz
31
+ npm install -g /absolute/path/orion-agents-orion-code-0.4.5.tgz
32
32
  orion --version
33
33
  orion doctor
34
34
  ```
@@ -36,7 +36,7 @@ orion doctor
36
36
  仅在另行确认 npm 已发布后,固定 registry 版本安装:
37
37
 
38
38
  ```bash
39
- npm install -g @orion-agents/orion-code@0.4.4
39
+ npm install -g @orion-agents/orion-code@0.4.5
40
40
  ```
41
41
 
42
42
  从候选分支源码运行:
@@ -104,7 +104,7 @@ npm run format:check
104
104
  npm run build
105
105
  npm run test:coverage -- --runInBand
106
106
  npm run test:harness-confluence
107
- npm run release:check -- --expected-version 0.4.4
107
+ npm run release:check -- --expected-version 0.4.5
108
108
  ```
109
109
 
110
110
  准出需绑定同一 tarball 的 SHA-256 与源码身份,在三个 Node floor 验证安装后的 CLI、TUI、
@@ -105,7 +105,13 @@ function storeArtifact(projectPath, toolName, output, outputBytes) {
105
105
  return null;
106
106
  const safeToolName = sanitizeArtifactToolName(toolName);
107
107
  const id = `${safeToolName}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
108
- const artifactDir = path.resolve(getArtifactDir(projectPath));
108
+ let artifactDir;
109
+ try {
110
+ artifactDir = path.resolve(getArtifactDir(projectPath));
111
+ }
112
+ catch {
113
+ return null;
114
+ }
109
115
  const artifactPath = path.resolve(artifactDir, `${id}.txt`);
110
116
  if (!artifactPath.startsWith(`${artifactDir}${path.sep}`)) {
111
117
  return null;
@@ -203,9 +209,16 @@ function truncateForContext(output, maxBytes = 4096) {
203
209
  return output;
204
210
  const half = Math.floor(maxBytes / 2);
205
211
  const buf = Buffer.from(output, 'utf8');
206
- const head = buf.subarray(0, half).toString('utf8');
207
- const tail = buf.subarray(buf.length - half).toString('utf8');
208
- return `${head}\n\n[... ${byteLen - maxBytes} bytes truncated, ${byteLen}B total — see artifact for full output]\n\n${tail}`;
212
+ let headEnd = half;
213
+ let tailStart = buf.length - half;
214
+ // Keep both cuts on UTF-8 boundaries, inside their respective byte limits.
215
+ while (headEnd > 0 && (buf[headEnd] & 0xc0) === 0x80)
216
+ headEnd--;
217
+ while (tailStart < buf.length && (buf[tailStart] & 0xc0) === 0x80)
218
+ tailStart++;
219
+ const head = buf.subarray(0, headEnd).toString('utf8');
220
+ const tail = buf.subarray(tailStart).toString('utf8');
221
+ return `${head}\n\n[... ${tailStart - headEnd} bytes truncated, ${byteLen}B total — see artifact for full output]\n\n${tail}`;
209
222
  }
210
223
  /**
211
224
  * Clean up expired artifacts (older than 24h).
@@ -17,6 +17,7 @@ exports.createFailedLoopStats = createFailedLoopStats;
17
17
  exports.query = query;
18
18
  const llm_1 = require("../services/llm");
19
19
  const provider_diagnostics_1 = require("../services/provider-diagnostics");
20
+ const tool_artifacts_1 = require("../core/tool-artifacts");
20
21
  const tool_1 = require("./tool");
21
22
  const auto_compact_1 = require("../services/compact/auto-compact");
22
23
  const fingerprint_1 = require("../services/compact/fingerprint");
@@ -452,7 +453,92 @@ function truncateModelField(text, maxSerializedBytes) {
452
453
  }
453
454
  return result;
454
455
  }
455
- function summarizeModelVisibleToolResult(executed, maxBytes, budgetRemainingBytes, budgetLimitBytes) {
456
+ function parseBatchPreviewSteps(output) {
457
+ const batch = parseRecord(output);
458
+ if (batch?.version !== 1 ||
459
+ !Array.isArray(batch.steps) ||
460
+ batch.steps.length === 0 ||
461
+ batch.steps.length > 8)
462
+ return;
463
+ const steps = [];
464
+ for (const [index, step] of batch.steps.entries()) {
465
+ if (!isRecord(step) ||
466
+ step.index !== index + 1 ||
467
+ typeof step.tool !== 'string' ||
468
+ !/^[a-z_]{1,32}$/u.test(step.tool) ||
469
+ (step.state !== 'completed' && step.state !== 'skipped') ||
470
+ typeof step.success !== 'boolean' ||
471
+ typeof step.output !== 'string')
472
+ return;
473
+ const terminal = typeof step.terminal === 'string' &&
474
+ ['completed', 'failed', 'interrupted', 'indeterminate'].includes(step.terminal)
475
+ ? step.terminal
476
+ : undefined;
477
+ steps.push({
478
+ index: step.index,
479
+ tool: step.tool,
480
+ state: step.state,
481
+ success: step.success,
482
+ terminal,
483
+ output: step.output,
484
+ truncated: step.truncated === true,
485
+ });
486
+ }
487
+ return steps;
488
+ }
489
+ function projectBatchPreview(steps, compactEnvelope, minimalEnvelope, maxBytes) {
490
+ const succeeded = steps.filter(step => step.state === 'completed' && step.success).length;
491
+ const skipped = steps.filter(step => step.state === 'skipped').length;
492
+ const failed = steps.length - succeeded - skipped;
493
+ const makePreview = (childBytes) => compactEnvelope(JSON.stringify({
494
+ version: 1,
495
+ success: failed === 0 && skipped === 0,
496
+ succeeded,
497
+ failed,
498
+ skipped,
499
+ steps: steps.map(step => {
500
+ const output = takeUtf8Prefix(step.output, childBytes);
501
+ return {
502
+ ...step,
503
+ output,
504
+ truncated: step.truncated || output.length < step.output.length,
505
+ };
506
+ }),
507
+ }));
508
+ let preview = makePreview(0);
509
+ if (byteLength(preview) > maxBytes) {
510
+ // The recovery floor normally fits even eight object rows. Keep the same
511
+ // child identities and terminal states for callers with a smaller limit.
512
+ const output = JSON.stringify({
513
+ version: 1,
514
+ stepFields: ['index', 'status', 'truncated'],
515
+ steps: steps.map(step => [
516
+ step.index,
517
+ step.state === 'skipped'
518
+ ? 'skipped'
519
+ : (step.terminal ?? (step.success ? 'completed' : 'failed')),
520
+ step.truncated || step.output.length > 0,
521
+ ]),
522
+ });
523
+ const compact = compactEnvelope(output);
524
+ return byteLength(compact) <= maxBytes ? compact : minimalEnvelope(output);
525
+ }
526
+ let low = 1;
527
+ let high = maxBytes;
528
+ while (low <= high) {
529
+ const middle = Math.floor((low + high) / 2);
530
+ const candidate = makePreview(middle);
531
+ if (byteLength(candidate) <= maxBytes) {
532
+ preview = candidate;
533
+ low = middle + 1;
534
+ }
535
+ else {
536
+ high = middle - 1;
537
+ }
538
+ }
539
+ return preview;
540
+ }
541
+ function summarizeModelVisibleToolResult(executed, maxBytes, budgetRemainingBytes, budgetLimitBytes, projectPath) {
456
542
  const rawBytes = byteLength(executed.result);
457
543
  const fullOutputBytes = executed.outputBytes ?? rawBytes;
458
544
  const envelope = (0, tool_serializer_1.parseToolResultEnvelope)(executed.result);
@@ -476,6 +562,44 @@ function summarizeModelVisibleToolResult(executed, maxBytes, budgetRemainingByte
476
562
  if (byteLength(fullResult) <= maxBytes) {
477
563
  return { result: fullResult, bytes: byteLength(fullResult), summarizedBytes: 0 };
478
564
  }
565
+ if (executed.prepared.tc.function.name === 'batch_read') {
566
+ const steps = parseBatchPreviewSteps(output);
567
+ if (steps) {
568
+ const existing = executed.artifactRef;
569
+ const artifact = existing &&
570
+ /^[a-z0-9_-]{1,64}$/iu.test(existing.id) &&
571
+ Number.isSafeInteger(existing.outputBytes)
572
+ ? existing
573
+ : (0, tool_artifacts_1.storeArtifact)(projectPath, 'batch_read', output, byteLength(output));
574
+ const artifactRef = artifact
575
+ ? { id: artifact.id, outputBytes: artifact.outputBytes }
576
+ : undefined;
577
+ const minimal = { success: executed.success, artifactRef };
578
+ const compactSummary = summary ? truncateModelField(summary, 128) : undefined;
579
+ const compactError = rawError ? truncateModelField(rawError, 128) : undefined;
580
+ const result = projectBatchPreview(steps, compactOutput => (0, tool_serializer_1.serializeToolResult)({
581
+ ...minimal,
582
+ output: compactOutput,
583
+ outputBytes: fullOutputBytes,
584
+ summary: compactSummary,
585
+ error: compactError,
586
+ metadata: {
587
+ modelVisibleCompressed: true,
588
+ originalResultBytes: rawBytes,
589
+ ...budgetMetadata,
590
+ },
591
+ }), compactOutput => (0, tool_serializer_1.serializeToolResult)({
592
+ ...minimal,
593
+ output: compactOutput,
594
+ metadata: {
595
+ modelVisibleCompressed: true,
596
+ budgetExhausted: budgetMetadata.budgetExhausted,
597
+ },
598
+ }), maxBytes);
599
+ const bytes = byteLength(result);
600
+ return { result, bytes, summarizedBytes: Math.max(0, fullOutputBytes - bytes), artifactRef };
601
+ }
602
+ }
479
603
  // Keep a real excerpt, status and a budget signal even after exhaustion. An
480
604
  // untrusted tool's arbitrarily large metadata must not displace the excerpt.
481
605
  const compactError = rawError ? truncateModelField(rawError, 192) : undefined;
@@ -983,23 +1107,29 @@ async function* query(params) {
983
1107
  return;
984
1108
  }
985
1109
  const visibleContent = (0, terminal_text_1.hasVisibleAssistantText)(response.content) ? response.content : '';
986
- if (response.finishReason === 'length' || response.finishReason === 'content_filter') {
1110
+ if (response.finishReason === 'length' ||
1111
+ response.finishReason === 'content_filter' ||
1112
+ response.finishReason === 'incomplete') {
987
1113
  if (visibleContent) {
988
1114
  appendMessage({ role: 'assistant', content: visibleContent });
989
1115
  if (holdAssistant)
990
1116
  streamCallbacks?.onChunk?.(visibleContent);
991
1117
  yield { type: 'message', role: 'assistant', content: visibleContent };
992
1118
  }
993
- stats.providerStop =
994
- response.finishReason === 'length'
995
- ? {
996
- code: 'provider_output_limit',
997
- message: 'The provider reached its output token limit. Continue with a narrower request.',
998
- }
999
- : {
1000
- code: 'provider_content_filter',
1001
- message: 'The provider stopped generation at its content filter.',
1002
- };
1119
+ stats.providerStop = {
1120
+ length: {
1121
+ code: 'provider_output_limit',
1122
+ message: 'The provider reached its output token limit. Continue with a narrower request.',
1123
+ },
1124
+ content_filter: {
1125
+ code: 'provider_content_filter',
1126
+ message: 'The provider stopped generation at its content filter.',
1127
+ },
1128
+ incomplete: {
1129
+ code: 'provider_stream_incomplete',
1130
+ message: 'The provider stream ended with an incomplete response. Retry the request.',
1131
+ },
1132
+ }[response.finishReason];
1003
1133
  yield attachCompactCommit({
1004
1134
  type: 'complete',
1005
1135
  content: stats.providerStop.message,
@@ -1080,7 +1210,7 @@ async function* query(params) {
1080
1210
  const { tc, args, attemptId } = prepared;
1081
1211
  const remainingModelVisibleBytes = Math.max(0, loopBudget.maxModelVisibleToolBytes - stats.modelVisibleToolBytes);
1082
1212
  const visibilityFloor = Math.min(exports.MIN_MODEL_VISIBLE_TOOL_RESULT_BYTES, maxModelVisibleToolResultBytes);
1083
- const modelVisible = summarizeModelVisibleToolResult(executed, Math.max(visibilityFloor, Math.min(maxModelVisibleToolResultBytes, remainingModelVisibleBytes)), remainingModelVisibleBytes, loopBudget.maxModelVisibleToolBytes);
1213
+ const modelVisible = summarizeModelVisibleToolResult(executed, Math.max(visibilityFloor, Math.min(maxModelVisibleToolResultBytes, remainingModelVisibleBytes)), remainingModelVisibleBytes, loopBudget.maxModelVisibleToolBytes, params.toolContext?.cwd);
1084
1214
  stats.toolResultBytes += executed.outputBytes ?? byteLength(executed.result);
1085
1215
  stats.modelVisibleToolBytes += modelVisible.bytes;
1086
1216
  stats.summarizedBytes += modelVisible.summarizedBytes;
@@ -1161,7 +1291,7 @@ async function* query(params) {
1161
1291
  modelVisibleResult: modelVisible.result,
1162
1292
  duration: executed.duration,
1163
1293
  success: executed.success,
1164
- artifactRef: executed.artifactRef,
1294
+ artifactRef: modelVisible.artifactRef ?? executed.artifactRef,
1165
1295
  externalAssertion: executed.externalAssertion,
1166
1296
  error: executed.error,
1167
1297
  summary: executed.summary,
@@ -1278,8 +1408,12 @@ async function* query(params) {
1278
1408
  if (completionGate && !completionGate.canComplete) {
1279
1409
  const rejectedState = JSON.stringify([
1280
1410
  completionGate.missing,
1281
- completionGate.stopDecision?.criterionStates,
1282
- completionGate.stopDecision?.evidenceRefs,
1411
+ completionGate.progressDelta?.workspaceStateHash,
1412
+ completionGate.criterionResults?.map(result => [
1413
+ result.criterionId,
1414
+ result.status,
1415
+ result.verificationProblems,
1416
+ ]),
1283
1417
  ]);
1284
1418
  if (rejectedCompletionStates.has(rejectedState)) {
1285
1419
  const missing = completionGate.missing?.length
@@ -11,6 +11,10 @@ export interface TodoItem {
11
11
  activeForm: string;
12
12
  verification?: LocalVerificationKind[];
13
13
  }
14
+ export interface TodoWriteAdjustment {
15
+ todos: TodoItem[];
16
+ warnings: string[];
17
+ }
14
18
  export interface ToolState {
15
19
  todos: TodoItem[];
16
20
  /** v0.2.24 — Goal target mode (set by create_goal / update_goal) */
@@ -1,5 +1,5 @@
1
1
  import type { LLMResponse, Message } from '../services/llm';
2
- import type { TodoItem } from '../framework/tool-state';
2
+ import type { TodoItem, TodoWriteAdjustment } from '../framework/tool-state';
3
3
  import { type PromptAssemblyOptions } from './assembler';
4
4
  import { type CreateTurnSummaryInput } from './turn-summary';
5
5
  import type { CompletionGateResult, CapabilityProfileInput, ContextCapsule, DriftCheckResult, HarnessConfig, HarnessProgressState, HarnessState, IntentUpdate, ProgressDelta, TaskPlanStop, TaskTodoObservation, TaskWorkspaceAction, ToolResultObservation, TurnSummary } from './types';
@@ -25,6 +25,7 @@ export declare class HarnessKernel {
25
25
  private taskChecklistTargets;
26
26
  private verificationWorkspace?;
27
27
  private goalTaskId?;
28
+ private goalVerificationBlocker?;
28
29
  private taskTodos;
29
30
  private reportedTaskBlocker?;
30
31
  private readonly taskTodoReceipts;
@@ -47,6 +48,7 @@ export declare class HarnessKernel {
47
48
  constructor(options: ContextHarnessOptions);
48
49
  updateContractFromUserInput(input: string, goalTaskId?: string): IntentUpdate | undefined;
49
50
  classifyIntent(input: string): IntentUpdate;
51
+ observeGoalSteering(input: string, goalId: string): void;
50
52
  activeTaskTodo(): string | undefined;
51
53
  hasTaskTodos(): boolean;
52
54
  missingExecutionChecklist(action?: TaskWorkspaceAction): string | undefined;
@@ -56,9 +58,11 @@ export declare class HarnessKernel {
56
58
  private deferTaskTodos;
57
59
  requiresVerification(): boolean;
58
60
  recordTaskTodoReceipt(step: string, observation: TaskTodoObservation): void;
59
- updateTaskTodos(todos: TodoItem[], blockedReason?: string): string | undefined;
61
+ updateTaskTodos(todos: TodoItem[], blockedReason?: string): TodoWriteAdjustment | string | undefined;
60
62
  private taskTodoId;
61
63
  private missingTodoEvidence;
64
+ private formatTodoCheck;
65
+ private diffTodoCheckHint;
62
66
  updateCapabilityProfile(input: CapabilityProfileInput): HarnessState['capabilityProfile'];
63
67
  assembleMessages(messages: Message[], options?: PromptAssemblyOptions): Message[];
64
68
  recordAssistantResponse(response: LLMResponse): void;