@open-cr-agent/core 0.5.0 → 0.7.0

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 (207) hide show
  1. package/README.md +1 -1
  2. package/dist/{pipeline → agent}/budget.d.ts +0 -1
  3. package/dist/{pipeline → agent}/budget.js +0 -1
  4. package/dist/agent/json.d.ts +1 -0
  5. package/dist/agent/json.js +11 -0
  6. package/dist/{pipeline → agent}/pool.d.ts +0 -1
  7. package/dist/{pipeline → agent}/pool.js +2 -2
  8. package/dist/{pipeline/agents.d.ts → agent/settings.d.ts} +9 -5
  9. package/dist/{pipeline/agents.js → agent/settings.js} +14 -6
  10. package/dist/{pipeline → agent}/usage.d.ts +0 -1
  11. package/dist/{pipeline → agent}/usage.js +0 -1
  12. package/dist/anchor/anchor.d.ts +0 -1
  13. package/dist/anchor/anchor.js +0 -1
  14. package/dist/anchor/match.d.ts +0 -1
  15. package/dist/anchor/match.js +5 -5
  16. package/dist/anchor/relocate.d.ts +1 -3
  17. package/dist/anchor/relocate.js +2 -3
  18. package/dist/at.d.ts +1 -0
  19. package/dist/at.js +11 -0
  20. package/dist/bounded-file.d.ts +12 -0
  21. package/dist/bounded-file.js +47 -0
  22. package/dist/bundle/bundle.d.ts +2 -2
  23. package/dist/bundle/bundle.js +3 -3
  24. package/dist/bundle/grouping.d.ts +0 -2
  25. package/dist/bundle/grouping.js +0 -1
  26. package/dist/bundle/runtime-grouper.d.ts +4 -0
  27. package/dist/{pipeline/helpers.js → bundle/runtime-grouper.js} +4 -14
  28. package/dist/contracts.d.ts +16 -15
  29. package/dist/contracts.js +6 -2
  30. package/dist/diff/hunks.d.ts +0 -1
  31. package/dist/diff/hunks.js +3 -3
  32. package/dist/diff/parse.d.ts +0 -1
  33. package/dist/diff/parse.js +5 -5
  34. package/dist/diff/quoted-path.d.ts +0 -1
  35. package/dist/diff/quoted-path.js +16 -16
  36. package/dist/domain.d.ts +14 -3
  37. package/dist/domain.js +2 -3
  38. package/dist/errors.d.ts +3 -2
  39. package/dist/errors.js +12 -1
  40. package/dist/hash.d.ts +1 -0
  41. package/dist/hash.js +6 -0
  42. package/dist/index.d.ts +27 -13
  43. package/dist/index.js +16 -6
  44. package/dist/internal.d.ts +10 -13
  45. package/dist/internal.js +10 -13
  46. package/dist/judge/judge.d.ts +1 -3
  47. package/dist/judge/judge.js +9 -9
  48. package/dist/judge/prompt.d.ts +0 -1
  49. package/dist/judge/prompt.js +0 -1
  50. package/dist/judge/verdict.d.ts +0 -2
  51. package/dist/judge/verdict.js +1 -2
  52. package/dist/memory/memory.d.ts +0 -1
  53. package/dist/memory/memory.js +2 -3
  54. package/dist/net/proxied-fetch.d.ts +0 -1
  55. package/dist/net/proxied-fetch.js +2 -2
  56. package/dist/pipeline/assemble-report.d.ts +21 -0
  57. package/dist/pipeline/assemble-report.js +98 -0
  58. package/dist/pipeline/check-stage.d.ts +12 -0
  59. package/dist/pipeline/check-stage.js +69 -0
  60. package/dist/pipeline/context.d.ts +2 -2
  61. package/dist/pipeline/context.js +8 -5
  62. package/dist/pipeline/coverage.d.ts +1 -2
  63. package/dist/pipeline/coverage.js +38 -17
  64. package/dist/pipeline/execute-stage.d.ts +25 -0
  65. package/dist/pipeline/execute-stage.js +130 -0
  66. package/dist/pipeline/execute.d.ts +11 -6
  67. package/dist/pipeline/execute.js +147 -59
  68. package/dist/pipeline/filter-stage.d.ts +15 -0
  69. package/dist/pipeline/filter-stage.js +45 -0
  70. package/dist/pipeline/findings.d.ts +0 -1
  71. package/dist/pipeline/findings.js +3 -3
  72. package/dist/pipeline/imports.d.ts +1 -2
  73. package/dist/pipeline/imports.js +1 -2
  74. package/dist/pipeline/matrix.d.ts +1 -9
  75. package/dist/pipeline/matrix.js +0 -1
  76. package/dist/pipeline/options.d.ts +66 -0
  77. package/dist/pipeline/options.js +8 -0
  78. package/dist/pipeline/plan-output.d.ts +89 -0
  79. package/dist/pipeline/plan-output.js +108 -0
  80. package/dist/pipeline/plan.d.ts +3 -5
  81. package/dist/pipeline/plan.js +10 -6
  82. package/dist/pipeline/preview.d.ts +23 -10
  83. package/dist/pipeline/preview.js +25 -5
  84. package/dist/pipeline/provenance.d.ts +4 -28
  85. package/dist/pipeline/provenance.js +2 -3
  86. package/dist/pipeline/resume.d.ts +22 -0
  87. package/dist/pipeline/resume.js +24 -0
  88. package/dist/pipeline/run-id.d.ts +0 -1
  89. package/dist/pipeline/run-id.js +0 -1
  90. package/dist/pipeline/run.d.ts +2 -49
  91. package/dist/pipeline/run.js +18 -274
  92. package/dist/pipeline/task.d.ts +5 -10
  93. package/dist/pipeline/task.js +10 -8
  94. package/dist/plugin/builtin.d.ts +1 -1
  95. package/dist/plugin/builtin.js +12 -3
  96. package/dist/plugin/host.d.ts +0 -1
  97. package/dist/plugin/host.js +0 -1
  98. package/dist/plugin/registry.d.ts +5 -5
  99. package/dist/plugin/registry.js +3 -4
  100. package/dist/plugin/types.d.ts +3 -6
  101. package/dist/plugin/types.js +0 -1
  102. package/dist/{pipeline → report}/output-schema.d.ts +95 -63
  103. package/dist/{pipeline → report}/output-schema.js +64 -42
  104. package/dist/report/output.d.ts +7 -0
  105. package/dist/report/output.js +214 -0
  106. package/dist/report/provenance.d.ts +25 -0
  107. package/dist/report/provenance.js +1 -0
  108. package/dist/report/read.d.ts +2 -0
  109. package/dist/report/read.js +36 -0
  110. package/dist/{pipeline → report}/report.d.ts +27 -4
  111. package/dist/{pipeline → report}/report.js +11 -3
  112. package/dist/report/serialize.d.ts +2 -0
  113. package/dist/report/serialize.js +26 -0
  114. package/dist/rereview/presence.d.ts +0 -1
  115. package/dist/rereview/presence.js +1 -2
  116. package/dist/rereview/quote.d.ts +0 -1
  117. package/dist/rereview/quote.js +2 -3
  118. package/dist/rereview/reconcile.d.ts +1 -2
  119. package/dist/rereview/reconcile.js +0 -1
  120. package/dist/review/impact.d.ts +0 -3
  121. package/dist/review/impact.js +2 -3
  122. package/dist/review/plan-phase.d.ts +1 -3
  123. package/dist/review/plan-phase.js +2 -3
  124. package/dist/review/prompt-text.d.ts +1 -2
  125. package/dist/review/prompt-text.js +1 -2
  126. package/dist/review/prompt.d.ts +0 -4
  127. package/dist/review/prompt.js +3 -4
  128. package/dist/review/reviewer.d.ts +0 -1
  129. package/dist/review/reviewer.js +0 -1
  130. package/dist/review/reviewers/agents-md.d.ts +0 -1
  131. package/dist/review/reviewers/agents-md.js +0 -1
  132. package/dist/review/reviewers/correctness.d.ts +0 -1
  133. package/dist/review/reviewers/correctness.js +0 -1
  134. package/dist/review/reviewers/docs.d.ts +0 -1
  135. package/dist/review/reviewers/docs.js +0 -1
  136. package/dist/review/reviewers/performance.d.ts +0 -1
  137. package/dist/review/reviewers/performance.js +0 -1
  138. package/dist/review/reviewers/scopes.d.ts +0 -1
  139. package/dist/review/reviewers/scopes.js +0 -1
  140. package/dist/review/reviewers/security.d.ts +0 -1
  141. package/dist/review/reviewers/security.js +0 -1
  142. package/dist/review/tools.d.ts +0 -1
  143. package/dist/review/tools.js +0 -1
  144. package/dist/rules/builtin/general.d.ts +0 -1
  145. package/dist/rules/builtin/general.js +0 -1
  146. package/dist/rules/builtin/go.d.ts +0 -1
  147. package/dist/rules/builtin/go.js +0 -1
  148. package/dist/rules/builtin/index.d.ts +0 -5
  149. package/dist/rules/builtin/index.js +1 -3
  150. package/dist/rules/builtin/java.d.ts +0 -1
  151. package/dist/rules/builtin/java.js +0 -1
  152. package/dist/rules/builtin/performance.d.ts +0 -1
  153. package/dist/rules/builtin/performance.js +0 -1
  154. package/dist/rules/builtin/python.d.ts +0 -1
  155. package/dist/rules/builtin/python.js +0 -1
  156. package/dist/rules/builtin/security.d.ts +0 -1
  157. package/dist/rules/builtin/security.js +0 -1
  158. package/dist/rules/builtin/typescript.d.ts +0 -1
  159. package/dist/rules/builtin/typescript.js +0 -1
  160. package/dist/rules/languages.d.ts +0 -1
  161. package/dist/rules/languages.js +0 -1
  162. package/dist/rules/repo-rules.d.ts +0 -7
  163. package/dist/rules/repo-rules.js +3 -4
  164. package/dist/rules/resolve.d.ts +0 -1
  165. package/dist/rules/resolve.js +0 -1
  166. package/dist/rules/rule-set.d.ts +0 -1
  167. package/dist/rules/rule-set.js +0 -1
  168. package/dist/runtime/attempt.d.ts +15 -2
  169. package/dist/runtime/attempt.js +47 -1
  170. package/dist/runtime/chain-runner.d.ts +18 -0
  171. package/dist/runtime/chain-runner.js +62 -0
  172. package/dist/runtime/effort-capability.d.ts +13 -0
  173. package/dist/runtime/effort-capability.js +69 -0
  174. package/dist/runtime/failback.d.ts +0 -10
  175. package/dist/runtime/failback.js +52 -13
  176. package/dist/runtime/models.d.ts +1 -3
  177. package/dist/runtime/models.js +14 -13
  178. package/dist/runtime/quota.d.ts +1 -1
  179. package/dist/runtime/quota.js +3 -2
  180. package/dist/runtime/tools.d.ts +0 -17
  181. package/dist/runtime/tools.js +3 -4
  182. package/dist/sarif/candidates.d.ts +2 -2
  183. package/dist/sarif/candidates.js +0 -1
  184. package/dist/sarif/schema.d.ts +2 -3
  185. package/dist/sarif/schema.js +4 -5
  186. package/dist/select/patterns.d.ts +0 -1
  187. package/dist/select/patterns.js +0 -1
  188. package/dist/select/select.d.ts +1 -1
  189. package/dist/select/select.js +16 -3
  190. package/dist/session/jsonl.d.ts +4 -4
  191. package/dist/session/jsonl.js +14 -8
  192. package/dist/session/resume-read.d.ts +2 -0
  193. package/dist/session/resume-read.js +128 -0
  194. package/dist/session/seal.d.ts +5 -0
  195. package/dist/session/seal.js +24 -0
  196. package/dist/triage.d.ts +2 -3
  197. package/dist/triage.js +1 -2
  198. package/dist/vcs.d.ts +14 -0
  199. package/dist/vcs.js +1 -0
  200. package/dist/verify/prompt.d.ts +0 -7
  201. package/dist/verify/prompt.js +1 -2
  202. package/dist/verify/verify.d.ts +2 -4
  203. package/dist/verify/verify.js +4 -5
  204. package/package.json +1 -1
  205. package/dist/pipeline/helpers.d.ts +0 -7
  206. package/dist/pipeline/output.d.ts +0 -79
  207. package/dist/pipeline/output.js +0 -132
@@ -44,4 +44,3 @@ export const docsReviewer = {
44
44
  systemPrompt: SYSTEM_PROMPT,
45
45
  scope: { minTier: "lite", ignore: [...TEST_FILES] },
46
46
  };
47
- //# sourceMappingURL=docs.js.map
@@ -1,3 +1,2 @@
1
1
  import type { ReviewerDefinition } from "../reviewer.js";
2
2
  export declare const performanceReviewer: ReviewerDefinition;
3
- //# sourceMappingURL=performance.d.ts.map
@@ -56,4 +56,3 @@ export const performanceReviewer = {
56
56
  },
57
57
  rules: { general: PERFORMANCE_RULES },
58
58
  };
59
- //# sourceMappingURL=performance.js.map
@@ -1,3 +1,2 @@
1
1
  export declare const DOCUMENTATION_FILES: string[];
2
2
  export declare const TEST_FILES: string[];
3
- //# sourceMappingURL=scopes.d.ts.map
@@ -6,4 +6,3 @@ export const TEST_FILES = [
6
6
  "**/{__tests__,__fixtures__,__snapshots__,__mocks__}/**",
7
7
  "**/{test,tests,fixtures,testdata}/**",
8
8
  ];
9
- //# sourceMappingURL=scopes.js.map
@@ -1,3 +1,2 @@
1
1
  import type { ReviewerDefinition } from "../reviewer.js";
2
2
  export declare const securityReviewer: ReviewerDefinition;
3
- //# sourceMappingURL=security.d.ts.map
@@ -49,4 +49,3 @@ export const securityReviewer = {
49
49
  scope: { minTier: "lite", ignore: [...DOCUMENTATION_FILES, ...TEST_FILES] },
50
50
  rules: { general: SECURITY_RULES },
51
51
  };
52
- //# sourceMappingURL=security.js.map
@@ -6,4 +6,3 @@ export declare const REVIEW_TOOLS: {
6
6
  readonly taskDone: "task_done";
7
7
  };
8
8
  export type ReviewToolName = (typeof REVIEW_TOOLS)[keyof typeof REVIEW_TOOLS];
9
- //# sourceMappingURL=tools.d.ts.map
@@ -5,4 +5,3 @@ export const REVIEW_TOOLS = {
5
5
  reportFinding: "report_finding",
6
6
  taskDone: "task_done",
7
7
  };
8
- //# sourceMappingURL=tools.js.map
@@ -1,2 +1 @@
1
1
  export declare const GENERAL_RULES = "### General correctness\n- Logic that produces a wrong result on a reachable input: inverted or incomplete conditions, off-by-one bounds, wrong operator, wrong variable, unreachable or dead branches that were meant to run.\n- Broken contracts between changed code and its callers or callees: changed signatures, return shapes, units, nullability or error behavior whose other side was not updated.\n- Error handling that hides failure: swallowed exceptions, errors converted to success or default values, partial writes reported as complete, cleanup that masks the original error.\n- State and resource bugs: missing cleanup on error paths, double release, leaked handles, mutation of shared or input data that callers do not expect.\n- Concurrency hazards that the code makes reachable: unsynchronized shared state, check-then-act races, missing cancellation or timeouts on blocking work.\n- Data integrity: lost updates, non-idempotent retries, inconsistent writes across stores, incorrect migrations or backfills.\n- Security defects visible in the change: injection, missing authorization on a new path, secrets in code or logs, unsafe deserialization.";
2
- //# sourceMappingURL=general.d.ts.map
@@ -6,4 +6,3 @@ export const GENERAL_RULES = `### General correctness
6
6
  - Concurrency hazards that the code makes reachable: unsynchronized shared state, check-then-act races, missing cancellation or timeouts on blocking work.
7
7
  - Data integrity: lost updates, non-idempotent retries, inconsistent writes across stores, incorrect migrations or backfills.
8
8
  - Security defects visible in the change: injection, missing authorization on a new path, secrets in code or logs, unsafe deserialization.`;
9
- //# sourceMappingURL=general.js.map
@@ -1,2 +1 @@
1
1
  export declare const GO_RULES = "### Go\n- Errors that are ignored, overwritten before being checked, or wrapped with `%v` where callers rely on `errors.Is`/`errors.As`.\n- Typed nil values stored in interfaces and then compared with `nil`; nil map writes; nil pointer dereferences reachable from real inputs.\n- Goroutines that can block forever or outlive their owner; missing cancellation; `context.Background()` used where the caller's context should flow.\n- `WithCancel`/`WithTimeout` whose cancel function is never called; timers or tickers left running.\n- Data races on maps, slices or counters shared between goroutines; locks held across blocking I/O; copying values that contain a `sync.Mutex`.\n- `defer` inside loops that delays cleanup until function exit; deferred `Close` errors dropped on write paths.\n- Loop variable capture in goroutines or closures when the module targets Go older than 1.22.";
2
- //# sourceMappingURL=go.d.ts.map
@@ -6,4 +6,3 @@ export const GO_RULES = `### Go
6
6
  - Data races on maps, slices or counters shared between goroutines; locks held across blocking I/O; copying values that contain a \`sync.Mutex\`.
7
7
  - \`defer\` inside loops that delays cleanup until function exit; deferred \`Close\` errors dropped on write paths.
8
8
  - Loop variable capture in goroutines or closures when the module targets Go older than 1.22.`;
9
- //# sourceMappingURL=go.js.map
@@ -1,9 +1,4 @@
1
- import type { Language } from "../languages.js";
2
1
  import type { RuleSet } from "../rule-set.js";
3
- import { GENERAL_RULES } from "./general.js";
4
2
  export { PERFORMANCE_RULES } from "./performance.js";
5
3
  export { SECURITY_RULES } from "./security.js";
6
- export { GENERAL_RULES };
7
- export declare const LANGUAGE_RULES: Record<Language, string>;
8
4
  export declare const CORRECTNESS_RULES: RuleSet;
9
- //# sourceMappingURL=index.d.ts.map
@@ -5,12 +5,10 @@ import { PYTHON_RULES } from "./python.js";
5
5
  import { TYPESCRIPT_RULES } from "./typescript.js";
6
6
  export { PERFORMANCE_RULES } from "./performance.js";
7
7
  export { SECURITY_RULES } from "./security.js";
8
- export { GENERAL_RULES };
9
- export const LANGUAGE_RULES = {
8
+ const LANGUAGE_RULES = {
10
9
  typescript: TYPESCRIPT_RULES,
11
10
  python: PYTHON_RULES,
12
11
  go: GO_RULES,
13
12
  java: JAVA_RULES,
14
13
  };
15
14
  export const CORRECTNESS_RULES = { general: GENERAL_RULES, languages: LANGUAGE_RULES };
16
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export declare const JAVA_RULES = "### Java\n- `equals`/`hashCode` inconsistencies, reference comparison (`==`) of strings or boxed numbers, and unboxing of possibly-null values.\n- Resources not closed with try-with-resources on paths that can throw; streams, connections or locks leaked on error.\n- Exceptions caught and ignored, logged and then treated as success, or rethrown without the cause.\n- Shared mutable state accessed from multiple threads without synchronization; non-thread-safe types (`SimpleDateFormat`, `HashMap`) in shared fields; double-checked locking without `volatile`.\n- `Optional.get()` or collection access without checking presence; modification of a collection while iterating it.\n- Transaction boundaries that do not cover all related writes; `@Transactional` on private or self-invoked methods.\n- SQL or JPQL built by string concatenation from input; deserialization of untrusted data.";
2
- //# sourceMappingURL=java.d.ts.map
@@ -6,4 +6,3 @@ export const JAVA_RULES = `### Java
6
6
  - \`Optional.get()\` or collection access without checking presence; modification of a collection while iterating it.
7
7
  - Transaction boundaries that do not cover all related writes; \`@Transactional\` on private or self-invoked methods.
8
8
  - SQL or JPQL built by string concatenation from input; deserialization of untrusted data.`;
9
- //# sourceMappingURL=java.js.map
@@ -1,2 +1 @@
1
1
  export declare const PERFORMANCE_RULES = "### Performance\n- Algorithmic complexity that grows with input the code cannot bound: nested loops over the same collections, repeated linear searches or `includes` inside loops where a set or map fits, sorting inside loops.\n- Round trips in loops: database queries, HTTP calls or file reads per item (N+1) where one batched call works; queries on new filters that fetch unbounded result sets without a limit or pagination.\n- Blocking work on latency-sensitive paths: synchronous file, network or CPU-heavy work in request handlers, event loops, UI threads or `async` functions.\n- Memory: whole files, streams or result sets buffered when their size is external; caches, maps or listener lists that grow without eviction or removal.\n- Repeated work on hot paths: recomputation or re-parsing inside loops, regular expressions or serializers rebuilt per call, React renders triggered by unstable dependencies or props.\n- Concurrency: independent I/O awaited one after another on a latency-critical path; unbounded parallelism that overwhelms a pool, a rate limit or memory.\n- Regressions of existing optimizations: removed indexes, caches, batching, streaming or early exits.";
2
- //# sourceMappingURL=performance.d.ts.map
@@ -6,4 +6,3 @@ export const PERFORMANCE_RULES = `### Performance
6
6
  - Repeated work on hot paths: recomputation or re-parsing inside loops, regular expressions or serializers rebuilt per call, React renders triggered by unstable dependencies or props.
7
7
  - Concurrency: independent I/O awaited one after another on a latency-critical path; unbounded parallelism that overwhelms a pool, a rate limit or memory.
8
8
  - Regressions of existing optimizations: removed indexes, caches, batching, streaming or early exits.`;
9
- //# sourceMappingURL=performance.js.map
@@ -1,2 +1 @@
1
1
  export declare const PYTHON_RULES = "### Python\n- Mutable default arguments or class attributes shared across calls or instances when per-call state was intended.\n- Broad `except` (bare or `Exception`) that swallows errors, including `KeyboardInterrupt`/`SystemExit` via bare `except`, or re-raises without the original cause.\n- Resources opened without `with` or `try/finally` on paths that can raise.\n- Blocking calls inside `async def` code, coroutines that are never awaited, or tasks created without keeping a reference.\n- Truthiness checks that misclassify valid values (`0`, `\"\"`, empty collections) where `is None` was meant.\n- Late-binding closures in loops, iteration while mutating the same collection, integer vs float division mistakes.\n- SQL, shell or template strings built from input instead of parameters; `pickle`/`yaml.load` on untrusted data.";
2
- //# sourceMappingURL=python.d.ts.map
@@ -6,4 +6,3 @@ export const PYTHON_RULES = `### Python
6
6
  - Truthiness checks that misclassify valid values (\`0\`, \`""\`, empty collections) where \`is None\` was meant.
7
7
  - Late-binding closures in loops, iteration while mutating the same collection, integer vs float division mistakes.
8
8
  - SQL, shell or template strings built from input instead of parameters; \`pickle\`/\`yaml.load\` on untrusted data.`;
9
- //# sourceMappingURL=python.js.map
@@ -1,2 +1 @@
1
1
  export declare const SECURITY_RULES = "### Security\n- Injection from input that reaches an interpreter: SQL or NoSQL built from strings, shell commands, template rendering, LDAP or XPath, HTML without escaping (XSS), headers or log lines with raw newlines.\n- Server-side request forgery and path traversal: URLs, hosts or file paths built from input without an allow-list or containment check, including archive extraction.\n- Authentication and authorization: new routes, handlers, jobs or queries without the checks their neighbours apply; object access by id without an ownership or tenant check (IDOR); privilege or role checks that can be bypassed or were weakened.\n- Secrets and sensitive data: credentials or tokens in code or config, secrets or personal data written to logs, errors, analytics or responses; session tokens or API keys exposed to the client.\n- Cryptography: home-made crypto, weak or misused algorithms (MD5/SHA-1 for passwords, ECB, static IVs), non-cryptographic randomness for tokens, disabled certificate or signature verification, timing-unsafe secret comparison.\n- Unsafe parsing: deserialization of untrusted data (pickle, Java serialization, YAML full loaders), XML external entities, prototype pollution through deep merges, regular expressions with catastrophic backtracking on input.\n- Resource exhaustion from untrusted input: unbounded sizes, counts, recursion or allocation that an external caller controls.\n- Configuration: permissive CORS with credentials, cookies without Secure/HttpOnly/SameSite where they carry sessions, debug modes or verbose errors enabled in production paths, world-writable files.\n- CI and supply chain: untrusted pull request text or branch names interpolated into workflow `run:` steps, `pull_request_target` checking out untrusted code with secrets, broadened workflow permissions, new dependencies from unexpected sources or install scripts.";
2
- //# sourceMappingURL=security.d.ts.map
@@ -8,4 +8,3 @@ export const SECURITY_RULES = `### Security
8
8
  - Resource exhaustion from untrusted input: unbounded sizes, counts, recursion or allocation that an external caller controls.
9
9
  - Configuration: permissive CORS with credentials, cookies without Secure/HttpOnly/SameSite where they carry sessions, debug modes or verbose errors enabled in production paths, world-writable files.
10
10
  - CI and supply chain: untrusted pull request text or branch names interpolated into workflow \`run:\` steps, \`pull_request_target\` checking out untrusted code with secrets, broadened workflow permissions, new dependencies from unexpected sources or install scripts.`;
11
- //# sourceMappingURL=security.js.map
@@ -1,2 +1 @@
1
1
  export declare const TYPESCRIPT_RULES = "### TypeScript and JavaScript\n- Promises that are neither awaited, returned nor explicitly handled, so failures become unhandled rejections or ordering is lost; `forEach` with async callbacks that callers assume completed.\n- `await` inside loops where independent work was meant to run concurrently, or `Promise.all` over work that must be sequential or bounded.\n- Truthiness checks that misclassify valid values (`0`, `\"\"`, `NaN`, `false`) where `??` or an explicit comparison was needed; `==` comparisons with surprising coercion.\n- Type assertions (`as`, non-null `!`, `any`) that bypass a check the runtime data can actually fail; parsed external data used without validation.\n- Mutation of arguments, shared module state or React state/props in place; missing or wrong hook dependencies that cause stale values or infinite loops.\n- Floating timers, listeners or subscriptions without cleanup on unmount, abort or error.\n- `JSON.parse`, `new URL`, `BigInt` and similar calls on external input without handling their exceptions.";
2
- //# sourceMappingURL=typescript.d.ts.map
@@ -6,4 +6,3 @@ export const TYPESCRIPT_RULES = `### TypeScript and JavaScript
6
6
  - Mutation of arguments, shared module state or React state/props in place; missing or wrong hook dependencies that cause stale values or infinite loops.
7
7
  - Floating timers, listeners or subscriptions without cleanup on unmount, abort or error.
8
8
  - \`JSON.parse\`, \`new URL\`, \`BigInt\` and similar calls on external input without handling their exceptions.`;
9
- //# sourceMappingURL=typescript.js.map
@@ -1,3 +1,2 @@
1
1
  export type Language = "typescript" | "python" | "go" | "java";
2
2
  export declare function detectLanguage(path: string): Language | undefined;
3
- //# sourceMappingURL=languages.d.ts.map
@@ -17,4 +17,3 @@ export function detectLanguage(path) {
17
17
  const dot = name.lastIndexOf(".");
18
18
  return dot > 0 ? EXTENSIONS[name.slice(dot + 1).toLowerCase()] : undefined;
19
19
  }
20
- //# sourceMappingURL=languages.js.map
@@ -8,12 +8,5 @@ export type RuleSource = "repository" | "shared" | "account" | "plugin";
8
8
  export type SourcedRule = RepoRule & {
9
9
  source?: RuleSource;
10
10
  };
11
- export declare const repoRulesFileSchema: z.ZodObject<{
12
- rules: z.ZodArray<z.ZodObject<{
13
- path: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
14
- rule: z.ZodString;
15
- }, z.core.$strip>>;
16
- }, z.core.$strip>;
17
11
  export declare const REPO_RULES_PATH = ".ocra/rules.json";
18
12
  export declare function parseRepoRules(json: string): RepoRule[];
19
- //# sourceMappingURL=repo-rules.d.ts.map
@@ -1,10 +1,10 @@
1
1
  import { z } from "zod";
2
- import { OcraError } from "../errors.js";
2
+ import { errorMessage, OcraError } from "../errors.js";
3
3
  export const repoRuleSchema = z.object({
4
4
  path: z.union([z.string().min(1), z.array(z.string().min(1)).min(1)]),
5
5
  rule: z.string().min(1),
6
6
  });
7
- export const repoRulesFileSchema = z.object({ rules: z.array(repoRuleSchema) });
7
+ const repoRulesFileSchema = z.object({ rules: z.array(repoRuleSchema) });
8
8
  export const REPO_RULES_PATH = ".ocra/rules.json";
9
9
  export function parseRepoRules(json) {
10
10
  let data;
@@ -12,7 +12,7 @@ export function parseRepoRules(json) {
12
12
  data = JSON.parse(json);
13
13
  }
14
14
  catch (error) {
15
- throw new OcraError("CONFIG_INVALID", `${REPO_RULES_PATH} is not valid JSON: ${error.message}`, { cause: error });
15
+ throw new OcraError("CONFIG_INVALID", `${REPO_RULES_PATH} is not valid JSON: ${errorMessage(error)}`, { cause: error });
16
16
  }
17
17
  const parsed = repoRulesFileSchema.safeParse(data);
18
18
  if (!parsed.success) {
@@ -20,4 +20,3 @@ export function parseRepoRules(json) {
20
20
  }
21
21
  return parsed.data.rules;
22
22
  }
23
- //# sourceMappingURL=repo-rules.js.map
@@ -1,4 +1,3 @@
1
1
  import type { RepoRule } from "./repo-rules.js";
2
2
  import type { RuleSet } from "./rule-set.js";
3
3
  export declare function resolveRules(paths: readonly string[], repoRules: readonly RepoRule[], builtin?: RuleSet): string;
4
- //# sourceMappingURL=resolve.d.ts.map
@@ -24,4 +24,3 @@ export function resolveRules(paths, repoRules, builtin = {}) {
24
24
  }
25
25
  return sections.join("\n\n");
26
26
  }
27
- //# sourceMappingURL=resolve.js.map
@@ -3,4 +3,3 @@ export interface RuleSet {
3
3
  general?: string;
4
4
  languages?: Partial<Record<Language, string>>;
5
5
  }
6
- //# sourceMappingURL=rule-set.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=rule-set.js.map
@@ -1,4 +1,4 @@
1
- import type { Usage } from "../contracts.js";
1
+ import type { AttemptRecord, IncompleteEnding, Usage } from "../contracts.js";
2
2
  import type { QuotaError } from "./quota.js";
3
3
  export declare const MAX_AGENT_STEPS = 30;
4
4
  export declare const RESUME_MESSAGE: string;
@@ -9,6 +9,9 @@ export interface AttemptOutcome {
9
9
  toolCalls: string[];
10
10
  text: string;
11
11
  resumed?: true;
12
+ atStepCap?: true;
13
+ read?: string[];
14
+ searched?: string[];
12
15
  usage: Usage;
13
16
  error?: AttemptError;
14
17
  }
@@ -19,4 +22,14 @@ export interface AttemptError {
19
22
  }
20
23
  export declare function attemptSummary(model: string, outcome: AttemptOutcome): string;
21
24
  export declare function toolSummary(toolCalls: readonly string[]): string;
22
- //# sourceMappingURL=attempt.d.ts.map
25
+ export type AttemptEnding = "done" | IncompleteEnding | "error";
26
+ export declare function attemptEnding(outcome: AttemptOutcome): AttemptEnding;
27
+ export interface ToolUse {
28
+ name: string;
29
+ input: unknown;
30
+ }
31
+ export declare function exploredBy(uses: readonly ToolUse[]): {
32
+ read: string[];
33
+ searched: string[];
34
+ };
35
+ export declare function attemptRecord(model: string, outcome: AttemptOutcome): AttemptRecord;
@@ -1,3 +1,4 @@
1
+ import { z } from "zod";
1
2
  import { REVIEW_TOOLS } from "../review/tools.js";
2
3
  // Each step resends the whole conversation, so an unbounded loop is the
3
4
  // largest cost risk. At 20 steps a quarter of the review tasks on Vertex
@@ -34,4 +35,49 @@ export function toolSummary(toolCalls) {
34
35
  const finished = names.includes(REVIEW_TOOLS.taskDone) ? "" : "; no task_done";
35
36
  return `${toolCalls.length} tool call(s) (${byUse.map(([n, c]) => `${n} ${c}`).join(", ")}${finished})`;
36
37
  }
37
- //# sourceMappingURL=attempt.js.map
38
+ export function attemptEnding(outcome) {
39
+ if (outcome.error)
40
+ return "error";
41
+ if (outcome.toolCalls.includes(REVIEW_TOOLS.taskDone))
42
+ return "done";
43
+ return outcome.atStepCap ? "step_cap" : "stopped_early";
44
+ }
45
+ // A model chooses these strings, so the session log keeps a bounded number
46
+ // of bounded ones.
47
+ const MAX_EXPLORED = 200;
48
+ const MAX_EXPLORED_CHARS = 500;
49
+ const MAX_TEXT_CHARS = 4_000;
50
+ // The files an attempt read and what it searched for, from its tool calls.
51
+ export function exploredBy(uses) {
52
+ return {
53
+ read: distinct(uses, REVIEW_TOOLS.readFile, (input) => readInput.safeParse(input).data?.path),
54
+ searched: distinct(uses, REVIEW_TOOLS.codeSearch, (input) => searchInput.safeParse(input).data?.literal),
55
+ };
56
+ }
57
+ const readInput = z.object({ path: z.string() });
58
+ const searchInput = z.object({ literal: z.string() });
59
+ function distinct(uses, tool, pick) {
60
+ const values = new Set();
61
+ for (const use of uses) {
62
+ const value = use.name === tool ? pick(use.input) : undefined;
63
+ if (value !== undefined)
64
+ values.add(cut(value, MAX_EXPLORED_CHARS));
65
+ if (values.size >= MAX_EXPLORED)
66
+ break;
67
+ }
68
+ return [...values];
69
+ }
70
+ export function attemptRecord(model, outcome) {
71
+ return {
72
+ model,
73
+ read: outcome.read ?? [],
74
+ searched: outcome.searched ?? [],
75
+ // The end of an answer is where a reviewer concludes.
76
+ text: outcome.text.length > MAX_TEXT_CHARS
77
+ ? `…${outcome.text.slice(-MAX_TEXT_CHARS)}`
78
+ : outcome.text,
79
+ };
80
+ }
81
+ function cut(text, max) {
82
+ return text.length > max ? `${text.slice(0, max)}…` : text;
83
+ }
@@ -0,0 +1,18 @@
1
+ import type { AgentEvent, AgentTaskSpec, CompletionRequest, CompletionResult, ModelChains, Usage } from "../contracts.js";
2
+ import { OcraError } from "../errors.js";
3
+ import type { AttemptOutcome } from "./attempt.js";
4
+ export interface ModelAttempts {
5
+ refuse?(chain: readonly string[], own: boolean): OcraError | undefined;
6
+ ready?(): Promise<void>;
7
+ task(model: string, spec: AgentTaskSpec, signal: AbortSignal, onUsage: (spent: Usage) => void): Promise<AttemptOutcome>;
8
+ complete(model: string, request: CompletionRequest, signal: AbortSignal): Promise<AttemptOutcome>;
9
+ }
10
+ export declare class ChainRunner {
11
+ private readonly health;
12
+ private readonly models;
13
+ private readonly attempts;
14
+ constructor(models: ModelChains, attempts: ModelAttempts);
15
+ runTask(spec: AgentTaskSpec, signal: AbortSignal): AsyncIterable<AgentEvent>;
16
+ complete(request: CompletionRequest, signal: AbortSignal): Promise<CompletionResult>;
17
+ private refusal;
18
+ }
@@ -0,0 +1,62 @@
1
+ import { OcraError } from "../errors.js";
2
+ import { completeWithFailback, withFailback } from "./failback.js";
3
+ import { callChain, ModelHealth } from "./models.js";
4
+ // The model chain of every call a runtime serves: which chain a call runs on,
5
+ // each model's health across the run (quota waits, a circuit breaker), and
6
+ // failing over to the next model. A runtime implements single-model
7
+ // attempts and hands its runTask and complete to one runner per instance,
8
+ // so the health it keeps spans the run.
9
+ export class ChainRunner {
10
+ health = new ModelHealth();
11
+ models;
12
+ attempts;
13
+ constructor(models, attempts) {
14
+ this.models = models;
15
+ this.attempts = attempts;
16
+ }
17
+ async *runTask(spec, signal) {
18
+ const own = Boolean(spec.models?.length);
19
+ const chain = callChain(this.models, spec.modelTier, spec.models);
20
+ const refused = this.refusal(spec.modelTier, chain, own);
21
+ if (refused) {
22
+ yield { type: "error", taskId: spec.taskId, error: refused.message, retryable: false };
23
+ return;
24
+ }
25
+ await this.attempts.ready?.();
26
+ yield* withFailback({
27
+ taskId: spec.taskId,
28
+ tier: spec.modelTier,
29
+ ...(own ? { agent: spec.reviewer } : {}),
30
+ chain,
31
+ health: this.health,
32
+ signal,
33
+ attempt: (model, onUsage) => this.attempts.task(model, spec, signal, onUsage),
34
+ });
35
+ }
36
+ // Throws a CompletionError carrying the usage of failed attempts, or the
37
+ // OcraError of a call refused before any request.
38
+ async complete(request, signal) {
39
+ const own = Boolean(request.models?.length);
40
+ const chain = callChain(this.models, request.tier, request.models);
41
+ const refused = this.refusal(request.tier, chain, own);
42
+ if (refused)
43
+ throw refused;
44
+ await this.attempts.ready?.();
45
+ return completeWithFailback({
46
+ tier: request.tier,
47
+ ...(own ? { agent: request.agent ?? request.tier } : {}),
48
+ chain,
49
+ health: this.health,
50
+ signal,
51
+ attempt: (model) => this.attempts.complete(model, request, signal),
52
+ });
53
+ }
54
+ refusal(tier, chain, own) {
55
+ if (chain.length === 0)
56
+ return noModel(tier);
57
+ return this.attempts.refuse?.(chain, own);
58
+ }
59
+ }
60
+ function noModel(tier) {
61
+ return new OcraError("CONFIG_INVALID", `No model configured for the "${tier}" tier; set models.${tier} in .ocra/config.json or OCRA_MODEL_${tier.toUpperCase()}`);
62
+ }
@@ -0,0 +1,13 @@
1
+ import type { Effort } from "../contracts.js";
2
+ export type EffortParameter = "reasoningEffort" | "thinkingBudget" | "thinkingLevel";
3
+ export interface EffortCapability {
4
+ parameter: EffortParameter;
5
+ levels: readonly Effort[];
6
+ budget?: {
7
+ min: number;
8
+ max?: number;
9
+ };
10
+ }
11
+ export declare function effortCapability(model: string): EffortCapability | undefined;
12
+ export declare const FALLBACK_OUTPUT_LIMIT = 32000;
13
+ export declare function thinkingBudget(capability: EffortCapability, level: Effort, outputLimit?: number): number | undefined;
@@ -0,0 +1,69 @@
1
+ // What ocra knows of current models, matched on the model id's last path
2
+ // segment, so "anthropic/claude-sonnet-4-5" and an OpenRouter
3
+ // "openrouter/anthropic/claude-sonnet-4.5" both match. It goes stale as
4
+ // models ship: a model it does not know, or a level it says a model does
5
+ // not take, is left out of the call with a warning, never refused. The first
6
+ // matching row wins, so a family's later versions come first.
7
+ const CAPABILITIES = [
8
+ {
9
+ pattern: /^gpt-5\.\d/,
10
+ parameter: "reasoningEffort",
11
+ levels: ["none", "low", "medium", "high"],
12
+ },
13
+ {
14
+ pattern: /^gpt-5(?:$|-)/,
15
+ parameter: "reasoningEffort",
16
+ levels: ["minimal", "low", "medium", "high"],
17
+ },
18
+ { pattern: /^o[134](?:$|-)/, parameter: "reasoningEffort", levels: ["low", "medium", "high"] },
19
+ {
20
+ pattern: /^claude-(?:(?:opus|sonnet|haiku)-)?[4-9]/,
21
+ parameter: "thinkingBudget",
22
+ levels: ["none", "minimal", "low", "medium", "high"],
23
+ budget: { min: 1_024 },
24
+ },
25
+ {
26
+ pattern: /^gemini-2\.5-pro/,
27
+ parameter: "thinkingBudget",
28
+ levels: ["minimal", "low", "medium", "high"],
29
+ budget: { min: 128, max: 32_768 },
30
+ },
31
+ {
32
+ pattern: /^gemini-2\.5-flash/,
33
+ parameter: "thinkingBudget",
34
+ levels: ["none", "minimal", "low", "medium", "high"],
35
+ budget: { min: 512, max: 24_576 },
36
+ },
37
+ { pattern: /^gemini-3/, parameter: "thinkingLevel", levels: ["low", "high"] },
38
+ ];
39
+ export function effortCapability(model) {
40
+ const id = (model.split("/").at(-1) ?? model).toLowerCase();
41
+ const row = CAPABILITIES.find((r) => r.pattern.test(id));
42
+ if (!row)
43
+ return undefined;
44
+ const { pattern: _, ...capability } = row;
45
+ return capability;
46
+ }
47
+ // Share of the model's output limit each level may spend on thinking.
48
+ const BUDGET_SHARE = {
49
+ minimal: 1 / 32,
50
+ low: 1 / 16,
51
+ medium: 1 / 4,
52
+ high: 1 / 2,
53
+ };
54
+ // Claude Opus 4's output limit, the smallest among the models the table
55
+ // knows: a budget derived from it fits all of them.
56
+ export const FALLBACK_OUTPUT_LIMIT = 32_000;
57
+ // The thinking budget for a level, derived from the model's output limit
58
+ // (the fallback when the catalog gives none); 0 for "none". Undefined when
59
+ // no budget within the bounds fits below that limit.
60
+ export function thinkingBudget(capability, level, outputLimit) {
61
+ if (level === "none")
62
+ return 0;
63
+ const limit = outputLimit && outputLimit > 0 ? outputLimit : FALLBACK_OUTPUT_LIMIT;
64
+ const min = capability.budget?.min ?? 0;
65
+ const max = Math.min(capability.budget?.max ?? Number.POSITIVE_INFINITY, limit - 1);
66
+ if (min > max)
67
+ return undefined;
68
+ return Math.min(max, Math.max(min, Math.floor(limit * BUDGET_SHARE[level])));
69
+ }
@@ -11,15 +11,6 @@ export interface FailbackOptions {
11
11
  attempt(model: string, onUsage: (spent: Usage) => void): Promise<AttemptOutcome>;
12
12
  }
13
13
  export declare function withFailback(options: FailbackOptions): AsyncGenerator<AgentEvent>;
14
- export declare class LiveUsage {
15
- private seen;
16
- private given;
17
- private wake;
18
- observe(spent: Usage): void;
19
- changed(): Promise<void>;
20
- take(): Usage;
21
- rest(total: Usage): Usage;
22
- }
23
14
  export interface CompleteOptions {
24
15
  tier: ModelTier;
25
16
  agent?: string;
@@ -29,4 +20,3 @@ export interface CompleteOptions {
29
20
  attempt(model: string): Promise<AttemptOutcome>;
30
21
  }
31
22
  export declare function completeWithFailback(options: CompleteOptions): Promise<CompletionResult>;
32
- //# sourceMappingURL=failback.d.ts.map