@orion-agents/orion-code 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/dist/commands/context-commands.js +16 -28
- package/dist/commands/context-tool-command-handlers.d.ts +2 -3
- package/dist/commands/context-tool-command-handlers.js +2 -20
- package/dist/commands/registry.js +24 -61
- package/dist/commands/retired-commands.d.ts +2 -0
- package/dist/commands/retired-commands.js +24 -0
- package/dist/commands/session-command-handlers.d.ts +3 -2
- package/dist/commands/session-command-handlers.js +41 -42
- package/dist/commands/session-commands.js +21 -0
- package/dist/commands/system-commands.js +2 -27
- package/dist/commands/tool-commands.js +0 -10
- package/dist/commands/types.d.ts +6 -4
- package/dist/commands/workflow-commands.js +0 -24
- package/dist/core/tool-artifacts.js +17 -4
- package/dist/framework/query.js +151 -17
- package/dist/framework/tool-state.d.ts +4 -0
- package/dist/harness/context-harness.d.ts +7 -3
- package/dist/harness/context-harness.js +222 -48
- package/dist/harness/contract.js +3 -1
- package/dist/harness/drift-guard.js +67 -17
- package/dist/harness/goal-verification.d.ts +11 -0
- package/dist/harness/goal-verification.js +62 -0
- package/dist/harness/ledger.js +16 -3
- package/dist/harness/state.js +3 -0
- package/dist/harness/stop-controller.js +1 -1
- package/dist/harness/task-checklist.d.ts +11 -1
- package/dist/harness/task-checklist.js +48 -4
- package/dist/harness/types.d.ts +10 -0
- package/dist/harness/verification.d.ts +11 -1
- package/dist/harness/verification.js +47 -2
- package/dist/runtime/agent-loop.js +4 -1
- package/dist/runtime/agent-runtime-controller.d.ts +4 -2
- package/dist/runtime/agent-runtime-controller.js +115 -30
- package/dist/runtime/batch-read-service.js +21 -4
- package/dist/runtime/goal-runtime-coordinator.js +1 -0
- package/dist/runtime/orion-session-runner.js +3 -5
- package/dist/runtime/product-bootstrap.js +24 -11
- package/dist/runtime/product-orion-runtime.js +24 -2
- package/dist/runtime/task-context-recovery.js +21 -5
- package/dist/runtime/task-context-service.d.ts +3 -1
- package/dist/runtime/task-context-service.js +3 -0
- package/dist/runtime/ui-events.d.ts +4 -1
- package/dist/runtime/ui-view-model.js +7 -3
- package/dist/runtime/workspace-verification.d.ts +2 -2
- package/dist/runtime/workspace-verification.js +24 -9
- package/dist/services/chat-completion-sse.d.ts +9 -0
- package/dist/services/chat-completion-sse.js +50 -0
- package/dist/services/compact/summary-generator.d.ts +1 -1
- package/dist/services/compact/summary-generator.js +12 -0
- package/dist/services/llm.d.ts +1 -1
- package/dist/services/llm.js +165 -292
- package/dist/services/provider-diagnostics.d.ts +1 -1
- package/dist/services/provider-diagnostics.js +7 -2
- package/dist/services/provider-resilience/error-classifier.d.ts +3 -0
- package/dist/services/provider-resilience/error-classifier.js +14 -0
- package/dist/skills/builtin/security-check/SKILL.md +2 -2
- package/dist/skills/builtin/test-gen/SKILL.md +2 -2
- package/dist/terminal-ui/launch.js +1 -1
- package/dist/tools/core/common.d.ts +0 -11
- package/dist/tools/core/common.js +0 -18
- package/dist/tools/core/edit-file.js +57 -86
- package/dist/tools/core/exec-command.js +61 -80
- package/dist/tools/core/grep.js +84 -24
- package/dist/tools/core/read-file.js +3 -2
- package/dist/tools/todo.d.ts +2 -2
- package/dist/tools/todo.js +13 -10
- package/dist/tui-ui/launch.js +4 -1
- package/dist/tui-ui/layout.d.ts +2 -2
- package/dist/tui-ui/layout.js +59 -47
- package/dist/tui-ui/pickers.d.ts +3 -1
- package/dist/tui-ui/pickers.js +17 -11
- package/dist/tui-ui/runner.d.ts +1 -1
- package/dist/tui-ui/runner.js +61 -68
- package/dist/tui-ui/state.d.ts +4 -0
- package/dist/tui-ui/state.js +33 -2
- package/dist/utils/utf8.d.ts +6 -0
- package/dist/utils/utf8.js +14 -0
- package/docs/cli-guide.md +27 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ exports.createBatchReadToolV1 = createBatchReadToolV1;
|
|
|
5
5
|
exports.parseBatchReadStepsV1 = parseBatchReadStepsV1;
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
7
7
|
const tool_artifacts_1 = require("../core/tool-artifacts");
|
|
8
|
+
const utf8_1 = require("../utils/utf8");
|
|
8
9
|
exports.BATCH_READ_SERVICE_VERSION_V1 = 1;
|
|
9
10
|
exports.BATCH_READ_MAX_STEPS_V1 = 8;
|
|
10
11
|
exports.BATCH_READ_CHILD_OUTPUT_BYTES_V1 = 1600;
|
|
@@ -115,13 +116,28 @@ class BatchReadExecutionServiceV1 {
|
|
|
115
116
|
skipped,
|
|
116
117
|
steps: results,
|
|
117
118
|
};
|
|
118
|
-
const
|
|
119
|
+
const stepsPreview = results.map(step => {
|
|
120
|
+
const clipped = (0, utf8_1.truncateToBytes)(step.output, exports.BATCH_READ_CHILD_OUTPUT_BYTES_V1);
|
|
121
|
+
return clipped.text === step.output
|
|
122
|
+
? step
|
|
123
|
+
: { ...step, output: clipped.text, truncated: true };
|
|
124
|
+
});
|
|
125
|
+
const completeOutput = JSON.stringify(payload);
|
|
126
|
+
const outputBytes = Buffer.byteLength(completeOutput, 'utf8');
|
|
127
|
+
const hasClippedStep = stepsPreview.some((step, index) => step !== results[index]);
|
|
128
|
+
const artifact = hasClippedStep
|
|
129
|
+
? (0, tool_artifacts_1.storeArtifact)(input.invocation.context.cwd, 'batch_read', completeOutput, outputBytes)
|
|
130
|
+
: undefined;
|
|
131
|
+
const output = hasClippedStep
|
|
132
|
+
? JSON.stringify({ ...payload, steps: stepsPreview })
|
|
133
|
+
: completeOutput;
|
|
119
134
|
const result = {
|
|
120
135
|
schemaVersion: 1,
|
|
121
136
|
success,
|
|
122
137
|
output,
|
|
123
138
|
summary,
|
|
124
|
-
outputBytes
|
|
139
|
+
outputBytes,
|
|
140
|
+
...(artifact ? { artifactRef: { id: artifact.id, outputBytes: artifact.outputBytes } } : {}),
|
|
125
141
|
...(!success
|
|
126
142
|
? { error: interrupted ? 'batch_read was interrupted.' : `${failed} child step(s) failed.` }
|
|
127
143
|
: {}),
|
|
@@ -181,8 +197,9 @@ function completedStep(index, step, child) {
|
|
|
181
197
|
state: 'completed',
|
|
182
198
|
success: child.receipt.success,
|
|
183
199
|
summary: child.result.summary ?? summarize(raw),
|
|
184
|
-
output:
|
|
185
|
-
outputBytes: Buffer.byteLength(raw, 'utf8'),
|
|
200
|
+
output: raw,
|
|
201
|
+
outputBytes: child.result.outputBytes ?? Buffer.byteLength(raw, 'utf8'),
|
|
202
|
+
...(child.result.artifactRef ? { truncated: true, artifactRef: child.result.artifactRef } : {}),
|
|
186
203
|
invocationId: child.receipt.invocationId,
|
|
187
204
|
receiptDigest: child.receipt.digest,
|
|
188
205
|
terminal: child.receipt.terminal,
|
|
@@ -608,6 +608,7 @@ function defaultContinuationInput(state) {
|
|
|
608
608
|
return [
|
|
609
609
|
'Continue the active Goal using saved state and receipts.',
|
|
610
610
|
`Objective: ${objective}`,
|
|
611
|
+
'Use the current TaskContext verification requirements when the user has corrected a check.',
|
|
611
612
|
'Do not claim completion unless the TaskContext completion gate verifies every criterion.',
|
|
612
613
|
].join('\n');
|
|
613
614
|
}
|
|
@@ -73,11 +73,9 @@ class OrionSessionRunnerV1 {
|
|
|
73
73
|
if (this.transition === transition)
|
|
74
74
|
this.transition = undefined;
|
|
75
75
|
}
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
// replacement and must preserve the current renderer window.
|
|
80
|
-
if (activation || this.options.replayHistoryOnRestore !== false) {
|
|
76
|
+
// Interactive commands publish their bounded replacement only after the
|
|
77
|
+
// new owner starts. A runner that replays from the beginning owns its view.
|
|
78
|
+
if (this.options.replayHistoryOnRestore !== false) {
|
|
81
79
|
this.options.eventSink.clearTranscript();
|
|
82
80
|
}
|
|
83
81
|
active.adapter.flush();
|
|
@@ -189,7 +189,16 @@ async function createProductUiRuntime(options) {
|
|
|
189
189
|
const setSession = (session) => {
|
|
190
190
|
if (currentSession?.id !== session?.id) {
|
|
191
191
|
compactCoordinator.cancelBackground('session_changed');
|
|
192
|
-
store.setState({
|
|
192
|
+
store.setState({
|
|
193
|
+
conversationHistory: [],
|
|
194
|
+
tokenUsage: null,
|
|
195
|
+
contextUsage: null,
|
|
196
|
+
backgroundCompact: undefined,
|
|
197
|
+
harnessState: undefined,
|
|
198
|
+
lastLoopStats: undefined,
|
|
199
|
+
currentPlan: null,
|
|
200
|
+
todos: [],
|
|
201
|
+
});
|
|
193
202
|
}
|
|
194
203
|
applySessionState(session);
|
|
195
204
|
currentSession = session;
|
|
@@ -203,17 +212,20 @@ async function createProductUiRuntime(options) {
|
|
|
203
212
|
overridesProjectEffort: currentSession.effortPreference !== undefined,
|
|
204
213
|
};
|
|
205
214
|
};
|
|
215
|
+
const createFreshSession = () => {
|
|
216
|
+
defaultModelSelector =
|
|
217
|
+
settingsCoordinator.describe().sections.defaults.model.effectiveValue ??
|
|
218
|
+
defaultModelSelector;
|
|
219
|
+
const created = (0, session_storage_1.createSession)(cwd, defaultModelSelector, options.sessionSource ? { source: options.sessionSource } : undefined);
|
|
220
|
+
(0, global_config_1.incrementSessionCount)();
|
|
221
|
+
return created;
|
|
222
|
+
};
|
|
206
223
|
const ensureSession = () => {
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
(0, global_config_1.incrementSessionCount)();
|
|
213
|
-
setSession(created);
|
|
214
|
-
return created;
|
|
215
|
-
}
|
|
216
|
-
return currentSession;
|
|
224
|
+
if (currentSession)
|
|
225
|
+
return currentSession;
|
|
226
|
+
const created = createFreshSession();
|
|
227
|
+
setSession(created);
|
|
228
|
+
return created;
|
|
217
229
|
};
|
|
218
230
|
const getSession = () => currentSession;
|
|
219
231
|
const prepareSettingsRuntime = (context) => {
|
|
@@ -437,6 +449,7 @@ async function createProductUiRuntime(options) {
|
|
|
437
449
|
synchronizeSettings,
|
|
438
450
|
bindSettingsRuntimeIdleProbe,
|
|
439
451
|
isConfigured: (0, config_1.isConfigured)(config),
|
|
452
|
+
createFreshSession,
|
|
440
453
|
ensureSession,
|
|
441
454
|
setSession,
|
|
442
455
|
getSession,
|
|
@@ -9,6 +9,7 @@ const prompt_context_1 = require("../memory/prompt-context");
|
|
|
9
9
|
const file_context_1 = require("../services/file-context");
|
|
10
10
|
const goal_storage_1 = require("../services/goal-storage");
|
|
11
11
|
const llm_1 = require("../services/llm");
|
|
12
|
+
const redaction_1 = require("../services/redaction");
|
|
12
13
|
const session_storage_1 = require("../services/session-storage");
|
|
13
14
|
const model_registry_1 = require("../services/model-registry");
|
|
14
15
|
const token_estimate_1 = require("../utils/token-estimate");
|
|
@@ -1105,7 +1106,7 @@ async function resolveMcpToolsForStep(input, runtime, catalog) {
|
|
|
1105
1106
|
execute: async (args, context) => {
|
|
1106
1107
|
try {
|
|
1107
1108
|
const result = await binding.invoke(args, context.abortSignal);
|
|
1108
|
-
return
|
|
1109
|
+
return projectMcpResult(result);
|
|
1109
1110
|
}
|
|
1110
1111
|
catch (error) {
|
|
1111
1112
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1151,11 +1152,32 @@ function normalizeLookup(value) {
|
|
|
1151
1152
|
.replace(/[^\p{L}\p{N}]+/gu, ' ')
|
|
1152
1153
|
.trim();
|
|
1153
1154
|
}
|
|
1155
|
+
function projectMcpResult(value) {
|
|
1156
|
+
const output = renderMcpResult(value);
|
|
1157
|
+
if (!value || typeof value !== 'object' || !('isError' in value) || value.isError !== true) {
|
|
1158
|
+
return { success: true, output };
|
|
1159
|
+
}
|
|
1160
|
+
const content = 'content' in value && Array.isArray(value.content) ? value.content : [];
|
|
1161
|
+
const diagnostic = content.find((item) => !!item &&
|
|
1162
|
+
typeof item === 'object' &&
|
|
1163
|
+
'type' in item &&
|
|
1164
|
+
item.type === 'text' &&
|
|
1165
|
+
'text' in item &&
|
|
1166
|
+
typeof item.text === 'string' &&
|
|
1167
|
+
!!item.text.trim());
|
|
1168
|
+
return {
|
|
1169
|
+
success: false,
|
|
1170
|
+
output,
|
|
1171
|
+
error: diagnostic
|
|
1172
|
+
? (0, redaction_1.redactTraceText)(diagnostic.text.trim()).slice(0, 2048)
|
|
1173
|
+
: 'MCP tool reported an error.',
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1154
1176
|
function renderMcpResult(value) {
|
|
1155
1177
|
if (typeof value === 'string')
|
|
1156
1178
|
return value;
|
|
1157
1179
|
try {
|
|
1158
|
-
return JSON.stringify(value);
|
|
1180
|
+
return JSON.stringify(value) ?? String(value);
|
|
1159
1181
|
}
|
|
1160
1182
|
catch {
|
|
1161
1183
|
return String(value);
|
|
@@ -142,10 +142,8 @@ function recoverInterruptedTaskContext(input) {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
const goalState = restoreGoalState();
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
'status' in goalState &&
|
|
148
|
-
goalState.status === 'paused' &&
|
|
145
|
+
const interruptedGoal = turn.mode === 'goal' && goalState && 'status' in goalState ? goalState : undefined;
|
|
146
|
+
const goalInterruptedBeforeTools = interruptedGoal?.status === 'paused' &&
|
|
149
147
|
turn.itemIds.every(itemId => projection.items[itemId].kind !== 'command');
|
|
150
148
|
// A Goal can crash on its first provider request, before a task seed is
|
|
151
149
|
// bound to any tool. Persist its pause or a later reopen will see only the
|
|
@@ -178,7 +176,13 @@ function recoverInterruptedTaskContext(input) {
|
|
|
178
176
|
});
|
|
179
177
|
let unconfirmedWorkspaceRevisions = 0;
|
|
180
178
|
for (const event of events) {
|
|
181
|
-
if (
|
|
179
|
+
if (event.seq < checkpoint.event.seq)
|
|
180
|
+
continue;
|
|
181
|
+
if (interruptedGoal && event.payload.type === 'turn.steered') {
|
|
182
|
+
taskContext.observeGoalSteering(event.payload.data.input, interruptedGoal.goalId);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (!event.itemId)
|
|
182
186
|
continue;
|
|
183
187
|
const bound = intents.get(event.itemId);
|
|
184
188
|
if (!bound ||
|
|
@@ -207,6 +211,18 @@ function recoverInterruptedTaskContext(input) {
|
|
|
207
211
|
taskContextState = taskContext.exportState();
|
|
208
212
|
taskContextRevision = taskContext.revision;
|
|
209
213
|
}
|
|
214
|
+
else if (interruptedGoal && events.some(event => event.payload.type === 'turn.steered')) {
|
|
215
|
+
// A user correction is durable independently of the first tool in a turn.
|
|
216
|
+
const taskContext = (0, task_context_service_1.createTaskContextService)(taskOptions);
|
|
217
|
+
taskContext.observeUserInput(interruptedGoal.objective, interruptedGoal.goalId);
|
|
218
|
+
for (const event of events) {
|
|
219
|
+
if (event.payload.type === 'turn.steered') {
|
|
220
|
+
taskContext.observeGoalSteering(event.payload.data.input, interruptedGoal.goalId);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
taskContextState = taskContext.exportState();
|
|
224
|
+
taskContextRevision = taskContext.revision;
|
|
225
|
+
}
|
|
210
226
|
if (!taskContextState || taskContextRevision === undefined)
|
|
211
227
|
return;
|
|
212
228
|
const openItems = turn.itemIds
|
|
@@ -3,6 +3,7 @@ import type { PromptAssemblyOptions } from '../harness/assembler';
|
|
|
3
3
|
import type { CreateTurnSummaryInput } from '../harness/turn-summary';
|
|
4
4
|
import type { CapabilityProfileInput, CompletionGateResult, ContextCapsule, DriftCheckResult, HarnessConfig, HarnessProgressState, HarnessState, IntentUpdate, TaskContract, TaskTodoObservation, TaskWorkspaceAction, ToolResultObservation, TurnSummary } from '../harness/types';
|
|
5
5
|
import type { LLMResponse, Message } from '../services/llm';
|
|
6
|
+
import type { TodoWriteAdjustment } from '../framework/tool-state';
|
|
6
7
|
export type DeepReadonly<T> = T extends (...args: never[]) => unknown ? T : T extends readonly (infer U)[] ? readonly DeepReadonly<U>[] : T extends object ? {
|
|
7
8
|
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
8
9
|
} : T;
|
|
@@ -63,6 +64,7 @@ export interface TaskContextService {
|
|
|
63
64
|
readonly serviceId: 'task-context';
|
|
64
65
|
readonly revision: number;
|
|
65
66
|
observeUserInput(input: string, goalTaskId?: string): DeepReadonly<IntentUpdate> | undefined;
|
|
67
|
+
observeGoalSteering(input: string, goalId: string): void;
|
|
66
68
|
classifyIntent(input: string): DeepReadonly<IntentUpdate>;
|
|
67
69
|
observeCapability(input: CapabilityProfileInput): DeepReadonly<HarnessState['capabilityProfile']>;
|
|
68
70
|
assembleMessages(messages: Message[], options?: PromptAssemblyOptions): Message[];
|
|
@@ -80,7 +82,7 @@ export interface TaskContextService {
|
|
|
80
82
|
prepareTaskPlanStopCheck(): ReturnType<HarnessKernel['prepareTaskPlanStopCheck']>;
|
|
81
83
|
requiresVerification(): boolean;
|
|
82
84
|
recordTaskTodoReceipt(step: string, observation: TaskTodoObservation): void;
|
|
83
|
-
updateTaskTodos(todos: NonNullable<HarnessState['taskTodos']>, blockedReason?: string): string | undefined;
|
|
85
|
+
updateTaskTodos(todos: NonNullable<HarnessState['taskTodos']>, blockedReason?: string): TodoWriteAdjustment | string | undefined;
|
|
84
86
|
progressState(): HarnessProgressState;
|
|
85
87
|
recordProgress(baseline: HarnessProgressState, unconfirmedWorkspaceRevisions?: number): void;
|
|
86
88
|
auditCompletion(enforceTaskTodos?: boolean, requireEveryCriterion?: boolean): TaskContextCompletionDecisionV1;
|
|
@@ -42,6 +42,9 @@ class HarnessKernelTaskContextService {
|
|
|
42
42
|
this.refreshVerificationWorkspace();
|
|
43
43
|
return result ? immutableClone(result) : undefined;
|
|
44
44
|
}
|
|
45
|
+
observeGoalSteering(input, goalId) {
|
|
46
|
+
this.mutate(() => this.kernel.observeGoalSteering(input, goalId));
|
|
47
|
+
}
|
|
45
48
|
classifyIntent(input) {
|
|
46
49
|
return immutableClone(this.kernel.classifyIntent(input));
|
|
47
50
|
}
|
|
@@ -225,6 +225,7 @@ export interface RuntimeToolFinishedEvent {
|
|
|
225
225
|
batchIndex?: number;
|
|
226
226
|
}
|
|
227
227
|
export interface RuntimeSessionRestoredEvent {
|
|
228
|
+
reason?: 'new';
|
|
228
229
|
sessionId: string;
|
|
229
230
|
projectPath: string;
|
|
230
231
|
model: string;
|
|
@@ -286,6 +287,8 @@ export interface RuntimeSettingsMutationV1 {
|
|
|
286
287
|
readonly operations: readonly SettingsOperationV1[];
|
|
287
288
|
}
|
|
288
289
|
export interface OrionCodeUiRuntime extends RuntimeSessionAccessors {
|
|
290
|
+
/** Allocate an independent Session using the workspace default without switching owners. */
|
|
291
|
+
createFreshSession?: () => SessionMeta;
|
|
289
292
|
cwd: string;
|
|
290
293
|
version: string;
|
|
291
294
|
config: OrionCodeCLIConfig;
|
|
@@ -304,7 +307,7 @@ export interface OrionCodeUiRuntime extends RuntimeSessionAccessors {
|
|
|
304
307
|
/** Defaults to true; Web snapshots history and opts out of replaying it through live events. */
|
|
305
308
|
readonly replayHistoryOnRestore?: boolean;
|
|
306
309
|
}) => AgentRuntimeRunnerV1;
|
|
307
|
-
/** Read-only v0.2 runtime diagnostics for `/
|
|
310
|
+
/** Read-only v0.2 runtime diagnostics for `/context explain`; never activates lazy providers. */
|
|
308
311
|
getHarnessDiagnostics?: () => Promise<OrionRuntimeDiagnosticsV1 | undefined>;
|
|
309
312
|
/** Descriptor-only Skill catalog for trusted product surfaces; never loads Skill bodies. */
|
|
310
313
|
inspectSkills?: () => Promise<readonly SkillDescriptorV1[]>;
|
|
@@ -380,6 +380,12 @@ function createSessionRestoredView(event) {
|
|
|
380
380
|
const summary = event.summary ? normalizeSingleLineText(event.summary) : undefined;
|
|
381
381
|
const hasDetailedCounts = typeof event.transcriptMessages === 'number';
|
|
382
382
|
const total = typeof event.messageCount === 'number' ? `/${event.messageCount}` : '';
|
|
383
|
+
const counts = hasDetailedCounts
|
|
384
|
+
? `${event.restoredMessages} model-context / ${event.transcriptMessages} transcript messages`
|
|
385
|
+
: `${event.restoredMessages}${total} messages`;
|
|
386
|
+
const headline = event.reason === 'new'
|
|
387
|
+
? `New session ${shortId}`
|
|
388
|
+
: `Resumed session ${shortId} · restored ${counts}`;
|
|
383
389
|
const view = {
|
|
384
390
|
sessionId: event.sessionId,
|
|
385
391
|
shortId,
|
|
@@ -388,9 +394,7 @@ function createSessionRestoredView(event) {
|
|
|
388
394
|
restoredMessages: event.restoredMessages,
|
|
389
395
|
messageCount: event.messageCount,
|
|
390
396
|
summary: summary || undefined,
|
|
391
|
-
headline
|
|
392
|
-
? `Resumed session ${shortId} · restored ${event.restoredMessages} model-context / ${event.transcriptMessages} transcript messages`
|
|
393
|
-
: `Resumed session ${shortId} · restored ${event.restoredMessages}${total} messages`,
|
|
397
|
+
headline,
|
|
394
398
|
};
|
|
395
399
|
if (event.summaryGeneratedAt !== undefined)
|
|
396
400
|
view.summaryGeneratedAt = event.summaryGeneratedAt;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Observe file identities at verification boundaries without reading file contents.
|
|
3
|
-
* Git supplies the tracked and nonignored file scope
|
|
4
|
-
*
|
|
3
|
+
* Git supplies the tracked and nonignored file scope, plus the staged object
|
|
4
|
+
* and HEAD identities used by diff checks. Other projects use the filesystem walk.
|
|
5
5
|
*/
|
|
6
6
|
export declare function captureVerificationWorkspace(workspace: string, runtimeDirectories: readonly string[]): string | null;
|
|
7
7
|
//# sourceMappingURL=workspace-verification.d.ts.map
|
|
@@ -15,8 +15,8 @@ const ignoredDirectories = new Set([
|
|
|
15
15
|
]);
|
|
16
16
|
/**
|
|
17
17
|
* Observe file identities at verification boundaries without reading file contents.
|
|
18
|
-
* Git supplies the tracked and nonignored file scope
|
|
19
|
-
*
|
|
18
|
+
* Git supplies the tracked and nonignored file scope, plus the staged object
|
|
19
|
+
* and HEAD identities used by diff checks. Other projects use the filesystem walk.
|
|
20
20
|
*/
|
|
21
21
|
function captureVerificationWorkspace(workspace, runtimeDirectories) {
|
|
22
22
|
try {
|
|
@@ -26,8 +26,13 @@ function captureVerificationWorkspace(workspace, runtimeDirectories) {
|
|
|
26
26
|
.filter(path => path && path !== '..' && !path.startsWith('..' + node_path_1.sep) && !(0, node_path_1.isAbsolute)(path))
|
|
27
27
|
.map(path => path.split(node_path_1.sep).join('/')));
|
|
28
28
|
const gitScope = listGitScope(root);
|
|
29
|
-
const digest = (0, node_crypto_1.createHash)('sha256').update('workspace-verification-
|
|
29
|
+
const digest = (0, node_crypto_1.createHash)('sha256').update('workspace-verification-v2\0' + root + '\0');
|
|
30
30
|
const visit = (directory, prefix, scope, scopeOffset = 0) => {
|
|
31
|
+
if (scope) {
|
|
32
|
+
digest.update('git\0' + prefix + '\0');
|
|
33
|
+
digest.update(scope.head + '\0');
|
|
34
|
+
digest.update(scope.indexDigest + '\0');
|
|
35
|
+
}
|
|
31
36
|
const entries = (0, node_fs_1.readdirSync)(directory, { withFileTypes: true }).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
32
37
|
for (const entry of entries) {
|
|
33
38
|
const path = prefix + entry.name;
|
|
@@ -42,7 +47,8 @@ function captureVerificationWorkspace(workspace, runtimeDirectories) {
|
|
|
42
47
|
// A gitlink lists the directory itself only. Inspect its worktree
|
|
43
48
|
// against its own ignore rules rather than hashing the gitlink alone.
|
|
44
49
|
if (scope?.files.has(scopedPath) && !scope.ancestors.has(scopedPath)) {
|
|
45
|
-
|
|
50
|
+
const nested = (0, node_fs_1.existsSync)((0, node_path_1.join)(absolute, '.git')) ? listGitScope(absolute) : undefined;
|
|
51
|
+
visit(absolute, path + '/', nested, path.length + 1);
|
|
46
52
|
}
|
|
47
53
|
else {
|
|
48
54
|
visit(absolute, path + '/', scope, scopeOffset);
|
|
@@ -68,16 +74,25 @@ function listGitScope(root) {
|
|
|
68
74
|
return undefined;
|
|
69
75
|
search = parent;
|
|
70
76
|
}
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
77
|
+
const options = { cwd: root, timeout: 2000, maxBuffer: 8 * 1024 * 1024 };
|
|
78
|
+
const listed = (0, node_child_process_1.spawnSync)('git', ['ls-files', '--cached', '--others', '--exclude-standard', '-z', '--', '.'], options);
|
|
79
|
+
const staged = (0, node_child_process_1.spawnSync)('git', ['ls-files', '--stage', '-z', '--', '.'], options);
|
|
80
|
+
const head = (0, node_child_process_1.spawnSync)('git', ['rev-parse', '--verify', '--quiet', 'HEAD'], options);
|
|
81
|
+
if (listed.status !== 0 || staged.status !== 0 || (head.status !== 0 && head.status !== 1)) {
|
|
82
|
+
throw new Error('Git verification scope could not be observed.');
|
|
83
|
+
}
|
|
84
|
+
const files = new Set(listed.stdout.toString('utf8').split('\0').filter(Boolean));
|
|
75
85
|
const ancestors = new Set();
|
|
76
86
|
for (const path of files) {
|
|
77
87
|
for (let slash = path.indexOf('/'); slash >= 0; slash = path.indexOf('/', slash + 1)) {
|
|
78
88
|
ancestors.add(path.slice(0, slash));
|
|
79
89
|
}
|
|
80
90
|
}
|
|
81
|
-
return {
|
|
91
|
+
return {
|
|
92
|
+
files,
|
|
93
|
+
ancestors,
|
|
94
|
+
head: head.stdout.toString('utf8').trim(),
|
|
95
|
+
indexDigest: (0, node_crypto_1.createHash)('sha256').update(staged.stdout).digest('hex'),
|
|
96
|
+
};
|
|
82
97
|
}
|
|
83
98
|
//# sourceMappingURL=workspace-verification.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import { Stream } from 'openai/core/streaming';
|
|
3
|
+
/** Keep the SDK's SSE framing while exposing the Chat Completions end marker. */
|
|
4
|
+
export declare class ChatCompletionSseStream<Chunk> extends Stream<Chunk> {
|
|
5
|
+
private doneEvent;
|
|
6
|
+
get sawDoneEvent(): boolean;
|
|
7
|
+
static fromSSEResponse<Item>(response: Response, controller: AbortController, client?: OpenAI): ChatCompletionSseStream<Item>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=chat-completion-sse.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ChatCompletionSseStream = void 0;
|
|
7
|
+
const openai_1 = __importDefault(require("openai"));
|
|
8
|
+
const streaming_1 = require("openai/core/streaming");
|
|
9
|
+
/** Keep the SDK's SSE framing while exposing the Chat Completions end marker. */
|
|
10
|
+
class ChatCompletionSseStream extends streaming_1.Stream {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.doneEvent = false;
|
|
14
|
+
}
|
|
15
|
+
get sawDoneEvent() {
|
|
16
|
+
return this.doneEvent;
|
|
17
|
+
}
|
|
18
|
+
static fromSSEResponse(response, controller, client) {
|
|
19
|
+
let consumed = false;
|
|
20
|
+
async function* chunks() {
|
|
21
|
+
if (consumed)
|
|
22
|
+
throw new openai_1.default.OpenAIError('Cannot iterate over a consumed completion stream.');
|
|
23
|
+
consumed = true;
|
|
24
|
+
let exhaustedBody = false;
|
|
25
|
+
try {
|
|
26
|
+
for await (const event of (0, streaming_1._iterSSEMessages)(response, controller)) {
|
|
27
|
+
if (event.data.trim() === '[DONE]') {
|
|
28
|
+
stream.doneEvent = true;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const data = JSON.parse(event.data);
|
|
32
|
+
if (data?.error) {
|
|
33
|
+
throw new openai_1.default.APIError(undefined, data.error, undefined, response.headers);
|
|
34
|
+
}
|
|
35
|
+
if (data && typeof data === 'object')
|
|
36
|
+
yield data;
|
|
37
|
+
}
|
|
38
|
+
exhaustedBody = true;
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
if (!exhaustedBody && !stream.doneEvent)
|
|
42
|
+
controller.abort();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const stream = new ChatCompletionSseStream(chunks, controller, client);
|
|
46
|
+
return stream;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.ChatCompletionSseStream = ChatCompletionSseStream;
|
|
50
|
+
//# sourceMappingURL=chat-completion-sse.js.map
|
|
@@ -43,7 +43,7 @@ export interface GeneratedSummary {
|
|
|
43
43
|
semanticSummary: CompactSummary;
|
|
44
44
|
diagnostics: SummaryDiagnostic[];
|
|
45
45
|
}
|
|
46
|
-
export type SummaryDiagnosticCode = 'llm_request_failed' | 'llm_empty_response' | 'llm_chunked_input' | 'llm_summary_budget' | 'background_summary_reused' | 'heuristic_fallback' | 'deterministic_projection';
|
|
46
|
+
export type SummaryDiagnosticCode = 'llm_request_failed' | 'llm_empty_response' | 'llm_incomplete_response' | 'llm_chunked_input' | 'llm_summary_budget' | 'background_summary_reused' | 'heuristic_fallback' | 'deterministic_projection';
|
|
47
47
|
export interface SummaryDiagnostic {
|
|
48
48
|
code: SummaryDiagnosticCode;
|
|
49
49
|
message: string;
|
|
@@ -333,6 +333,18 @@ Summary:`;
|
|
|
333
333
|
const response = await llm.chat([{ role: 'user', content: prompt }], undefined, {
|
|
334
334
|
abortSignal,
|
|
335
335
|
});
|
|
336
|
+
if ((response.finishReason !== undefined && response.finishReason !== 'stop') ||
|
|
337
|
+
response.endTurn === false ||
|
|
338
|
+
response.toolCalls?.length) {
|
|
339
|
+
diagnostics.push({
|
|
340
|
+
code: 'llm_incomplete_response',
|
|
341
|
+
message: `Summary model did not complete chunk ${chunkIndex + 1} (${response.finishReason ?? 'non-final response'}).`,
|
|
342
|
+
fallbackUsed: true,
|
|
343
|
+
chunkIndex,
|
|
344
|
+
chunkCount: chunks.length,
|
|
345
|
+
});
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
336
348
|
if (!response.content?.trim()) {
|
|
337
349
|
diagnostics.push({
|
|
338
350
|
code: 'llm_empty_response',
|
package/dist/services/llm.d.ts
CHANGED
|
@@ -169,7 +169,7 @@ export interface LLMResponse {
|
|
|
169
169
|
};
|
|
170
170
|
}>;
|
|
171
171
|
}
|
|
172
|
-
export type LLMFinishReason = 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'unknown';
|
|
172
|
+
export type LLMFinishReason = 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'incomplete' | 'unknown';
|
|
173
173
|
export declare function normalizeFinishReason(value: unknown): LLMFinishReason | undefined;
|
|
174
174
|
/** 流式回调 */
|
|
175
175
|
export type StreamCallback = (chunk: string) => void;
|