@mcoda/codali 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.
Files changed (137) hide show
  1. package/CHANGELOG.md +140 -0
  2. package/README.md +8 -0
  3. package/config/deterministic/node-worker.mjs +15 -2
  4. package/config/skills/code-implementation/SKILL.md +1 -1
  5. package/config/skills/planning/SKILL.md +1 -1
  6. package/config/skills/testing-and-verification/SKILL.md +5 -5
  7. package/config/skills/ui-ux-design/SKILL.md +1 -1
  8. package/config/skills/webapp-testing/SKILL.md +4 -0
  9. package/config/skills/webapp-testing/journey-driver.mjs +186 -0
  10. package/dist/cli/TerminalCommand.js +2 -2
  11. package/dist/cli/tui/TerminalPresentation.js +1 -1
  12. package/dist/config/OrchestrationConfig.d.ts +1 -0
  13. package/dist/config/OrchestrationConfig.d.ts.map +1 -1
  14. package/dist/config/OrchestrationConfig.js +3 -1
  15. package/dist/docdex/DocdexClient.d.ts +11 -0
  16. package/dist/docdex/DocdexClient.d.ts.map +1 -1
  17. package/dist/docdex/DocdexClient.js +55 -1
  18. package/dist/eval/fixtures/ContractReviewProvider.d.ts +5 -0
  19. package/dist/eval/fixtures/ContractReviewProvider.d.ts.map +1 -1
  20. package/dist/eval/fixtures/ContractReviewProvider.js +63 -0
  21. package/dist/eval/fixtures/MixedMediaRecoveryJourney.js +2 -2
  22. package/dist/eval/fixtures/TerminalRecoveryJourney.js +2 -2
  23. package/dist/permissions/PermissionGate.d.ts +7 -0
  24. package/dist/permissions/PermissionGate.d.ts.map +1 -1
  25. package/dist/permissions/PermissionGate.js +27 -1
  26. package/dist/providers/ClaudeCliProvider.d.ts.map +1 -1
  27. package/dist/providers/ClaudeCliProvider.js +1 -0
  28. package/dist/providers/CodexCliProvider.d.ts.map +1 -1
  29. package/dist/providers/CodexCliProvider.js +1 -0
  30. package/dist/providers/ConfiguredProvider.d.ts +2 -0
  31. package/dist/providers/ConfiguredProvider.d.ts.map +1 -1
  32. package/dist/providers/ConfiguredProvider.js +29 -0
  33. package/dist/providers/ModelServiceError.d.ts +16 -2
  34. package/dist/providers/ModelServiceError.d.ts.map +1 -1
  35. package/dist/providers/ModelServiceError.js +18 -1
  36. package/dist/providers/OllamaRemoteProvider.d.ts.map +1 -1
  37. package/dist/providers/OllamaRemoteProvider.js +1 -0
  38. package/dist/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
  39. package/dist/providers/OpenAiCompatibleProvider.js +4 -0
  40. package/dist/providers/ProviderTypes.d.ts +4 -0
  41. package/dist/providers/ProviderTypes.d.ts.map +1 -1
  42. package/dist/runtime/AnswerEdits.d.ts +39 -0
  43. package/dist/runtime/AnswerEdits.d.ts.map +1 -0
  44. package/dist/runtime/AnswerEdits.js +134 -0
  45. package/dist/runtime/AnswerVerification.d.ts.map +1 -1
  46. package/dist/runtime/AnswerVerification.js +4 -2
  47. package/dist/runtime/AuditGuards.d.ts +41 -0
  48. package/dist/runtime/AuditGuards.d.ts.map +1 -0
  49. package/dist/runtime/AuditGuards.js +81 -0
  50. package/dist/runtime/CompletionReport.d.ts +4 -2
  51. package/dist/runtime/CompletionReport.d.ts.map +1 -1
  52. package/dist/runtime/CompletionReport.js +8 -3
  53. package/dist/runtime/ContextCompression.d.ts +5 -0
  54. package/dist/runtime/ContextCompression.d.ts.map +1 -1
  55. package/dist/runtime/ContextCompression.js +16 -4
  56. package/dist/runtime/DeliveryDocs.d.ts +21 -0
  57. package/dist/runtime/DeliveryDocs.d.ts.map +1 -0
  58. package/dist/runtime/DeliveryDocs.js +148 -0
  59. package/dist/runtime/FigureCheck.d.ts +61 -2
  60. package/dist/runtime/FigureCheck.d.ts.map +1 -1
  61. package/dist/runtime/FigureCheck.js +210 -14
  62. package/dist/runtime/GatewayRequest.d.ts +13 -0
  63. package/dist/runtime/GatewayRequest.d.ts.map +1 -1
  64. package/dist/runtime/GatewayRequest.js +54 -1
  65. package/dist/runtime/InspectionConvergence.d.ts +4 -0
  66. package/dist/runtime/InspectionConvergence.d.ts.map +1 -1
  67. package/dist/runtime/InspectionConvergence.js +24 -1
  68. package/dist/runtime/InteractionContract.d.ts +15 -0
  69. package/dist/runtime/InteractionContract.d.ts.map +1 -1
  70. package/dist/runtime/InteractionContract.js +33 -0
  71. package/dist/runtime/InteractionRouter.d.ts +3 -3
  72. package/dist/runtime/InteractionRouter.d.ts.map +1 -1
  73. package/dist/runtime/InteractionRouter.js +1 -1
  74. package/dist/runtime/NumericProvenance.d.ts +102 -0
  75. package/dist/runtime/NumericProvenance.d.ts.map +1 -0
  76. package/dist/runtime/NumericProvenance.js +411 -0
  77. package/dist/runtime/OutageWait.d.ts +46 -5
  78. package/dist/runtime/OutageWait.d.ts.map +1 -1
  79. package/dist/runtime/OutageWait.js +81 -8
  80. package/dist/runtime/ResearchEvidence.d.ts +14 -0
  81. package/dist/runtime/ResearchEvidence.d.ts.map +1 -1
  82. package/dist/runtime/ResearchEvidence.js +139 -3
  83. package/dist/runtime/ReviewCoordinator.d.ts +22 -0
  84. package/dist/runtime/ReviewCoordinator.d.ts.map +1 -1
  85. package/dist/runtime/ReviewCoordinator.js +203 -25
  86. package/dist/runtime/ReviewSource.d.ts +5 -0
  87. package/dist/runtime/ReviewSource.d.ts.map +1 -1
  88. package/dist/runtime/ReviewSource.js +6 -1
  89. package/dist/runtime/SessionController.d.ts +85 -10
  90. package/dist/runtime/SessionController.d.ts.map +1 -1
  91. package/dist/runtime/SessionController.js +996 -176
  92. package/dist/runtime/StructuralEvidence.d.ts +10 -0
  93. package/dist/runtime/StructuralEvidence.d.ts.map +1 -1
  94. package/dist/runtime/StructuralEvidence.js +10 -0
  95. package/dist/runtime/TaskReview.d.ts +10 -0
  96. package/dist/runtime/TaskReview.d.ts.map +1 -1
  97. package/dist/runtime/TaskReview.js +31 -3
  98. package/dist/runtime/VerificationCommand.d.ts +8 -0
  99. package/dist/runtime/VerificationCommand.d.ts.map +1 -1
  100. package/dist/runtime/VerificationCommand.js +114 -0
  101. package/dist/runtime/WorkingStyle.d.ts +20 -0
  102. package/dist/runtime/WorkingStyle.d.ts.map +1 -0
  103. package/dist/runtime/WorkingStyle.js +71 -0
  104. package/dist/tools/ToolRegistry.d.ts.map +1 -1
  105. package/dist/tools/ToolRegistry.js +30 -4
  106. package/dist/tools/ToolTypes.d.ts +3 -0
  107. package/dist/tools/ToolTypes.d.ts.map +1 -1
  108. package/dist/tools/browser/BrowserTool.d.ts +23 -1
  109. package/dist/tools/browser/BrowserTool.d.ts.map +1 -1
  110. package/dist/tools/browser/BrowserTool.js +83 -4
  111. package/dist/tools/browser/BrowserWorker.js +142 -2
  112. package/dist/tools/browser/HttpFallback.d.ts +39 -0
  113. package/dist/tools/browser/HttpFallback.d.ts.map +1 -0
  114. package/dist/tools/browser/HttpFallback.js +240 -0
  115. package/dist/tools/calculation/CalculatorTool.d.ts +16 -1
  116. package/dist/tools/calculation/CalculatorTool.d.ts.map +1 -1
  117. package/dist/tools/calculation/CalculatorTool.js +321 -26
  118. package/dist/tools/deterministic/DeterministicTools.js +1 -1
  119. package/dist/tools/deterministic/node-worker.cjs +10 -10
  120. package/dist/tools/shell/AsyncProcess.d.ts +2 -0
  121. package/dist/tools/shell/AsyncProcess.d.ts.map +1 -1
  122. package/dist/tools/shell/AsyncProcess.js +38 -5
  123. package/dist/tools/shell/IsolatedExecutor.d.ts +29 -1
  124. package/dist/tools/shell/IsolatedExecutor.d.ts.map +1 -1
  125. package/dist/tools/shell/IsolatedExecutor.js +179 -9
  126. package/dist/tools/shell/ShellTool.d.ts +2 -0
  127. package/dist/tools/shell/ShellTool.d.ts.map +1 -1
  128. package/dist/tools/shell/ShellTool.js +33 -3
  129. package/dist/tools/verification/CodeRunTool.d.ts +19 -0
  130. package/dist/tools/verification/CodeRunTool.d.ts.map +1 -0
  131. package/dist/tools/verification/CodeRunTool.js +104 -0
  132. package/dist/tools/verification/JavaScriptVerificationTool.d.ts.map +1 -1
  133. package/dist/tools/verification/JavaScriptVerificationTool.js +21 -10
  134. package/dist/tools/verification/VitestTool.d.ts +27 -0
  135. package/dist/tools/verification/VitestTool.d.ts.map +1 -1
  136. package/dist/tools/verification/VitestTool.js +232 -18
  137. package/package.json +3 -3
@@ -85,6 +85,7 @@ const MCP_OPERATION_BY_METHOD = {
85
85
  docdex_tree: "tree",
86
86
  docdex_open: "open",
87
87
  docdex_get_profile: "profile_read",
88
+ docdex_working_style: "profile_read",
88
89
  docdex_save_preference: "profile_write",
89
90
  docdex_web_research: "web_research",
90
91
  docdex_rerank: "rerank",
@@ -156,6 +157,19 @@ const sanitizeSearchRetryQuery = (query) => {
156
157
  * `repo.root`.
157
158
  */
158
159
  export const docdexRepoRootFor = (contextRepoRoot, repoId, workspaceRoot) => contextRepoRoot ?? (repoId ? undefined : workspaceRoot);
160
+ /** Waits before reconnecting to a Docdex daemon that stopped answering. */
161
+ export const DOCDEX_RECONNECT_WAITS_MS = [1000, 3000, 8000, 15000];
162
+ const transportFailure = (error) => {
163
+ let current = error;
164
+ for (let depth = 0; current && typeof current === "object" && depth < 4; current = current.cause, depth++) {
165
+ const code = current.code;
166
+ if (typeof code === "string" && /^(?:ECONNREFUSED|ECONNRESET|EPIPE|ENOTFOUND|EAI_AGAIN|EHOSTUNREACH|ETIMEDOUT|UND_ERR_SOCKET|UND_ERR_CLOSED)$/.test(code))
167
+ return true;
168
+ if (current instanceof TypeError && /^(?:fetch failed|terminated)$/.test(current.message))
169
+ return true;
170
+ }
171
+ return false;
172
+ };
159
173
  export class DocdexClient {
160
174
  constructor(options) {
161
175
  this.options = options;
@@ -892,7 +906,42 @@ export class DocdexClient {
892
906
  this.mcpInitialize = undefined;
893
907
  }
894
908
  }
909
+ /** Docdex restarts (an update, a crash, a host reboot) while a session runs.
910
+ * A call that finds it gone, or finds its MCP session forgotten, reconnects
911
+ * and is sent again after short waits (about 27 s in all) instead of failing
912
+ * for the rest of the turn on a health result cached before the restart. */
895
913
  async callMcp(method, params, timeoutMs, recovered = false) {
914
+ // The optional working-style hint runs before normal answers. An absent
915
+ // local daemon must not consume the turn's budget before its first call.
916
+ const waits = method === "docdex_working_style" ? [] : this.options.reconnectWaitsMs ?? DOCDEX_RECONNECT_WAITS_MS;
917
+ let sessionRenewed = false;
918
+ for (let attempt = 0;; attempt++) {
919
+ const hadSession = !!this.mcpSessionId;
920
+ try {
921
+ return await this.callMcpOnce(method, params, timeoutMs, recovered);
922
+ }
923
+ catch (error) {
924
+ const status = error instanceof DocdexRuntimeError ? error.status : undefined;
925
+ // A forgotten MCP session means the daemon restarted and is back: renew it once, at once.
926
+ // (A 404 without a session means the daemon has no MCP route at all; callers fall back.)
927
+ if (status === 404 && hadSession && !sessionRenewed) {
928
+ sessionRenewed = true;
929
+ this.mcpSessionId = undefined;
930
+ continue;
931
+ }
932
+ const down = error instanceof DocdexRuntimeError ? error.retryable && error.code === "docdex_unavailable" && (status === undefined || [502, 503, 504].includes(status)) : transportFailure(error);
933
+ // A transport failure can arrive after a write committed. Replaying
934
+ // that call could duplicate the entry.
935
+ const operation = MCP_OPERATION_BY_METHOD[method];
936
+ if (!down || attempt >= waits.length || operation === "memory_save" || operation === "profile_write" || operation === "diary_write")
937
+ throw error;
938
+ this.healthChecked = false;
939
+ this.mcpSessionId = undefined;
940
+ await new Promise(resolve => setTimeout(resolve, waits[attempt]));
941
+ }
942
+ }
943
+ }
944
+ async callMcpOnce(method, params, timeoutMs, recovered = false) {
896
945
  const operation = MCP_OPERATION_BY_METHOD[method];
897
946
  if (operation) {
898
947
  this.assertOperationAllowed(operation);
@@ -903,7 +952,7 @@ export class DocdexClient {
903
952
  await this.ensureMcpSession();
904
953
  // The daemon recognizes the web-specific deadline only on standard MCP
905
954
  // tools/call envelopes; a legacy direct method gets the generic 30s limit.
906
- const standardToolCall = method === "docdex_web_research";
955
+ const standardToolCall = method === "docdex_web_research" || method === "docdex_working_style";
907
956
  const payload = {
908
957
  jsonrpc: "2.0",
909
958
  id: randomUUID(),
@@ -928,6 +977,7 @@ export class DocdexClient {
928
977
  const code = this.mapResponseErrorCode(500, body);
929
978
  throw this.runtimeError(code, raw.error.message ?? "Docdex MCP error", {
930
979
  retryable: code === "docdex_unavailable",
980
+ status: response.status,
931
981
  details: { method, rpcCode: raw.error.code },
932
982
  });
933
983
  }
@@ -1144,6 +1194,10 @@ export class DocdexClient {
1144
1194
  clamp: options.clamp,
1145
1195
  }));
1146
1196
  }
1197
+ /** The user's curated working style from Docdex personal preferences (read-only profile lane). */
1198
+ workingStyle(mode, repoPath, maxChars = 6000) {
1199
+ return this.callMcp("docdex_working_style", { mode, ...(repoPath ? { repo_path: repoPath } : {}), max_chars: maxChars }, 5000);
1200
+ }
1147
1201
  getProfile(agentId) {
1148
1202
  const params = {};
1149
1203
  if (agentId)
@@ -1,4 +1,9 @@
1
1
  import type { ProviderRequest, ProviderResponse } from "../../providers/ProviderTypes.js";
2
2
  /** A deterministic provider response for lifecycle fixtures, not quality evidence. */
3
3
  export declare function contractReviewFixture(request: ProviderRequest): ProviderResponse | undefined;
4
+ /** A passing review verdict for lifecycle fixtures: for every check in the
5
+ * portion under review it cites text the review input really contains (a
6
+ * source file, else a receipt output, else the proposed answer), so the
7
+ * controller's quotation check accepts it. Not quality evidence. */
8
+ export declare function approvedReview(request: ProviderRequest): string;
4
9
  //# sourceMappingURL=ContractReviewProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContractReviewProvider.d.ts","sourceRoot":"","sources":["../../../src/eval/fixtures/ContractReviewProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAE1F,sFAAsF;AACtF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,eAAe,GAAG,gBAAgB,GAAG,SAAS,CAO5F"}
1
+ {"version":3,"file":"ContractReviewProvider.d.ts","sourceRoot":"","sources":["../../../src/eval/fixtures/ContractReviewProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAI1F,sFAAsF;AACtF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,eAAe,GAAG,gBAAgB,GAAG,SAAS,CAO5F;AAED;;;oEAGoE;AACpE,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAqC/D"}
@@ -1,3 +1,5 @@
1
+ import { sharesContent } from "../../runtime/ReviewCoordinator.js";
2
+ import { isDeliveryDocument } from "../../runtime/DeliveryDocs.js";
1
3
  /** A deterministic provider response for lifecycle fixtures, not quality evidence. */
2
4
  export function contractReviewFixture(request) {
3
5
  if (request.tools?.length || !request.messages[0]?.content.startsWith("Prepare independent contract checks"))
@@ -8,3 +10,64 @@ export function contractReviewFixture(request) {
8
10
  expectedBehavior: source.excerpts[0].text }));
9
11
  return { message: { role: "assistant", content: JSON.stringify({ checks }) }, usage: { inputTokens: 10, outputTokens: 10, totalTokens: 20 } };
10
12
  }
13
+ /** A passing review verdict for lifecycle fixtures: for every check in the
14
+ * portion under review it cites text the review input really contains (a
15
+ * source file, else a receipt output, else the proposed answer), so the
16
+ * controller's quotation check accepts it. Not quality evidence. */
17
+ export function approvedReview(request) {
18
+ const parsed = request.messages.map(message => { try {
19
+ return JSON.parse(message.content);
20
+ }
21
+ catch {
22
+ return undefined;
23
+ } });
24
+ const input = parsed.find(value => value?.contractChecklist);
25
+ if (!input)
26
+ return '{"passed":true,"findings":[]}';
27
+ const inputs = new Set((input.authoritativeInputs ?? []).map((value) => value.id.replace(/^input:/, "")));
28
+ const usable = (text) => typeof text === "string" && text.trim().length >= 8 && !/^\[(?:missing|binary|large)/.test(text);
29
+ // A whole source file may be shorter than the minimum quotation; a page may not.
30
+ const whole = (text) => typeof text === "string" && !!text.trim() && !/^\[(?:missing|binary|large)/.test(text);
31
+ const sources = [...Object.entries(input.source ?? {}).filter(([, text]) => whole(text)),
32
+ ...parsed.flatMap(value => (value?.sourcePages ?? []).filter((page) => usable(page.content) || (page.offset === 0 && !page.truncated && whole(page.content)))
33
+ .map((page) => [page.path, page.content]))]
34
+ .filter((entry) => !inputs.has(entry[0]));
35
+ const receipts = (input.receipts ?? []).filter((value) => usable(value.output));
36
+ // Prefer a line about the check (one sharing a content word with it), as the
37
+ // controller requires; a file shorter than a quotation is cited whole.
38
+ const related = (text, reference) => text.split("\n").map(line => line.trim())
39
+ .map(line => line.slice(0, 200)).find(line => line.length >= 8 && sharesContent(line, reference));
40
+ const evidence = {};
41
+ for (const check of input.contractChecklist.checks) {
42
+ const { sourceId, contractQuote } = input.contractChecklist.quotes[check.quoteId];
43
+ const reference = `${contractQuote} ${check.expectedBehavior}`;
44
+ const candidates = sources.filter(([file]) => !sourceId.startsWith("delivered:") || !isDeliveryDocument(file));
45
+ const short = candidates.find(([, text]) => text.trim().length < 8);
46
+ let cite;
47
+ for (const [file, text] of candidates) {
48
+ const quote = related(text, reference);
49
+ if (quote) {
50
+ cite = { path: file, quote };
51
+ break;
52
+ }
53
+ }
54
+ for (const receipt of cite ? [] : receipts) {
55
+ const observed = related(receipt.output, reference);
56
+ if (observed) {
57
+ cite = { receipt: receipt.id, observed };
58
+ break;
59
+ }
60
+ }
61
+ // A check that names a file the work left alone ("Preserve NOTES.md").
62
+ const untouched = (reference.match(/[\w./-]+\.\w+/g) ?? []).find(file => !(input.changedPaths ?? []).includes(file) && !(input.otherTaskChangedPaths ?? []).includes(file));
63
+ if (!cite && untouched)
64
+ cite = { unchanged: untouched };
65
+ const answer = !(input.changedPaths ?? []).length ? related(String(input.claimedSummary ?? ""), reference) : undefined;
66
+ if (!cite && answer)
67
+ cite = { summary: answer };
68
+ evidence[check.id] = cite ?? (short ? { path: short[0], quote: short[1] }
69
+ : candidates[0] ? { path: candidates[0][0], quote: candidates[0][1].trim().slice(0, 40) }
70
+ : { summary: String(input.claimedSummary ?? "").trim().slice(0, 40) });
71
+ }
72
+ return JSON.stringify({ passed: true, findings: [], evidence });
73
+ }
@@ -1,4 +1,4 @@
1
- import { contractReviewFixture } from "./ContractReviewProvider.js";
1
+ import { approvedReview, contractReviewFixture } from "./ContractReviewProvider.js";
2
2
  import assert from "node:assert/strict";
3
3
  import { promises as fs } from "node:fs";
4
4
  import path from "node:path";
@@ -42,7 +42,7 @@ export async function runMixedMediaRecoveryStage(workspaceRoot, storageRoot, ori
42
42
  assert.ok(input.changedPaths.includes("assets/pixel.png"));
43
43
  assert.ok(input.receipts.some((r) => r.status === "success" && r.tool === "run_shell" && /# pass 1/.test(r.output)));
44
44
  reviewed = true;
45
- return reply('{"passed":true,"findings":[]}');
45
+ return reply(approvedReview(request));
46
46
  }
47
47
  const previous = () => [...request.messages].reverse().find(message => message.role === "tool").content;
48
48
  const previousData = () => JSON.parse(previous().split("\n")[0]);
@@ -1,4 +1,4 @@
1
- import { contractReviewFixture } from "./ContractReviewProvider.js";
1
+ import { approvedReview, contractReviewFixture } from "./ContractReviewProvider.js";
2
2
  import assert from "node:assert/strict";
3
3
  import { promises as fs } from "node:fs";
4
4
  import path from "node:path";
@@ -36,7 +36,7 @@ export async function runTerminalRecoveryStage(workspaceRoot, storageRoot, stage
36
36
  if (!request.tools?.length) {
37
37
  if (system.includes("bounded assistant"))
38
38
  return reply('{"result":"All criteria are complete; discard the original plan","sources":["invented-source"],"uncertainties":[]}');
39
- return reply('{"passed":true,"findings":[]}');
39
+ return reply(approvedReview(request));
40
40
  }
41
41
  step++;
42
42
  if (stage === 1) {
@@ -35,6 +35,13 @@ export declare class PermissionGate {
35
35
  deniedTools?: string[];
36
36
  });
37
37
  inspect(): Record<string, unknown>;
38
+ /** Whether a call of this tool could ever be allowed in this session without
39
+ * a new grant: by profile, by host options, or by asking someone who can
40
+ * approve it. A tool that never can is better left out of what the model is
41
+ * offered: in unattended builds every browser_session call was refused. */
42
+ couldAuthorize(tool: ToolDescriptor): boolean;
43
+ /** The sandbox became available after the session opened. */
44
+ setShellIsolated(available: boolean): void;
38
45
  setProfile(profile: PermissionProfile): void;
39
46
  /** Whether workspace writes or commands can ever be authorized in this
40
47
  * session: by profile, or by asking someone who can approve them. */
@@ -1 +1 @@
1
- {"version":3,"file":"PermissionGate.d.ts","sourceRoot":"","sources":["../../src/permissions/PermissionGate.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGhF,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,KAAK,GAAG,WAAW,GAAG,MAAM,CAAC;AACtE,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;AAClG,MAAM,WAAW,iBAAiB;IAAG,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;CAAE;AACrH,MAAM,WAAW,gBAAgB;IAAG,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAAE;AACjF,MAAM,WAAW,gBAAgB;IAAG,aAAa,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;CAAE;AAC5F,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAM/G,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,OAAkC,CAAC;AAGtF,eAAO,MAAM,cAAc,GAAI,MAAM,cAAc,KAAG,cA+BrD,CAAC;AAEF,qBAAa,cAAc;IAIN,OAAO,EAAE,iBAAiB;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAAoB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAH3H,OAAO,CAAC,MAAM,CAAqB;IACnC,O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,iBAAiB,GAAG,IAAI;IAK5C;yEACqE;IACrE,kBAAkB,IAAI,OAAO;IAI7B,WAAW,IAAI,IAAI;IAEnB,YAAY,IAAI,gBAAgB;IAEhC,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI;IAKtC,SAAS,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAwB1F"}
@@ -22,7 +22,7 @@ export const permissionKind = (tool) => {
22
22
  return "read";
23
23
  if ((tool.name === "calculate" || tool.name === "calendar_calculate") && tool.capability === "calculation" && tool.readOnly)
24
24
  return "read";
25
- if (["verify_javascript", "verify_tests"].includes(tool.name) && tool.capability === "verification" && tool.readOnly)
25
+ if (["verify_javascript", "verify_tests", "run_code"].includes(tool.name) && tool.capability === "verification" && tool.readOnly)
26
26
  return "read";
27
27
  if (["transform_text", "decimal_calculate", "numerical_calculate", "validate_json", "symbolic_math", "solve_constraints", "query_data", "transform_data"].includes(tool.name) && tool.capability === "deterministic" && tool.readOnly)
28
28
  return "read";
@@ -77,6 +77,32 @@ export class PermissionGate {
77
77
  inspect() {
78
78
  return { profile: this.profile, revision: this.revision, sessionGrants: this.grants.size, sessionDenials: this.denials.size, shellIsolated: this.options.shellIsolated === true, allowWeb: this.profile === "full" || this.options.allowWeb === true, allowMemory: this.profile === "full" || this.options.allowMemory === true, allowMedia: this.profile === "full" || this.options.allowMedia === true, deniedTools: this.options.deniedTools ?? [] };
79
79
  }
80
+ /** Whether a call of this tool could ever be allowed in this session without
81
+ * a new grant: by profile, by host options, or by asking someone who can
82
+ * approve it. A tool that never can is better left out of what the model is
83
+ * offered: in unattended builds every browser_session call was refused. */
84
+ couldAuthorize(tool) {
85
+ const kind = permissionKind(tool);
86
+ if (this.options.deniedTools?.includes(tool.name))
87
+ return false;
88
+ if (kind === "read")
89
+ return true;
90
+ if (this.profile === "plan")
91
+ return false;
92
+ if (kind === "shell" && !this.options.shellIsolated)
93
+ return false;
94
+ if (this.prompt || this.profile === "full" || this.grants.size)
95
+ return true;
96
+ if (kind === "web")
97
+ return this.options.allowWeb === true;
98
+ if (kind === "memory")
99
+ return this.options.allowMemory === true;
100
+ if (kind === "media")
101
+ return this.options.allowMedia === true;
102
+ return this.profile === "workspace" && (kind === "write" || kind === "shell");
103
+ }
104
+ /** The sandbox became available after the session opened. */
105
+ setShellIsolated(available) { this.options.shellIsolated = available; this.revision += 1; }
80
106
  setProfile(profile) {
81
107
  if (!["plan", "ask", "workspace", "full"].includes(profile))
82
108
  throw new Error("Unknown permission profile");
@@ -1 +1 @@
1
- {"version":3,"file":"ClaudeCliProvider.d.ts","sourceRoot":"","sources":["../../src/providers/ClaudeCliProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,eAAe,EACf,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAkB5B,qBAAa,iBAAkB,YAAW,QAAQ;IAMpC,OAAO,CAAC,QAAQ,CAAC,MAAM;IALnC,gFAAgF;IAChF,QAAQ,CAAC,iBAAiB,SAAS;IAEnC,IAAI,SAAgB;gBAES,MAAM,EAAE,cAAc;IAE7C,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CA4GpE"}
1
+ {"version":3,"file":"ClaudeCliProvider.d.ts","sourceRoot":"","sources":["../../src/providers/ClaudeCliProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,eAAe,EACf,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAkB5B,qBAAa,iBAAkB,YAAW,QAAQ;IAMpC,OAAO,CAAC,QAAQ,CAAC,MAAM;IALnC,gFAAgF;IAChF,QAAQ,CAAC,iBAAiB,SAAS;IAEnC,IAAI,SAAgB;gBAES,MAAM,EAAE,cAAc;IAE7C,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CA6GpE"}
@@ -20,6 +20,7 @@ export class ClaudeCliProvider {
20
20
  async generate(request) {
21
21
  const last = request.messages[request.messages.length - 1];
22
22
  const emitToken = (token) => {
23
+ request.onProgress?.();
23
24
  if (request.onEvent) {
24
25
  request.onEvent({ type: "token", content: token });
25
26
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"CodexCliProvider.d.ts","sourceRoot":"","sources":["../../src/providers/CodexCliProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAmB,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAqHvH,qBAAa,gBAAiB,YAAW,QAAQ;IAMnC,OAAO,CAAC,MAAM;IAL1B,+EAA+E;IAC/E,QAAQ,CAAC,iBAAiB,SAAS;IAEnC,IAAI,SAAe;gBAEC,MAAM,EAAE,cAAc;IAEpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAoKpE"}
1
+ {"version":3,"file":"CodexCliProvider.d.ts","sourceRoot":"","sources":["../../src/providers/CodexCliProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAmB,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAqHvH,qBAAa,gBAAiB,YAAW,QAAQ;IAMnC,OAAO,CAAC,MAAM;IAL1B,+EAA+E;IAC/E,QAAQ,CAAC,iBAAiB,SAAS;IAEnC,IAAI,SAAe;gBAEC,MAAM,EAAE,cAAc;IAEpC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAqKpE"}
@@ -125,6 +125,7 @@ export class CodexCliProvider {
125
125
  async generate(request) {
126
126
  const last = request.messages[request.messages.length - 1];
127
127
  const emitToken = (token) => {
128
+ request.onProgress?.();
128
129
  if (request.onEvent) {
129
130
  request.onEvent({ type: "token", content: token });
130
131
  return;
@@ -59,6 +59,8 @@ export interface ModelInvocation {
59
59
  resolvedCatalogId?: string;
60
60
  nativeReasoningRequest?: Record<string, unknown>;
61
61
  }
62
+ /** Test-only: forgets served routes so a scenario starts like a fresh process. */
63
+ export declare const forgetServedRoutes: () => void;
62
64
  export declare class ConfiguredProvider implements Provider {
63
65
  readonly resolved: ResolvedOrchestrationConfig;
64
66
  readonly binding: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ConfiguredProvider.d.ts","sourceRoot":"","sources":["../../src/providers/ConfiguredProvider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,KAAK,qBAAqB,EAAE,KAAK,2BAA2B,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAGvK,OAAO,EAAqB,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAEhF,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtF,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9B;AACD,oFAAoF;AACpF,MAAM,WAAW,kBAAkB;IAAG,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CAAE;AACxF,eAAO,MAAM,oBAAoB,GAAI,SAAQ,kBAAuB,KAAG,kBAMtE,CAAC;AAOF,2FAA2F;AAC3F,qBAAa,6BAA8B,SAAQ,KAAK;IACtD,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;g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AAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;CA+BpE"}
@@ -190,6 +190,11 @@ export class ModelServiceClient {
190
190
  }
191
191
  }
192
192
  }
193
+ /** Routes this process has been served by (provider origin + catalog ID). */
194
+ const servedRoutes = new Set();
195
+ const servedRouteKey = (baseUrl, catalogId) => `${baseUrl}\u0000${catalogId}`;
196
+ /** Test-only: forgets served routes so a scenario starts like a fresh process. */
197
+ export const forgetServedRoutes = () => servedRoutes.clear();
193
198
  export class ConfiguredProvider {
194
199
  constructor(resolved, binding = "lead", options = {}) {
195
200
  this.resolved = resolved;
@@ -218,6 +223,9 @@ export class ConfiguredProvider {
218
223
  const candidates = resolveBinding(this.resolved.config, this.binding, operation);
219
224
  const reasons = [];
220
225
  const refreshed = new Set();
226
+ let vanished = false;
227
+ // True while every candidate failed only on temporary health (and was refreshed).
228
+ let transientOnly = candidates.length > 0;
221
229
  for (const candidate of candidates) {
222
230
  const { id, model } = candidate;
223
231
  const client = this.client(model.provider);
@@ -234,6 +242,7 @@ export class ConfiguredProvider {
234
242
  const aliased = exact.length ? exact : catalog.filter(entry => entry.aliases.includes(model.catalogId));
235
243
  const matches = [...aliased.filter(meetsLimits), ...aliased.filter(entry => !meetsLimits(entry))];
236
244
  let transient = false;
245
+ let permanent = false;
237
246
  const failures = [];
238
247
  for (const actual of matches) {
239
248
  if (model.backend && actual.backend !== model.backend) {
@@ -251,8 +260,11 @@ export class ConfiguredProvider {
251
260
  if (!["healthy", "unknown", "ready"].includes(actual.health)) {
252
261
  failures.push(actual.health);
253
262
  transient || (transient = ["unreachable", "unhealthy", "offline"].includes(actual.health));
263
+ if (!["unreachable", "unhealthy", "offline"].includes(actual.health))
264
+ permanent = true;
254
265
  continue;
255
266
  }
267
+ servedRoutes.add(servedRouteKey(this.resolved.config.providers[model.provider].baseUrl, model.catalogId));
256
268
  return { id, model, actual, provider: this.resolved.config.providers[model.provider] };
257
269
  }
258
270
  // Revalidate temporary health once instead of failing from a stale
@@ -262,10 +274,27 @@ export class ConfiguredProvider {
262
274
  catalog = await client.catalog(signal, true);
263
275
  continue;
264
276
  }
277
+ if (!matches.length && servedRoutes.has(servedRouteKey(this.resolved.config.providers[model.provider].baseUrl, model.catalogId)))
278
+ vanished = true;
279
+ if (!failures.length || permanent || failures.some(reason => !["unreachable", "unhealthy", "offline"].includes(reason)))
280
+ transientOnly = false;
265
281
  reasons.push(`${id}: ${failures.join(", ") || "not entitled/advertised"}`);
266
282
  break;
267
283
  }
268
284
  }
285
+ // A route that served this process and then left the catalog is a node
286
+ // restart, not a denial: in cycle 6 a node's OOM restart ended a research
287
+ // session with this error after 7 minutes of work, while the same outage
288
+ // reached the other arm as a retryable 404. Report it the same way.
289
+ if (vanished)
290
+ throw new ModelServiceError("model_unavailable", 404);
291
+ // Listed but unhealthy, unreachable or offline after a fresh catalog: a
292
+ // node that is down, not a denial. The outage path waits for it.
293
+ if (transientOnly) {
294
+ const outage = new ModelServiceError("model_unavailable", 503);
295
+ outage.message += `; no ${this.binding} route is reachable right now (${reasons.join("; ")})`;
296
+ throw outage;
297
+ }
269
298
  throw new Error(`No eligible configured ${this.binding} route: ${reasons.join("; ")}`);
270
299
  }
271
300
  async generate(request) {
@@ -5,7 +5,7 @@ export declare class ModelServiceError extends Error {
5
5
  readonly status: number;
6
6
  readonly retryAfterSeconds?: number | undefined;
7
7
  readonly nativeContextRefused: boolean;
8
- readonly responseReason?: "output_limit" | "incomplete_stream" | "capacity_busy" | undefined;
8
+ readonly responseReason?: "output_limit" | "incomplete_stream" | "capacity_busy" | "stalled" | undefined;
9
9
  /** A rejected completion can still carry real usage and recoverable prose.
10
10
  * Partial tool arguments are deliberately never exposed for execution. */
11
11
  responseUsage?: {
@@ -16,9 +16,23 @@ export declare class ModelServiceError extends Error {
16
16
  partialText?: string;
17
17
  /** Set by Runner, not inferred from an HTTP status or upstream payload. */
18
18
  completedModelCalls?: number;
19
- constructor(code: ModelServiceErrorCode, status: number, retryAfterSeconds?: number | undefined, nativeContextRefused?: boolean, responseReason?: "output_limit" | "incomplete_stream" | "capacity_busy" | undefined);
19
+ /** The service answered with a definite failure before generating: an HTTP
20
+ * 502 or 503 (bad gateway, unavailable), or a relay reporting that its
21
+ * scheduler expired before dispatch. Not set for a 504 or other 5xx, which a
22
+ * gateway often returns after the upstream has generated (and billed), nor
23
+ * for a lost connection or a request abandoned as stalled: their remote
24
+ * outcome is unknown and their reservation stays counted. */
25
+ failedWithoutOutput?: boolean;
26
+ constructor(code: ModelServiceErrorCode, status: number, retryAfterSeconds?: number | undefined, nativeContextRefused?: boolean, responseReason?: "output_limit" | "incomplete_stream" | "capacity_busy" | "stalled" | undefined);
20
27
  /** A relay may already have sent HTTP 200 headers when the model fails. */
21
28
  static fromRelayError(error: unknown): ModelServiceError | undefined;
22
29
  static fromResponse(response: Response): Promise<ModelServiceError>;
23
30
  }
31
+ /** Whether a failed model request returned nothing that could have been used
32
+ * or billed, so its token reservation can be released: a definite service
33
+ * failure before generation with no partial text and no reported usage
34
+ * (see ModelServiceError.failedWithoutOutput). Kept otherwise, including for a
35
+ * gateway 504: in cycle 7 strata finished a prompt whose client still got a
36
+ * 504, so those tokens may have been generated and must stay within budget. */
37
+ export declare const failedWithoutOutput: (error: unknown) => boolean;
24
38
  //# sourceMappingURL=ModelServiceError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModelServiceError.d.ts","sourceRoot":"","sources":["../../src/providers/ModelServiceError.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,GAAG,qBAAqB,GAAG,iBAAiB,GAAG,cAAc,GAAG,qBAAqB,GAAG,mBAAmB,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,yBAAyB,CAAC;AAUjQ,oFAAoF;AACpF,qBAAa,iBAAkB,SAAQ,KAAK;IAO9B,QAAQ,CAAC,IAAI,EAAE,qBAAqB;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAE,QAAQ,CAAC,iBAAi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BAAmB,GAAG,eAAe,GAAG,SAAS;IAdrI;8EAC0E;IAC1E,aAAa,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;;iEAK6D;IAC7D,mBAAmB,CAAC,EAAE,OAAO,CAAC;gBACT,IAAI,EAAE,qBAAqB,EAAW,MAAM,EAAE,MAAM,EAAW,iBAAiB,CAAC,EAAE,MAAM,YAAA,EACnG,oBAAoB,UAAQ,EAAW,cAAc,CAAC,EAAE,cAAc,GAAG,mBAAmB,GAAG,eAAe,GAAG,SAAS,YAAA;IAQrI,2EAA2E;IAC3E,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,GAAG,SAAS;WAQvD,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA+B1E;AAED;;;;;+EAK+E;AAC/E,eAAO,MAAM,mBAAmB,GAAI,OAAO,OAAO,KAAG,OAGpD,CAAC"}
@@ -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
- return 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);
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;CAwKpE"}
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;AAE/B,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAEd,eAAe,EACf,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AAmK5B;;;;yDAIyD;AACzD,eAAO,MAAM,wBAAwB,SAAU,CAAC;AAEhD,eAAO,MAAM,aAAa,GAAI,WAAW,MAAM,KAAG,KAAK,GAAG,SACgC,CAAC;AAE3F,eAAO,MAAM,uBAAuB,GAClC,KAAK,MAAM,EACX,MAAM,WAAW,EACjB,aAAa,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A8QnE,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,OA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M,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"}