@mcoda/mswarm 0.1.135-codali.41 → 0.1.135-codali.47
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/dist/vendor/codali/cli/TerminalCommand.js +2 -2
- package/dist/vendor/codali/cli/tui/TerminalPresentation.js +1 -1
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts +1 -0
- package/dist/vendor/codali/config/OrchestrationConfig.d.ts.map +1 -1
- package/dist/vendor/codali/config/OrchestrationConfig.js +3 -1
- package/dist/vendor/codali/docdex/DocdexClient.d.ts +11 -0
- package/dist/vendor/codali/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/vendor/codali/docdex/DocdexClient.js +55 -1
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts +5 -0
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.d.ts.map +1 -1
- package/dist/vendor/codali/eval/fixtures/ContractReviewProvider.js +63 -0
- package/dist/vendor/codali/eval/fixtures/MixedMediaRecoveryJourney.js +2 -2
- package/dist/vendor/codali/eval/fixtures/TerminalRecoveryJourney.js +2 -2
- package/dist/vendor/codali/permissions/PermissionGate.d.ts +7 -0
- package/dist/vendor/codali/permissions/PermissionGate.d.ts.map +1 -1
- package/dist/vendor/codali/permissions/PermissionGate.js +27 -1
- package/dist/vendor/codali/providers/ClaudeCliProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ClaudeCliProvider.js +1 -0
- package/dist/vendor/codali/providers/CodexCliProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/CodexCliProvider.js +1 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts +2 -0
- package/dist/vendor/codali/providers/ConfiguredProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ConfiguredProvider.js +29 -0
- package/dist/vendor/codali/providers/ModelServiceError.d.ts +16 -2
- package/dist/vendor/codali/providers/ModelServiceError.d.ts.map +1 -1
- package/dist/vendor/codali/providers/ModelServiceError.js +18 -1
- package/dist/vendor/codali/providers/OllamaRemoteProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/OllamaRemoteProvider.js +1 -0
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
- package/dist/vendor/codali/providers/OpenAiCompatibleProvider.js +4 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts +4 -0
- package/dist/vendor/codali/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/AnswerEdits.d.ts +39 -0
- package/dist/vendor/codali/runtime/AnswerEdits.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/AnswerEdits.js +134 -0
- package/dist/vendor/codali/runtime/AnswerVerification.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/AnswerVerification.js +4 -2
- package/dist/vendor/codali/runtime/AuditGuards.d.ts +41 -0
- package/dist/vendor/codali/runtime/AuditGuards.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/AuditGuards.js +81 -0
- package/dist/vendor/codali/runtime/CompletionReport.d.ts +4 -2
- package/dist/vendor/codali/runtime/CompletionReport.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/CompletionReport.js +8 -3
- package/dist/vendor/codali/runtime/ContextCompression.d.ts +5 -0
- package/dist/vendor/codali/runtime/ContextCompression.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ContextCompression.js +16 -4
- package/dist/vendor/codali/runtime/DeliveryDocs.d.ts +21 -0
- package/dist/vendor/codali/runtime/DeliveryDocs.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/DeliveryDocs.js +148 -0
- package/dist/vendor/codali/runtime/FigureCheck.d.ts +61 -2
- package/dist/vendor/codali/runtime/FigureCheck.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/FigureCheck.js +210 -14
- package/dist/vendor/codali/runtime/GatewayRequest.d.ts +13 -0
- package/dist/vendor/codali/runtime/GatewayRequest.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/GatewayRequest.js +54 -1
- package/dist/vendor/codali/runtime/InspectionConvergence.d.ts +4 -0
- package/dist/vendor/codali/runtime/InspectionConvergence.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/InspectionConvergence.js +24 -1
- package/dist/vendor/codali/runtime/InteractionContract.d.ts +15 -0
- package/dist/vendor/codali/runtime/InteractionContract.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/InteractionContract.js +33 -0
- package/dist/vendor/codali/runtime/InteractionRouter.d.ts +3 -3
- package/dist/vendor/codali/runtime/InteractionRouter.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/InteractionRouter.js +1 -1
- package/dist/vendor/codali/runtime/NumericProvenance.d.ts +102 -0
- package/dist/vendor/codali/runtime/NumericProvenance.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/NumericProvenance.js +411 -0
- package/dist/vendor/codali/runtime/OutageWait.d.ts +46 -5
- package/dist/vendor/codali/runtime/OutageWait.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/OutageWait.js +81 -8
- package/dist/vendor/codali/runtime/ResearchEvidence.d.ts +14 -0
- package/dist/vendor/codali/runtime/ResearchEvidence.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ResearchEvidence.js +139 -3
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts +22 -0
- package/dist/vendor/codali/runtime/ReviewCoordinator.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ReviewCoordinator.js +203 -25
- package/dist/vendor/codali/runtime/ReviewSource.d.ts +5 -0
- package/dist/vendor/codali/runtime/ReviewSource.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/ReviewSource.js +6 -1
- package/dist/vendor/codali/runtime/SessionController.d.ts +85 -10
- package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/SessionController.js +996 -176
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts +10 -0
- package/dist/vendor/codali/runtime/StructuralEvidence.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/StructuralEvidence.js +10 -0
- package/dist/vendor/codali/runtime/TaskReview.d.ts +10 -0
- package/dist/vendor/codali/runtime/TaskReview.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/TaskReview.js +31 -3
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts +8 -0
- package/dist/vendor/codali/runtime/VerificationCommand.d.ts.map +1 -1
- package/dist/vendor/codali/runtime/VerificationCommand.js +114 -0
- package/dist/vendor/codali/runtime/WorkingStyle.d.ts +20 -0
- package/dist/vendor/codali/runtime/WorkingStyle.d.ts.map +1 -0
- package/dist/vendor/codali/runtime/WorkingStyle.js +71 -0
- package/dist/vendor/codali/tools/ToolRegistry.d.ts.map +1 -1
- package/dist/vendor/codali/tools/ToolRegistry.js +30 -4
- package/dist/vendor/codali/tools/ToolTypes.d.ts +3 -0
- package/dist/vendor/codali/tools/ToolTypes.d.ts.map +1 -1
- package/dist/vendor/codali/tools/browser/BrowserTool.d.ts +23 -1
- package/dist/vendor/codali/tools/browser/BrowserTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/browser/BrowserTool.js +83 -4
- package/dist/vendor/codali/tools/browser/BrowserWorker.js +142 -2
- package/dist/vendor/codali/tools/browser/HttpFallback.d.ts +39 -0
- package/dist/vendor/codali/tools/browser/HttpFallback.d.ts.map +1 -0
- package/dist/vendor/codali/tools/browser/HttpFallback.js +240 -0
- package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts +16 -1
- package/dist/vendor/codali/tools/calculation/CalculatorTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/calculation/CalculatorTool.js +321 -26
- package/dist/vendor/codali/tools/deterministic/DeterministicTools.js +1 -1
- package/dist/vendor/codali/tools/deterministic/node-worker.cjs +10 -10
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts +2 -0
- package/dist/vendor/codali/tools/shell/AsyncProcess.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/AsyncProcess.js +38 -5
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts +29 -1
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/IsolatedExecutor.js +179 -9
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts +2 -0
- package/dist/vendor/codali/tools/shell/ShellTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/shell/ShellTool.js +33 -3
- package/dist/vendor/codali/tools/verification/CodeRunTool.d.ts +19 -0
- package/dist/vendor/codali/tools/verification/CodeRunTool.d.ts.map +1 -0
- package/dist/vendor/codali/tools/verification/CodeRunTool.js +104 -0
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/verification/JavaScriptVerificationTool.js +21 -10
- package/dist/vendor/codali/tools/verification/VitestTool.d.ts +27 -0
- package/dist/vendor/codali/tools/verification/VitestTool.d.ts.map +1 -1
- package/dist/vendor/codali/tools/verification/VitestTool.js +232 -18
- package/dist/vendor/config/deterministic/node-worker.mjs +15 -2
- package/dist/vendor/config/skills/code-implementation/SKILL.md +1 -1
- package/dist/vendor/config/skills/planning/SKILL.md +1 -1
- package/dist/vendor/config/skills/testing-and-verification/SKILL.md +5 -5
- package/dist/vendor/config/skills/ui-ux-design/SKILL.md +1 -1
- package/dist/vendor/config/skills/webapp-testing/SKILL.md +4 -0
- package/dist/vendor/config/skills/webapp-testing/journey-driver.mjs +186 -0
- package/package.json +3 -3
|
@@ -16,6 +16,8 @@ export class ModelServiceError extends Error {
|
|
|
16
16
|
this.nativeContextRefused = nativeContextRefused;
|
|
17
17
|
this.responseReason = responseReason;
|
|
18
18
|
this.name = "ModelServiceError";
|
|
19
|
+
if (responseReason === "stalled")
|
|
20
|
+
this.message += "; the model request did not return within its time allowance and was abandoned";
|
|
19
21
|
if (responseReason === "capacity_busy")
|
|
20
22
|
this.message += "; all compatible model workers are busy; retry after capacity becomes available";
|
|
21
23
|
if (code === "request_conflict")
|
|
@@ -26,6 +28,8 @@ export class ModelServiceError extends Error {
|
|
|
26
28
|
if (!error || typeof error !== "object")
|
|
27
29
|
return undefined;
|
|
28
30
|
const code = error.code;
|
|
31
|
+
if (code === "timeout" && error.message === "Self-hosted scheduler reservation expired before dispatch completed")
|
|
32
|
+
return Object.assign(new ModelServiceError("service_unavailable", 200), { failedWithoutOutput: true });
|
|
29
33
|
if (code === "context_length_exceeded" || code === "invalid_response" || code === "rate_limited")
|
|
30
34
|
return new ModelServiceError(code, 200);
|
|
31
35
|
return undefined;
|
|
@@ -72,6 +76,19 @@ export class ModelServiceError extends Error {
|
|
|
72
76
|
: response.status === 409 ? "request_conflict"
|
|
73
77
|
: response.status >= 500 ? "service_unavailable" : "invalid_request";
|
|
74
78
|
const retry = Number(response.headers.get("retry-after"));
|
|
75
|
-
|
|
79
|
+
const error = new ModelServiceError(code, response.status, response.headers.has("retry-after") && Number.isFinite(retry) && retry >= 0 ? Math.min(retry, 3600) : capacityBusy ? 2 : undefined, nativeRefused, capacityBusy ? "capacity_busy" : undefined);
|
|
80
|
+
if (code === "service_unavailable" && (response.status === 502 || response.status === 503))
|
|
81
|
+
error.failedWithoutOutput = true;
|
|
82
|
+
return error;
|
|
76
83
|
}
|
|
77
84
|
}
|
|
85
|
+
/** Whether a failed model request returned nothing that could have been used
|
|
86
|
+
* or billed, so its token reservation can be released: a definite service
|
|
87
|
+
* failure before generation with no partial text and no reported usage
|
|
88
|
+
* (see ModelServiceError.failedWithoutOutput). Kept otherwise, including for a
|
|
89
|
+
* gateway 504: in cycle 7 strata finished a prompt whose client still got a
|
|
90
|
+
* 504, so those tokens may have been generated and must stay within budget. */
|
|
91
|
+
export const failedWithoutOutput = (error) => {
|
|
92
|
+
const service = error instanceof ModelServiceError ? error : error?.cause instanceof ModelServiceError ? error.cause : undefined;
|
|
93
|
+
return !!service?.failedWithoutOutput && service.responseReason !== "stalled" && !service.partialText && !service.responseUsage;
|
|
94
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OllamaRemoteProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OllamaRemoteProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,eAAe,EACf,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AA2J5B,qBAAa,oBAAqB,YAAW,QAAQ;IAMvC,OAAO,CAAC,MAAM;IAL1B,uDAAuD;IACvD,QAAQ,CAAC,iBAAiB,QAAQ;IAElC,IAAI,SAAmB;gBAEH,MAAM,EAAE,cAAc;IAEpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"OllamaRemoteProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OllamaRemoteProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,eAAe,EACf,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AA2J5B,qBAAa,oBAAqB,YAAW,QAAQ;IAMvC,OAAO,CAAC,MAAM;IAL1B,uDAAuD;IACvD,QAAQ,CAAC,iBAAiB,QAAQ;IAElC,IAAI,SAAmB;gBAEH,MAAM,EAAE,cAAc;IAEpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAyKpE"}
|
|
@@ -141,6 +141,7 @@ export class OllamaRemoteProvider {
|
|
|
141
141
|
const url = new URL("api/chat", baseUrl).toString();
|
|
142
142
|
let resolvedModel = this.config.model;
|
|
143
143
|
const emitToken = (token) => {
|
|
144
|
+
request.onProgress?.();
|
|
144
145
|
if (request.onEvent) {
|
|
145
146
|
request.onEvent({ type: "token", content: token });
|
|
146
147
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAiCompatibleProvider.d.ts","sourceRoot":"","sources":["../../src/providers/OpenAiCompatibleProvider.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;A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AM;IAR1B,+EAA+E;IAC/E,QAAQ,CAAC,iBAAiB,QAAQ;IAElC,IAAI,SAAuB;IAC3B,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,sBAAsB,CAAoC;gBAE9C,MAAM,EAAE,cAAc;IAWpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA8QnE,OAAO,CAAC,WAAW;CA0BpB"}
|
|
@@ -169,6 +169,7 @@ export class OpenAiCompatibleProvider {
|
|
|
169
169
|
const url = new URL("chat/completions", baseUrl).toString();
|
|
170
170
|
const auth = this.resolveAuth();
|
|
171
171
|
const emitToken = (token) => {
|
|
172
|
+
request.onProgress?.();
|
|
172
173
|
if (request.onEvent) {
|
|
173
174
|
request.onEvent({ type: "token", content: token });
|
|
174
175
|
return;
|
|
@@ -310,6 +311,9 @@ export class OpenAiCompatibleProvider {
|
|
|
310
311
|
throw new Error("Model stream exceeds output limit");
|
|
311
312
|
emitToken(delta.content);
|
|
312
313
|
}
|
|
314
|
+
// Tool arguments and reasoning are generation too: a stream producing them is alive.
|
|
315
|
+
if (Array.isArray(delta?.tool_calls) && delta.tool_calls.length || typeof delta?.reasoning_content === "string" && delta.reasoning_content || typeof delta?.reasoning === "string" && delta.reasoning)
|
|
316
|
+
request.onProgress?.();
|
|
313
317
|
if (Array.isArray(delta?.tool_calls))
|
|
314
318
|
for (const call of delta.tool_calls) {
|
|
315
319
|
const index = call.index ?? 0;
|
|
@@ -70,6 +70,10 @@ export interface ProviderRequest {
|
|
|
70
70
|
stream?: boolean;
|
|
71
71
|
onEvent?: (event: AgentEvent) => void;
|
|
72
72
|
onToken?: (token: string) => void;
|
|
73
|
+
/** Called whenever a streaming response delivers more generated output
|
|
74
|
+
* (text, tool arguments or reasoning), so a caller can tell a live long
|
|
75
|
+
* generation from a stalled request. */
|
|
76
|
+
onProgress?: () => void;
|
|
73
77
|
streamFlushMs?: number;
|
|
74
78
|
}
|
|
75
79
|
export interface ProviderResponse {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderTypes.d.ts","sourceRoot":"","sources":["../../src/providers/ProviderTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iCAAiC,EACjC,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EAClC,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAEpE,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC;AAE9E,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAClD;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,GACD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,gBAAgB,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7D;IAAE,IAAI,E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AE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,iCAAiC,CAAC;IAChD,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,sBAAsB,CAAC,EAAE,iCAAiC,CAAC;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;;;;;OAUG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC/D;AAED,eAAO,MAAM,yBAAyB,GAAI,UAAU,QAAQ,KAAG,OAC1B,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Audits that return edits instead of a rewritten answer. A rewrite has to
|
|
2
|
+
* reproduce the whole answer to change one sentence, and in cycle 7 that went
|
|
3
|
+
* wrong both ways: a research rewrite came back at half the length, cut off
|
|
4
|
+
* inside a link, and replaced the complete answer; a design rewrite that fixed
|
|
5
|
+
* a figure was discarded only because it was longer. An edit names the text it
|
|
6
|
+
* replaces, so the rest of the answer cannot be lost, each edit can be judged
|
|
7
|
+
* and refused on its own, and the length of the reply does not matter. */
|
|
8
|
+
export interface AnswerEdit {
|
|
9
|
+
find: string;
|
|
10
|
+
replace: string;
|
|
11
|
+
reason?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface AppliedEdits {
|
|
14
|
+
text: string;
|
|
15
|
+
applied: AnswerEdit[];
|
|
16
|
+
skipped: Array<{
|
|
17
|
+
edit: AnswerEdit;
|
|
18
|
+
reason: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
export declare const EDIT_FORMAT_RULE = "Return only JSON: {\"edits\":[{\"find\":\"...\",\"replace\":\"...\",\"reason\":\"...\"}]}. Each \"find\" is a passage copied character for character from the draft, long enough to occur only once (a sentence, a table row or a heading line), and an edit never changes a link address or inline code unless that is the defect, in which case its find includes the whole link; \"replace\" is the text that goes in its place, in the draft's own format; \"reason\" names the defect in a few words. Correct every place a changed value or claim is used, each with its own edit. To add text, find the sentence or line it follows and replace it with that line plus the addition. To delete text, replace it with \"\". Do not edit passages that are correct and do not restate the draft. Return {\"edits\":[]} when there is no demonstrable defect.";
|
|
22
|
+
/** The edits in an audit reply, or undefined when the reply is not an edit list
|
|
23
|
+
* (then it is read as a full rewritten answer). */
|
|
24
|
+
export declare function parseAnswerEdits(text: string): AnswerEdit[] | undefined;
|
|
25
|
+
/** Apply edits in order. An edit is placed only where its passage occurs
|
|
26
|
+
* exactly once outside link targets, URLs and inline code; otherwise it is
|
|
27
|
+
* skipped (not_found, inside_link_or_code, ambiguous). `refuse` may veto an
|
|
28
|
+
* edit with a reason. `allowShrink` admits an edit that removes most of the
|
|
29
|
+
* answer, for a request with an explicit length limit. */
|
|
30
|
+
export declare function applyAnswerEdits(draft: string, edits: AnswerEdit[], refuse?: (edit: AnswerEdit, text: string) => string | undefined, allowShrink?: boolean): AppliedEdits;
|
|
31
|
+
/** An answer that stops inside markup: an open link, bracket or code span on
|
|
32
|
+
* its last line. Seen in cycle 7 at 4,044 output tokens, a count no cap check
|
|
33
|
+
* would flag, with the server reporting a normal finish. */
|
|
34
|
+
export declare const endsInsideMarkup: (text: string) => boolean;
|
|
35
|
+
/** What a revised answer lost of the draft's structure, if it lost much: most
|
|
36
|
+
* of its section headings, or most of its distinct links (only the links
|
|
37
|
+
* `countLink` accepts, so removing links that were never retrieved is not a loss). */
|
|
38
|
+
export declare const structureLoss: (draft: string, revised: string, countLink?: (url: string) => boolean) => "lost_sections" | "lost_links" | undefined;
|
|
39
|
+
//# sourceMappingURL=AnswerEdits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnswerEdits.d.ts","sourceRoot":"","sources":["../../src/runtime/AnswerEdits.ts"],"names":[],"mappings":"AAAA;;;;;;0EAM0E;AAC1E,MAAM,WAAW,UAAU;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAAE;AAC/E,MAAM,WAAW,YAAY;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,UAAU,EAAE,CAAC;IAAC,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,UAAU,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAAE;AAE5H,eAAO,MAAM,gBAAgB,s0BAA8yB,CAAC;AAE50B;mDACmD;AACnD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,GAAG,SAAS,CAavE;AA2CD;;;;0DAI0D;AAC1D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,EAAE,WAAW,UAAQ,GAAG,YAAY,CAkBvK;AAKD;;4DAE4D;AAC5D,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,OAM/C,CAAC;AAEF;;sFAEsF;AACtF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,SAAS,MAAM,EAAE,YAAW,CAAC,GAAG,EAAE,MAAM,KAAK,OAAoB,KAAG,eAAe,GAAG,YAAY,GAAG,SASjJ,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
export const EDIT_FORMAT_RULE = `Return only JSON: {"edits":[{"find":"...","replace":"...","reason":"..."}]}. Each "find" is a passage copied character for character from the draft, long enough to occur only once (a sentence, a table row or a heading line), and an edit never changes a link address or inline code unless that is the defect, in which case its find includes the whole link; "replace" is the text that goes in its place, in the draft's own format; "reason" names the defect in a few words. Correct every place a changed value or claim is used, each with its own edit. To add text, find the sentence or line it follows and replace it with that line plus the addition. To delete text, replace it with "". Do not edit passages that are correct and do not restate the draft. Return {"edits":[]} when there is no demonstrable defect.`;
|
|
2
|
+
/** The edits in an audit reply, or undefined when the reply is not an edit list
|
|
3
|
+
* (then it is read as a full rewritten answer). */
|
|
4
|
+
export function parseAnswerEdits(text) {
|
|
5
|
+
const body = text.trim().replace(/^```(?:json)?\s*/u, "").replace(/\s*```$/u, "");
|
|
6
|
+
if (!/^\{\s*"edits"\s*:/u.test(body))
|
|
7
|
+
return undefined;
|
|
8
|
+
let data;
|
|
9
|
+
try {
|
|
10
|
+
data = JSON.parse(body);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const list = data && typeof data === "object" ? data.edits : undefined;
|
|
16
|
+
if (!Array.isArray(list))
|
|
17
|
+
return undefined;
|
|
18
|
+
return list.flatMap(item => {
|
|
19
|
+
if (!item || typeof item !== "object")
|
|
20
|
+
return [];
|
|
21
|
+
const { find, replace, reason } = item;
|
|
22
|
+
if (typeof find !== "string" || !find.trim() || typeof replace !== "string" || find === replace)
|
|
23
|
+
return [];
|
|
24
|
+
return [{ find, replace, ...(typeof reason === "string" ? { reason: reason.slice(0, 300) } : {}) }];
|
|
25
|
+
}).slice(0, 200);
|
|
26
|
+
}
|
|
27
|
+
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
28
|
+
/** The same passage with any run of whitespace matching any other run: models
|
|
29
|
+
* often copy a passage with a line break turned into a space. */
|
|
30
|
+
const loosePattern = (find) => new RegExp(find.trim().split(/\s+/u).map(escape).join("\\s+"), "gu");
|
|
31
|
+
/** Spans an edit may not touch: link targets, bare URLs and inline code. A
|
|
32
|
+
* figure edit (v2024 -> v2025) that also rewrote a link's address broke the link. */
|
|
33
|
+
const maskedSpans = (text) => {
|
|
34
|
+
const spans = [];
|
|
35
|
+
for (const pattern of [/\]\([^)\s]*\)/gu, /https?:\/\/[^\s<>()\[\]"'`\\]+/gu, /`[^`\n]+`/gu]) {
|
|
36
|
+
for (const match of text.matchAll(pattern))
|
|
37
|
+
spans.push([match.index, match.index + match[0].length]);
|
|
38
|
+
}
|
|
39
|
+
return spans;
|
|
40
|
+
};
|
|
41
|
+
const occurrences = (text, find) => {
|
|
42
|
+
const found = [];
|
|
43
|
+
for (let at = text.indexOf(find); at >= 0; at = text.indexOf(find, at + 1))
|
|
44
|
+
found.push([at, at + find.length]);
|
|
45
|
+
if (found.length)
|
|
46
|
+
return found;
|
|
47
|
+
return [...text.matchAll(loosePattern(find))].map(match => [match.index, match.index + match[0].length]);
|
|
48
|
+
};
|
|
49
|
+
const headingLines = (text) => text.match(/^ {0,3}(?:#{1,6}[ \t]+\S.*|\*\*[^*\n]{2,120}\*\*:?[ \t]*)$/gmu) ?? [];
|
|
50
|
+
/** A heading's kind: its level ("#", "##", ...) or "bold" for a bold-only line. */
|
|
51
|
+
const headingKind = (line) => /^\s*(#{1,6})[ \t]/u.exec(line)?.[1] ?? "bold";
|
|
52
|
+
/** Why one edit must not apply as a deletion: it removes a section heading, or
|
|
53
|
+
* most of the answer. Other large deletions are judged edit by edit and stand.
|
|
54
|
+
* A heading counts as removed only when the replacement has fewer headings of
|
|
55
|
+
* its kind than the passage it replaces: renaming a heading or correcting a
|
|
56
|
+
* figure in it ("**Total cost: $243**" to "$324") is an ordinary edit. */
|
|
57
|
+
const deletionDefect = (edit, text, allowShrink) => {
|
|
58
|
+
const before = headingLines(edit.find), after = headingLines(edit.replace);
|
|
59
|
+
const lines = (value) => value.split("\n").filter(line => line.trim()).length;
|
|
60
|
+
for (const kind of new Set(before.map(headingKind))) {
|
|
61
|
+
const lost = before.filter(line => headingKind(line) === kind).length - after.filter(line => headingKind(line) === kind).length;
|
|
62
|
+
// A bold line is lost only when the line itself goes, not when it is reworded or unbolded.
|
|
63
|
+
if (lost > 0 && (kind !== "bold" || lines(edit.find) - lines(edit.replace) >= lost))
|
|
64
|
+
return "removes_section";
|
|
65
|
+
}
|
|
66
|
+
if (!allowShrink && edit.find.length - edit.replace.length > text.length * 0.5)
|
|
67
|
+
return "removes_most_of_answer";
|
|
68
|
+
return undefined;
|
|
69
|
+
};
|
|
70
|
+
/** Apply edits in order. An edit is placed only where its passage occurs
|
|
71
|
+
* exactly once outside link targets, URLs and inline code; otherwise it is
|
|
72
|
+
* skipped (not_found, inside_link_or_code, ambiguous). `refuse` may veto an
|
|
73
|
+
* edit with a reason. `allowShrink` admits an edit that removes most of the
|
|
74
|
+
* answer, for a request with an explicit length limit. */
|
|
75
|
+
export function applyAnswerEdits(draft, edits, refuse, allowShrink = false) {
|
|
76
|
+
let text = draft;
|
|
77
|
+
const applied = [], skipped = [];
|
|
78
|
+
for (const edit of edits) {
|
|
79
|
+
const vetoed = refuse?.(edit, text) ?? deletionDefect(edit, text, allowShrink);
|
|
80
|
+
if (vetoed) {
|
|
81
|
+
skipped.push({ edit, reason: vetoed });
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const masked = maskedSpans(text);
|
|
85
|
+
const all = occurrences(text, edit.find);
|
|
86
|
+
const free = all.filter(([start, end]) => !masked.some(([from, to]) => start < to && end > from && !(start <= from && end >= to)));
|
|
87
|
+
if (!all.length) {
|
|
88
|
+
skipped.push({ edit, reason: "not_found" });
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (!free.length) {
|
|
92
|
+
skipped.push({ edit, reason: "inside_link_or_code" });
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// The same passage in several places is not a place: "243" could be any of them.
|
|
96
|
+
if (free.length > 1) {
|
|
97
|
+
skipped.push({ edit, reason: "ambiguous" });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const [[start, end]] = free;
|
|
101
|
+
text = text.slice(0, start) + edit.replace + text.slice(end);
|
|
102
|
+
applied.push(edit);
|
|
103
|
+
}
|
|
104
|
+
return { text, applied, skipped };
|
|
105
|
+
}
|
|
106
|
+
const headings = (text) => (text.match(/^ {0,3}(?:#{1,6}[ \t]+\S.*|\*\*[^*\n]{2,120}\*\*:?[ \t]*)$/gmu) ?? []).length;
|
|
107
|
+
const distinctLinks = (text) => new Set((text.match(/https?:\/\/[^\s<>()\[\]"'`\\]+/gu) ?? []).map(url => url.replace(/[.,;:!?*]+$/u, "").replace(/\/+$/u, "")));
|
|
108
|
+
/** An answer that stops inside markup: an open link, bracket or code span on
|
|
109
|
+
* its last line. Seen in cycle 7 at 4,044 output tokens, a count no cap check
|
|
110
|
+
* would flag, with the server reporting a normal finish. */
|
|
111
|
+
export const endsInsideMarkup = (text) => {
|
|
112
|
+
const last = text.trimEnd().split("\n").pop() ?? "";
|
|
113
|
+
if (/\]\([^)\s]*$/u.test(last))
|
|
114
|
+
return true;
|
|
115
|
+
const opened = (last.match(/\[/gu) ?? []).length, closed = (last.match(/\]/gu) ?? []).length;
|
|
116
|
+
if (opened > closed)
|
|
117
|
+
return true;
|
|
118
|
+
return (last.match(/`/gu) ?? []).length % 2 === 1;
|
|
119
|
+
};
|
|
120
|
+
/** What a revised answer lost of the draft's structure, if it lost much: most
|
|
121
|
+
* of its section headings, or most of its distinct links (only the links
|
|
122
|
+
* `countLink` accepts, so removing links that were never retrieved is not a loss). */
|
|
123
|
+
export const structureLoss = (draft, revised, countLink = () => true) => {
|
|
124
|
+
const before = headings(draft), after = headings(revised);
|
|
125
|
+
if (before >= 3 && after < Math.ceil(before * 0.75))
|
|
126
|
+
return "lost_sections";
|
|
127
|
+
const links = new Set([...distinctLinks(draft)].filter(countLink));
|
|
128
|
+
if (links.size >= 4) {
|
|
129
|
+
const kept = distinctLinks(revised);
|
|
130
|
+
if ([...links].filter(link => kept.has(link)).length * 2 < links.size)
|
|
131
|
+
return "lost_links";
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnswerVerification.d.ts","sourceRoot":"","sources":["../../src/runtime/AnswerVerification.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AnswerVerification.d.ts","sourceRoot":"","sources":["../../src/runtime/AnswerVerification.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,kBAAkB;IAAG,QAAQ,EAAE,KAAK,GAAG,YAAY,GAAG,YAAY,GAAG,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;CAAE;AAElH;kFACkF;AAClF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,GAAG,MAAM,EAAE,CAU5F;AAED,MAAM,WAAW,OAAO;IAAG,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAAE;AAK9F;;;;;6EAK6E;AAC7E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAY3F;AAED;8EAC8E;AAC9E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,GAAG,SAAS,CAmBzI"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isTestFile } from "../tools/verification/VitestTool.js";
|
|
1
2
|
/** Detect presentation drift, not semantic correctness. A passing execution
|
|
2
3
|
* says nothing about code the model subsequently rewrites in its final answer. */
|
|
3
4
|
export function unmatchedExecutedCode(text, executed) {
|
|
@@ -12,7 +13,8 @@ export function unmatchedExecutedCode(text, executed) {
|
|
|
12
13
|
}
|
|
13
14
|
return [...unmatched];
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
+
// The same test-file rule verify_tests applies (test_x.js, x.test.js, ...).
|
|
17
|
+
const isTest = (file, runner) => isTestFile(file, runner === "python" || runner === "node" ? runner : file.path.endsWith(".py") ? "python" : "vitest");
|
|
16
18
|
const LANGUAGE_OF = (path) => path.endsWith(".py") ? "python" : /\.[cm]?[jt]s$/.test(path) ? "code-js" : undefined;
|
|
17
19
|
/** The session's last test run with the final answer's code in place of its
|
|
18
20
|
* source file. Cycle 5 case 28 (.41 regression pack): every verify_tests run
|
|
@@ -23,7 +25,7 @@ const LANGUAGE_OF = (path) => path.endsWith(".py") ? "python" : /\.[cm]?[jt]s$/.
|
|
|
23
25
|
export function finalCodeRerun(text, last) {
|
|
24
26
|
if (!last?.files?.length)
|
|
25
27
|
return;
|
|
26
|
-
const sources = last.files.filter(file => !
|
|
28
|
+
const sources = last.files.filter(file => !isTest(file, last.runner));
|
|
27
29
|
if (sources.length !== 1 || sources.length === last.files.length)
|
|
28
30
|
return;
|
|
29
31
|
const language = LANGUAGE_OF(sources[0].path);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type AnswerCheck, type FigureResult } from "./FigureCheck.js";
|
|
2
|
+
import type { AnswerEdit } from "./AnswerEdits.js";
|
|
3
|
+
/** Figures in a mismatch the audit should resolve: not those whose expression
|
|
4
|
+
* uses numbers the draft and request never state. A difference of exactly a
|
|
5
|
+
* unit factor stays flagged, marked as a possible slip: it may be the
|
|
6
|
+
* expression's slip or a real unit error in the draft, and the audit judges which. */
|
|
7
|
+
export declare const flaggedFigures: (check: AnswerCheck | undefined) => FigureResult[];
|
|
8
|
+
/** Values the calculator confirmed and the text states, which an edit may not
|
|
9
|
+
* change. A confirmed figure that uses a flagged figure as an input is not
|
|
10
|
+
* protected: correcting the input must be able to carry through. */
|
|
11
|
+
export declare const protectedFigures: (check: AnswerCheck | undefined, text: string) => FigureResult[];
|
|
12
|
+
/** The protected figures that stay protected under a set of edits. When an
|
|
13
|
+
* edit changes an input of a protected figure (3 shifts become 4), that figure
|
|
14
|
+
* must be free to change with it, and so must every figure built on it, or the
|
|
15
|
+
* answer is left saying 4 x 81 = 243. The new values are then judged by the
|
|
16
|
+
* re-check, not by the protection. */
|
|
17
|
+
export declare const stillProtected: (guarded: FigureResult[], edits: AnswerEdit[]) => FigureResult[];
|
|
18
|
+
/** Why an edit must be refused: it removes a protected value from the passage it replaces. */
|
|
19
|
+
export declare const editChangesProtected: (edit: AnswerEdit, guarded: FigureResult[]) => string | undefined;
|
|
20
|
+
/** Protected values that a full rewrite dropped. */
|
|
21
|
+
export declare const droppedProtected: (guarded: FigureResult[], revised: string) => number[];
|
|
22
|
+
/** Failures in the re-check of a revised text that the revision introduced: a
|
|
23
|
+
* mismatched figure whose stated value the previous text did not contain or
|
|
24
|
+
* the previous check had confirmed (an input changed, its result did not), or
|
|
25
|
+
* a target the previous check found met (or did not list) and the new one
|
|
26
|
+
* finds missed. `inputs` are the input numbers of those figures. */
|
|
27
|
+
export declare const introducedFailures: (after: AnswerCheck, previousText: string, previous: AnswerCheck | undefined) => {
|
|
28
|
+
values: number[];
|
|
29
|
+
inputs: number[];
|
|
30
|
+
targets: string[];
|
|
31
|
+
};
|
|
32
|
+
/** The edits to undo for introduced failures: those whose new text carries an
|
|
33
|
+
* introduced value, an input of a newly broken figure, or an achieved claim. */
|
|
34
|
+
export declare const editsToRevert: (edits: AnswerEdit[], failures: {
|
|
35
|
+
values: number[];
|
|
36
|
+
inputs?: number[];
|
|
37
|
+
targets: string[];
|
|
38
|
+
}, after: AnswerCheck) => AnswerEdit[];
|
|
39
|
+
/** Open problems a check hands to the audit: flagged figures, missed targets, conflicts. */
|
|
40
|
+
export declare const openIssues: (check: AnswerCheck | undefined) => number;
|
|
41
|
+
//# sourceMappingURL=AuditGuards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuditGuards.d.ts","sourceRoot":"","sources":["../../src/runtime/AuditGuards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAenD;;;sFAGsF;AACtF,eAAO,MAAM,cAAc,GAAI,OAAO,WAAW,GAAG,SAAS,KAAG,YAAY,EAC0C,CAAC;AAIvH;;oEAEoE;AACpE,eAAO,MAAM,gBAAgB,GAAI,OAAO,WAAW,GAAG,SAAS,EAAE,MAAM,MAAM,KAAG,YAAY,EAI3F,CAAC;AAEF;;;;sCAIsC;AACtC,eAAO,MAAM,cAAc,GAAI,SAAS,YAAY,EAAE,EAAE,OAAO,UAAU,EAAE,KAAG,YAAY,EAWzF,CAAC;AAEF,8FAA8F;AAC9F,eAAO,MAAM,oBAAoB,GAAI,MAAM,UAAU,EAAE,SAAS,YAAY,EAAE,KAAG,MAAM,GAAG,SAIzF,CAAC;AAEF,oDAAoD;AACpD,eAAO,MAAM,gBAAgB,GAAI,SAAS,YAAY,EAAE,EAAE,SAAS,MAAM,KAAG,MAAM,EAGjF,CAAC;AAEF;;;;oEAIoE;AACpE,eAAO,MAAM,kBAAkB,GAAI,OAAO,WAAW,EAAE,cAAc,MAAM,EAAE,UAAU,WAAW,GAAG,SAAS,KAAG;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAQvK,CAAC;AAEF;gFACgF;AAChF,eAAO,MAAM,aAAa,GAAI,OAAO,UAAU,EAAE,EAAE,UAAU;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,EAAE,OAAO,WAAW,KAAG,UAAU,EAOvJ,CAAC;AAEF,4FAA4F;AAC5F,eAAO,MAAM,UAAU,GAAI,OAAO,WAAW,GAAG,SAAS,KAAG,MACkF,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { numberValues } from "./FigureCheck.js";
|
|
2
|
+
/** Guards around a consistency audit, decided from calculator results rather
|
|
3
|
+
* than from the audit's own judgement. In cycle 7 the audit doubled figures
|
|
4
|
+
* the calculator had just confirmed (243 cartridges a year became 486) and
|
|
5
|
+
* "corrected" a right figure into a tenfold error, and nothing checked its
|
|
6
|
+
* output. */
|
|
7
|
+
const same = (a, b) => Math.abs(a - b) <= 1e-9 * Math.max(1, Math.abs(a), Math.abs(b));
|
|
8
|
+
const contains = (values, value) => values.some(other => same(other, value));
|
|
9
|
+
/** Kept, allowing for the rounding of a restated value (233.28 written as 233.3). */
|
|
10
|
+
const keeps = (values, value) => values.some(other => Math.abs(other - value) <= 0.01 * Math.abs(value));
|
|
11
|
+
/** Small whole numbers occur everywhere; protecting them would refuse ordinary edits. */
|
|
12
|
+
const distinctive = (value) => !(Number.isInteger(value) && Math.abs(value) < 10);
|
|
13
|
+
/** Figures in a mismatch the audit should resolve: not those whose expression
|
|
14
|
+
* uses numbers the draft and request never state. A difference of exactly a
|
|
15
|
+
* unit factor stays flagged, marked as a possible slip: it may be the
|
|
16
|
+
* expression's slip or a real unit error in the draft, and the audit judges which. */
|
|
17
|
+
export const flaggedFigures = (check) => (check?.figures ?? []).filter(figure => !figure.error && !figure.matches && figure.suspect !== "inputs_not_in_text");
|
|
18
|
+
const inputsOf = (figure) => numberValues(figure.expression.replace(/\[[^\]]*\]/gu, " "));
|
|
19
|
+
/** Values the calculator confirmed and the text states, which an edit may not
|
|
20
|
+
* change. A confirmed figure that uses a flagged figure as an input is not
|
|
21
|
+
* protected: correcting the input must be able to carry through. */
|
|
22
|
+
export const protectedFigures = (check, text) => {
|
|
23
|
+
const flagged = flaggedFigures(check).map(figure => figure.stated), stated = numberValues(text);
|
|
24
|
+
return (check?.figures ?? []).filter(figure => figure.matches && !figure.error && figure.computed !== undefined && distinctive(figure.stated)
|
|
25
|
+
&& contains(stated, figure.stated) && !inputsOf(figure).some(input => contains(flagged, input)));
|
|
26
|
+
};
|
|
27
|
+
/** The protected figures that stay protected under a set of edits. When an
|
|
28
|
+
* edit changes an input of a protected figure (3 shifts become 4), that figure
|
|
29
|
+
* must be free to change with it, and so must every figure built on it, or the
|
|
30
|
+
* answer is left saying 4 x 81 = 243. The new values are then judged by the
|
|
31
|
+
* re-check, not by the protection. */
|
|
32
|
+
export const stillProtected = (guarded, edits) => {
|
|
33
|
+
const removed = edits.flatMap(edit => { const after = numberValues(edit.replace); return numberValues(edit.find).filter(value => !keeps(after, value)); });
|
|
34
|
+
const freed = new Set();
|
|
35
|
+
// Inputs changed directly (not themselves protected results), then whatever depends on a freed result.
|
|
36
|
+
let changed = removed.filter(value => !guarded.some(figure => same(figure.stated, value)));
|
|
37
|
+
while (changed.length) {
|
|
38
|
+
const next = guarded.filter(figure => !freed.has(figure) && inputsOf(figure).some(input => contains(changed, input)));
|
|
39
|
+
for (const figure of next)
|
|
40
|
+
freed.add(figure);
|
|
41
|
+
changed = next.map(figure => figure.stated).filter(value => contains(removed, value));
|
|
42
|
+
}
|
|
43
|
+
return guarded.filter(figure => !freed.has(figure));
|
|
44
|
+
};
|
|
45
|
+
/** Why an edit must be refused: it removes a protected value from the passage it replaces. */
|
|
46
|
+
export const editChangesProtected = (edit, guarded) => {
|
|
47
|
+
const before = numberValues(edit.find), after = numberValues(edit.replace);
|
|
48
|
+
const hit = guarded.find(figure => contains(before, figure.stated) && !keeps(after, figure.stated));
|
|
49
|
+
return hit ? `confirmed_figure:${hit.stated}` : undefined;
|
|
50
|
+
};
|
|
51
|
+
/** Protected values that a full rewrite dropped. */
|
|
52
|
+
export const droppedProtected = (guarded, revised) => {
|
|
53
|
+
const after = numberValues(revised);
|
|
54
|
+
return guarded.filter(figure => !keeps(after, figure.stated)).map(figure => figure.stated);
|
|
55
|
+
};
|
|
56
|
+
/** Failures in the re-check of a revised text that the revision introduced: a
|
|
57
|
+
* mismatched figure whose stated value the previous text did not contain or
|
|
58
|
+
* the previous check had confirmed (an input changed, its result did not), or
|
|
59
|
+
* a target the previous check found met (or did not list) and the new one
|
|
60
|
+
* finds missed. `inputs` are the input numbers of those figures. */
|
|
61
|
+
export const introducedFailures = (after, previousText, previous) => {
|
|
62
|
+
const earlier = numberValues(previousText);
|
|
63
|
+
const confirmed = (previous?.figures ?? []).filter(figure => figure.matches && !figure.error && figure.computed !== undefined).map(figure => figure.stated);
|
|
64
|
+
const broken = flaggedFigures(after).filter(figure => !contains(earlier, figure.stated) || contains(confirmed, figure.stated));
|
|
65
|
+
const missedBefore = new Set((previous?.targets ?? []).filter(target => !target.met && !target.error).map(target => target.requirement.trim().toLowerCase()));
|
|
66
|
+
const targets = after.targets.filter(target => !target.met && !target.error && !missedBefore.has(target.requirement.trim().toLowerCase()))
|
|
67
|
+
.filter(target => target.achievedClaim === undefined || !previousText.includes(target.achievedClaim)).map(target => target.requirement);
|
|
68
|
+
return { values: broken.map(figure => figure.stated), inputs: broken.flatMap(inputsOf), targets };
|
|
69
|
+
};
|
|
70
|
+
/** The edits to undo for introduced failures: those whose new text carries an
|
|
71
|
+
* introduced value, an input of a newly broken figure, or an achieved claim. */
|
|
72
|
+
export const editsToRevert = (edits, failures, after) => {
|
|
73
|
+
const claims = after.targets.filter(target => failures.targets.includes(target.requirement)).map(target => target.achievedClaim ?? "").filter(Boolean);
|
|
74
|
+
const suspects = [...failures.values, ...(failures.inputs ?? [])];
|
|
75
|
+
return edits.filter(edit => {
|
|
76
|
+
const added = numberValues(edit.replace).filter(value => !contains(numberValues(edit.find), value));
|
|
77
|
+
return suspects.some(value => contains(added, value)) || claims.some(claim => edit.replace.includes(claim) && !edit.find.includes(claim));
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
/** Open problems a check hands to the audit: flagged figures, missed targets, conflicts. */
|
|
81
|
+
export const openIssues = (check) => flaggedFigures(check).length + (check?.targets ?? []).filter(target => !target.met && !target.error).length + (check?.conflicts.length ?? 0);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { WorkState } from "../session/WorkTypes.js";
|
|
2
2
|
/** A stopped turn is not a delivery. Summarize only durable state, without inference. */
|
|
3
|
-
|
|
3
|
+
/** Files changed during a call that failed on a workspace conflict and not read or written since. */
|
|
4
|
+
export declare const unreconciledNote: (files: string[]) => string;
|
|
5
|
+
export declare function interruptedReport(state: WorkState, sessionId: string, touched: string[], uncertain: string[], unreconciled?: string[]): string;
|
|
4
6
|
/** What a turn that ran out of time hands back: recorded state only, with the
|
|
5
7
|
* latest check as it was observed. */
|
|
6
8
|
export declare function deadlineReport(handoff: string, latestCheck?: {
|
|
@@ -9,5 +11,5 @@ export declare function deadlineReport(handoff: string, latestCheck?: {
|
|
|
9
11
|
}): string;
|
|
10
12
|
/** Delivery repeats accepted evidence instead of asking the model to introduce
|
|
11
13
|
* new factual claims after the goal has already passed review. */
|
|
12
|
-
export declare function completionReport(state: WorkState, budgetExhausted?: boolean): string;
|
|
14
|
+
export declare function completionReport(state: WorkState, budgetExhausted?: boolean, unreconciled?: string[]): string;
|
|
13
15
|
//# sourceMappingURL=CompletionReport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompletionReport.d.ts","sourceRoot":"","sources":["../../src/runtime/CompletionReport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"CompletionReport.d.ts","sourceRoot":"","sources":["../../src/runtime/CompletionReport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,yFAAyF;AACzF,qGAAqG;AACrG,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,EAAE,KAAG,MAAuP,CAAC;AAE3S,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,YAAY,GAAE,MAAM,EAAO,GAAG,MAAM,CAalJ;AAED;sCACsC;AACtC,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAKzG;AAED;kEACkE;AAClE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,eAAe,UAAQ,EAAE,YAAY,GAAE,MAAM,EAAO,GAAG,MAAM,CAU/G"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** A stopped turn is not a delivery. Summarize only durable state, without inference. */
|
|
2
|
-
|
|
2
|
+
/** Files changed during a call that failed on a workspace conflict and not read or written since. */
|
|
3
|
+
export const unreconciledNote = (files) => `Files changed during a failed tool call and not inspected since (they may hold another process's edits): ${files.slice(0, 8).join(", ")}${files.length > 8 ? `; ${files.length - 8} more` : ""}. Review them before relying on this result.`;
|
|
4
|
+
export function interruptedReport(state, sessionId, touched, uncertain, unreconciled = []) {
|
|
3
5
|
const pending = state.tasks.filter(task => !["verified", "cancelled", "superseded"].includes(task.status));
|
|
4
6
|
const verified = state.tasks.filter(task => task.status === "verified").length;
|
|
5
7
|
const short = (text) => text.replace(/\s+/g, " ").slice(0, 180);
|
|
@@ -12,6 +14,8 @@ export function interruptedReport(state, sessionId, touched, uncertain) {
|
|
|
12
14
|
lines.push(`Changed files (not a completion claim): ${touched.slice(0, 8).map(short).join(", ")}${touched.length > 8 ? `; ${touched.length - 8} more` : ""}.`);
|
|
13
15
|
if (uncertain.length)
|
|
14
16
|
lines.push(`${uncertain.length} operation outcome(s) need reconciliation before retrying.`);
|
|
17
|
+
if (unreconciled.length)
|
|
18
|
+
lines.push(unreconciledNote(unreconciled));
|
|
15
19
|
lines.push(`Resume this session with /resume ${sessionId}, then /continue. Inspect /status and /usage for details.`);
|
|
16
20
|
return lines.join("\n");
|
|
17
21
|
}
|
|
@@ -25,7 +29,7 @@ export function deadlineReport(handoff, latestCheck) {
|
|
|
25
29
|
}
|
|
26
30
|
/** Delivery repeats accepted evidence instead of asking the model to introduce
|
|
27
31
|
* new factual claims after the goal has already passed review. */
|
|
28
|
-
export function completionReport(state, budgetExhausted = false) {
|
|
32
|
+
export function completionReport(state, budgetExhausted = false, unreconciled = []) {
|
|
29
33
|
const accepted = new Set(state.tasks.filter(task => task.status === "verified").flatMap(task => task.evidenceIds));
|
|
30
34
|
const summaries = [...new Set(state.evidence.filter(item => accepted.has(item.id) && item.kind === "review" && item.ok)
|
|
31
35
|
.map(item => item.summary.trim()).filter(Boolean))];
|
|
@@ -33,5 +37,6 @@ export function completionReport(state, budgetExhausted = false) {
|
|
|
33
37
|
const selected = summaries.slice(-5).map(summary => summary.length <= 2000 ? summary : summary.slice(0, 2000) + "\n[Summary shortened; full evidence is retained in the session.]");
|
|
34
38
|
const more = summaries.length > selected.length ? `\n\n${summaries.length - selected.length} additional accepted task summaries are retained in the session.` : "";
|
|
35
39
|
return heading + (selected.length ? "\n\n" + selected.join("\n\n") : "") + more
|
|
36
|
-
+ (budgetExhausted ? "\n\nThe model budget was exhausted; this report uses the recorded verification evidence." : "")
|
|
40
|
+
+ (budgetExhausted ? "\n\nThe model budget was exhausted; this report uses the recorded verification evidence." : "")
|
|
41
|
+
+ (unreconciled.length ? `\n\n${unreconciledNote(unreconciled)}` : "");
|
|
37
42
|
}
|
|
@@ -22,6 +22,11 @@ export declare const compressConversation: (messages: ProviderMessage[], targetC
|
|
|
22
22
|
messages: ProviderMessage[];
|
|
23
23
|
archived: ArchivedContext[];
|
|
24
24
|
};
|
|
25
|
+
/** Trim when the context passes this share of the room for input ... */
|
|
26
|
+
export declare const COMPRESSION_TRIGGER_SHARE = 0.9;
|
|
27
|
+
/** ... down to this share, so several calls pass between two trims instead of
|
|
28
|
+
* every call rewriting older messages (which also defeats the server's prompt cache). */
|
|
29
|
+
export declare const COMPRESSION_TARGET_SHARE = 0.6;
|
|
25
30
|
/** Whether an identical earlier tool result is still in front of the model,
|
|
26
31
|
* unabbreviated. An abbreviated copy keeps the head, so it is recognised by the
|
|
27
32
|
* marker `shorten` prepends rather than by its text. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextCompression.d.ts","sourceRoot":"","sources":["../../src/runtime/ContextCompression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAE1E,MAAM,WAAW,eAAe;IAAG,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,eAAe,CAAC;CAAE;AAC9E,eAAO,MAAM,WAAW,GAAI,SAAS,eAAe,KAAG,MAA4E,CAAC;AACpI,eAAO,MAAM,qBAAqB,oCAA8B,CAAC;AAEjE;;4EAE4E;AAC5E,eAAO,MAAM,eAAe,GAAI,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,EAAE,eAAe,EAAE,CAAC;IAAC,QAAQ,EAAE,eAAe,EAAE,CAAA;CAajJ,CAAC;AAUF,wEAAwE;AACxE,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAC7C;yFACyF;AACzF,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAS5C;;wDAEwD;AACxD,eAAO,MAAM,kBAAkB,GAAI,QAAQ,MAAM,EAAE,SAAS,SAAS,MAAM,EAAE,KAAG,OAG/E,CAAC;AAEF;qEACqE;AACrE,eAAO,MAAM,oBAAoB,GAAI,eAAe,MAAM,EAAE,iBAAiB,MAAM,KAAG,MACiF,CAAC;AACxK,eAAO,MAAM,sBAAsB,GAAI,eAAe,MAAM,EAAE,iBAAiB,MAAM,KAAG,MACa,CAAC;AActG;8EAC8E;AAC9E,eAAO,MAAM,uBAAuB,GAAI,SAAS,eAAe,EAAE,eAAe,MAAM,EAAE,cAAc,MAAM,KAAG;IAC9G,OAAO,EAAE,eAAe,CAAC;IAAC,QAAQ,EAAE,eAAe,EAAE,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;CAqFlG,CAAC"}
|
|
@@ -157,7 +157,19 @@ export const compressConversation = (messages, targetChars) => {
|
|
|
157
157
|
}
|
|
158
158
|
return { messages: result, archived: [...archived.values()] };
|
|
159
159
|
};
|
|
160
|
-
|
|
160
|
+
/** Share of the window kept free for the response. At 0.3, with trimming at 80%
|
|
161
|
+
* of the rest down to 70%, a 131k window held 64-73k estimated tokens (about
|
|
162
|
+
* 51-58k real ones: the estimate runs a fifth high), and app builds trimmed on
|
|
163
|
+
* 85% of their model calls. Answers and file writes rarely pass 10k tokens. */
|
|
164
|
+
const OUTPUT_RESERVE_SHARE = 0.15;
|
|
165
|
+
/** A small window still keeps room for one file write, up to the old share. */
|
|
166
|
+
const OUTPUT_RESERVE_FLOOR = 16384;
|
|
167
|
+
const OUTPUT_RESERVE_CEILING_SHARE = 0.3;
|
|
168
|
+
/** Trim when the context passes this share of the room for input ... */
|
|
169
|
+
export const COMPRESSION_TRIGGER_SHARE = 0.9;
|
|
170
|
+
/** ... down to this share, so several calls pass between two trims instead of
|
|
171
|
+
* every call rewriting older messages (which also defeats the server's prompt cache). */
|
|
172
|
+
export const COMPRESSION_TARGET_SHARE = 0.6;
|
|
161
173
|
/** Token budget for retained execution history. It reserves output the same way
|
|
162
174
|
* as compressProviderContext: subtracting the full 40k ceiling of a 65k model
|
|
163
175
|
* left 6k tokens of history, so each file read evicted the previous one, the
|
|
@@ -173,7 +185,7 @@ export const resultStillVisible = (output, visible) => {
|
|
|
173
185
|
};
|
|
174
186
|
/** Output is an allowance, not occupied context: every budget derived from the
|
|
175
187
|
* window reserves this much for it, never the configured ceiling. */
|
|
176
|
-
export const reservedOutputTokens = (contextWindow, maxOutputTokens) => Math.min(maxOutputTokens, Math.floor(contextWindow * OUTPUT_RESERVE_SHARE));
|
|
188
|
+
export const reservedOutputTokens = (contextWindow, maxOutputTokens) => Math.min(maxOutputTokens, Math.floor(contextWindow * OUTPUT_RESERVE_CEILING_SHARE), Math.max(Math.floor(contextWindow * OUTPUT_RESERVE_SHARE), OUTPUT_RESERVE_FLOOR));
|
|
177
189
|
export const executionHistoryBudget = (contextWindow, maxOutputTokens) => Math.max(1, Math.floor((contextWindow - reservedOutputTokens(contextWindow, maxOutputTokens)) / 4));
|
|
178
190
|
const KEPT_HISTORY_MARKERS = 8;
|
|
179
191
|
const INVENTORY_ENTRIES = 40;
|
|
@@ -199,14 +211,14 @@ export const compressProviderContext = (request, contextWindow, outputTokens) =>
|
|
|
199
211
|
const reservedOutput = reservedOutputTokens(contextWindow, outputTokens);
|
|
200
212
|
const available = contextWindow - reservedOutput - 512;
|
|
201
213
|
const beforeTokens = estimateContextTokens(request);
|
|
202
|
-
if (beforeTokens <= available *
|
|
214
|
+
if (beforeTokens <= available * COMPRESSION_TRIGGER_SHARE) {
|
|
203
215
|
const room = contextWindow - beforeTokens - 512;
|
|
204
216
|
return { request: (request.maxTokens ?? outputTokens) > room ? { ...request, maxTokens: room } : request, archived: [], beforeTokens, afterTokens: beforeTokens };
|
|
205
217
|
}
|
|
206
218
|
const archived = new Map();
|
|
207
219
|
const messages = request.messages.map(message => ({ ...message }));
|
|
208
220
|
const compressed = { ...request, messages };
|
|
209
|
-
const target = Math.max(0, Math.floor(available *
|
|
221
|
+
const target = Math.max(0, Math.floor(available * COMPRESSION_TARGET_SHARE));
|
|
210
222
|
// Do not immediately abbreviate the excerpt the model just recovered with
|
|
211
223
|
// context_read. Exhaust older history first; trim recent context only if the
|
|
212
224
|
// actual window requires it, not merely to meet the preferred headroom.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Delivery documents (README, delivery notes, guides) the session wrote. Cycle 7
|
|
2
|
+
* left them to the last task (a crash left neither) and stated a session
|
|
3
|
+
* lifetime the code did not have; cycle 5 claimed a logout that failed. */
|
|
4
|
+
export declare const isDeliveryDocument: (file: string) => boolean;
|
|
5
|
+
/** Markdown files the request asks to be delivered that do not exist yet.
|
|
6
|
+
* Inputs and files the request only refers to are excluded. */
|
|
7
|
+
export declare function missingDeliveryDocuments(requestTexts: readonly string[], existingPaths: readonly string[], inputPaths: readonly string[]): string[];
|
|
8
|
+
/** Statements in a delivered document worth checking: prose lines and list
|
|
9
|
+
* items, without headings, fences, table rules or very short fragments. */
|
|
10
|
+
export declare function deliveryClaims(text: string): string[];
|
|
11
|
+
/** Durations a delivered document states for a setting (a session lifetime, a
|
|
12
|
+
* timeout, a lockout window) that no source setting and no receipt output has.
|
|
13
|
+
* Each finding names the document line and the settings the code does have. */
|
|
14
|
+
export declare function ungroundedDurations(docs: readonly {
|
|
15
|
+
path: string;
|
|
16
|
+
text: string;
|
|
17
|
+
}[], sources: readonly {
|
|
18
|
+
path: string;
|
|
19
|
+
text: string;
|
|
20
|
+
}[], receiptOutputs: readonly string[]): string[];
|
|
21
|
+
//# sourceMappingURL=DeliveryDocs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeliveryDocs.d.ts","sourceRoot":"","sources":["../../src/runtime/DeliveryDocs.ts"],"names":[],"mappings":"AAGA;;2EAE2E;AAC3E,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,OACuF,CAAC;AAU1I;+DAC+D;AAC/D,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,EAAE,aAAa,EAAE,SAAS,MAAM,EAAE,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAuBnJ;AAED;2EAC2E;AAC3E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAYrD;AAyDD;;+EAE+E;AAC/E,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,EAAE,OAAO,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,EACrI,cAAc,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAuB7C"}
|