crysk 0.7.0 → 0.8.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 (133) hide show
  1. package/README.md +27 -23
  2. package/dist/SKILL-1q3658n0.md +74 -0
  3. package/dist/SKILL-25j4q9b8.md +143 -0
  4. package/dist/SKILL-4747bhne.md +143 -0
  5. package/dist/SKILL-4jc3sv23.md +74 -0
  6. package/dist/SKILL-c0492rch.md +540 -0
  7. package/dist/SKILL-d1nzkhhr.md +74 -0
  8. package/dist/SKILL-f8p7kvx0.md +143 -0
  9. package/dist/SKILL-gxd45g38.md +553 -0
  10. package/dist/SKILL-rec41991.md +66 -0
  11. package/dist/SKILL-zze8zj5g.md +536 -0
  12. package/dist/cli.js +24658 -24654
  13. package/dist/index.js +492 -463
  14. package/dist/opencode-ci-qrcv7a99.md +106 -0
  15. package/dist/opencode-ci-rdpcc7xc.md +106 -0
  16. package/dist/opencode-ci-yt0k74t0.md +106 -0
  17. package/dist/workflow-andv2dvm.yml +158 -0
  18. package/package.json +1 -1
  19. package/prompts/default/PROVENANCE.md +1 -0
  20. package/skills/crysk/SKILL.md +6 -6
  21. package/skills/crysk-ci-setup/SKILL.md +32 -33
  22. package/skills/crysk-ci-setup/assets/workflow.yml +5 -10
  23. package/skills/crysk-ci-setup/references/ci-admission.md +5 -5
  24. package/skills/crysk-ci-setup/references/opencode-ci.md +6 -6
  25. package/skills/crysk-loop/SKILL.md +37 -54
  26. package/skills/crysk-pr/SKILL.md +1 -1
  27. package/src/asset-manifest.ts +0 -6
  28. package/src/assets.ts +1 -4
  29. package/src/brand.ts +20 -30
  30. package/src/ci/gates.ts +155 -201
  31. package/src/ci/outcome.ts +4 -31
  32. package/src/ci/platform-limits.ts +135 -0
  33. package/src/ci/platform-report.ts +212 -126
  34. package/src/ci/platform.ts +28 -26
  35. package/src/ci/reporter.ts +25 -26
  36. package/src/ci/review-admission.ts +1 -2
  37. package/src/ci/review-levels.ts +12 -53
  38. package/src/ci/setup.ts +96 -66
  39. package/src/ci/trace-bundle.ts +11 -27
  40. package/src/ci/trace-transcripts.ts +4 -6
  41. package/src/ci/trigger.ts +3 -5
  42. package/src/cli.ts +6 -5
  43. package/src/commands/ci-setup-questions.ts +2 -55
  44. package/src/commands/ci-setup.ts +2 -26
  45. package/src/commands/triage.ts +131 -38
  46. package/src/commands/usage.ts +0 -1
  47. package/src/compare/compare.ts +3 -3
  48. package/src/compare/floor-test.ts +30 -201
  49. package/src/config/config.ts +6 -30
  50. package/src/diversity/accounting.ts +0 -26
  51. package/src/diversity/benchmark.ts +1 -17
  52. package/src/diversity/identity.ts +0 -14
  53. package/src/diversity/pipeline-integration.ts +0 -29
  54. package/src/doctor.ts +3 -6
  55. package/src/execution/claude-session-trace.ts +7 -2
  56. package/src/execution/contracts.ts +15 -9
  57. package/src/execution/harness.ts +165 -187
  58. package/src/execution/spend-limiter.ts +39 -131
  59. package/src/execution/usage-facts.ts +397 -0
  60. package/src/execution/usage-normalized.ts +33 -86
  61. package/src/harness/materiality-judge.ts +0 -5
  62. package/src/harness/pipeline-plan.ts +0 -3
  63. package/src/harness/replay-rows.ts +0 -5
  64. package/src/harness/route-runner.ts +2 -2
  65. package/src/harness/single-step.ts +3 -9
  66. package/src/index.ts +1 -1
  67. package/src/mcp/preflight.ts +2 -2
  68. package/src/model/catalog.ts +1 -3
  69. package/src/model/free-discovery.ts +11 -78
  70. package/src/model/model-name.ts +14 -4
  71. package/src/model/profiles/claude.ts +1 -2
  72. package/src/model/profiles/openai.ts +1 -2
  73. package/src/model/profiles.ts +1 -2
  74. package/src/model/provider-capabilities.ts +16 -55
  75. package/src/model/routing.ts +39 -36
  76. package/src/pr/admission.ts +6 -6
  77. package/src/pr/answered-findings.ts +8 -4
  78. package/src/pr/ci-publish.ts +0 -2
  79. package/src/pr/discovery.ts +4 -25
  80. package/src/pr/plan.ts +40 -121
  81. package/src/pr/pr-status.ts +14 -2
  82. package/src/pr/preflight.ts +15 -12
  83. package/src/pr/publish-outcome.ts +1 -19
  84. package/src/pr/review-pr.ts +10 -47
  85. package/src/pr/target.ts +76 -82
  86. package/src/production-runtime.ts +52 -114
  87. package/src/progress.ts +0 -54
  88. package/src/rereview/prepare.ts +4 -1
  89. package/src/rereview/state.ts +1 -1
  90. package/src/review/boundary.ts +4 -8
  91. package/src/review/drafts.ts +3 -3
  92. package/src/review/findings-conformance.ts +1 -1
  93. package/src/review/findings.ts +0 -4
  94. package/src/review/pipeline.ts +57 -395
  95. package/src/review/preflight.ts +162 -201
  96. package/src/review/prompt-set.ts +0 -2
  97. package/src/review/report.ts +2 -162
  98. package/src/review/review.ts +16 -65
  99. package/src/review/route-preflight.ts +3 -35
  100. package/src/review/run.ts +37 -73
  101. package/src/review/size-gate.ts +3 -3
  102. package/src/review/spec.ts +6 -11
  103. package/src/review/step-runner.ts +4 -4
  104. package/src/runner-authority.ts +10 -9
  105. package/src/security/credential-broker.ts +5 -6
  106. package/src/server/preflight.ts +0 -1
  107. package/src/server/server.ts +17 -6
  108. package/src/store/activity.ts +1 -2
  109. package/src/store/backfill-preflight.ts +0 -3
  110. package/src/store/backfill.ts +0 -1
  111. package/src/store/metrics-preflight.ts +4 -14
  112. package/src/store/metrics.ts +5 -5
  113. package/src/store/preflight.ts +0 -13
  114. package/src/store/store.ts +11 -12
  115. package/src/transport-registry.ts +6 -30
  116. package/src/transports/claude-code-cli.ts +149 -215
  117. package/src/transports/opencode-client.ts +4 -24
  118. package/src/transports/opencode-sdk.ts +17 -112
  119. package/src/triage/plain-reply.ts +37 -0
  120. package/src/ui/activity.ts +1 -6
  121. package/src/ui/config-edit.ts +14 -67
  122. package/src/ui/config.ts +3 -8
  123. package/src/ui/plan.ts +11 -198
  124. package/src/ui/progress.ts +3 -49
  125. package/src/ui/result.ts +18 -77
  126. package/src/ui/review-menu.ts +3 -12
  127. package/src/ui/select.ts +9 -79
  128. package/src/updater.ts +1 -1
  129. package/src/usage.ts +1 -7
  130. package/prompts/default/deep-review-parity.md +0 -152
  131. package/prompts/scout.md +0 -140
  132. package/src/ci/platform-estimate.ts +0 -111
  133. package/src/review/scout.ts +0 -323
package/src/ci/outcome.ts CHANGED
@@ -1191,10 +1191,6 @@ const ENGINE_DEFECT_ISSUE =
1191
1191
  'gh issue create -R cryskai/crysk --title "CRYSK-ENGINE-DEFECT {detail}" --body "{runUrl}"';
1192
1192
  const RERUN_FAILED = "$ gh run rerun {runId} --failed";
1193
1193
  const REVIEW_AGAIN = '$ gh pr comment {pr} --body "/crysk review"';
1194
- // A workflow set up before the rename filters only `/pr-hero`, and the
1195
- // floating action tag still delivers this text to it.
1196
- const LEGACY_REVIEW_NOTE =
1197
- "On a workflow set up before the rename, comment `/pr-hero review` instead.";
1198
1194
  // The OpenCode secrets (S8): one per provider, <PROVIDER> being the provider id
1199
1195
  // uppercased with `-` and `.` as `_` (opencodeSecretToken in crysk-secrets.ts,
1200
1196
  // which this module cannot import: see the builtins-only guard).
@@ -1390,11 +1386,7 @@ function single(
1390
1386
 
1391
1387
  const PROVIDER_LIMITED: CatalogVariant = {
1392
1388
  why: "the provider has throttled this account or key, so an immediate retry would fail the same way",
1393
- fixes: [
1394
- "Wait, or raise the quota, then ask for a new review:",
1395
- REVIEW_AGAIN,
1396
- LEGACY_REVIEW_NOTE,
1397
- ],
1389
+ fixes: ["Wait, or raise the quota, then ask for a new review:", REVIEW_AGAIN],
1398
1390
  annotationFix: `wait for the limit to reset or raise the quota, then comment ${commandHint("/crysk review", "")} on the PR`,
1399
1391
  };
1400
1392
 
@@ -1535,7 +1527,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1535
1527
  "Or run on the subscription: set CRYSK_CLAUDE_OAUTH_TOKEN and put subscription first in `credentials.claude` (the default order).",
1536
1528
  "Then ask for a new review:",
1537
1529
  REVIEW_AGAIN,
1538
- LEGACY_REVIEW_NOTE,
1539
1530
  ],
1540
1531
  annotationFix:
1541
1532
  "create a new key and run `gh secret set {secret}`, or set CRYSK_CLAUDE_OAUTH_TOKEN and put subscription first in `credentials.claude` (the default order)",
@@ -1546,7 +1537,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1546
1537
  "$ claude setup-token && gh secret set {secret}",
1547
1538
  "Then ask for a new review:",
1548
1539
  REVIEW_AGAIN,
1549
- LEGACY_REVIEW_NOTE,
1550
1540
  ],
1551
1541
  annotationFix:
1552
1542
  "log in again with `claude setup-token` and set `{secret}` (`gh secret set {secret}`)",
@@ -1560,7 +1550,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1560
1550
  "$ gh secret set {secret}",
1561
1551
  "Then ask for a new review:",
1562
1552
  REVIEW_AGAIN,
1563
- LEGACY_REVIEW_NOTE,
1564
1553
  ],
1565
1554
  annotationFix:
1566
1555
  "create a new key with the provider and run `gh secret set {secret}`",
@@ -1575,7 +1564,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1575
1564
  "$ gh secret set CRYSK_OPENCODE_OPENAI_API_KEY",
1576
1565
  "Then ask for a new review:",
1577
1566
  REVIEW_AGAIN,
1578
- LEGACY_REVIEW_NOTE,
1579
1567
  ],
1580
1568
  annotationFix:
1581
1569
  "log in again with `opencode auth login`, choose ChatGPT and set {secret} from its record, or set CRYSK_OPENCODE_OPENAI_API_KEY and stop passing {secret} to bill per token",
@@ -1590,7 +1578,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1590
1578
  OPENCODE_API_KEY_SECRET,
1591
1579
  "Then ask for a new review:",
1592
1580
  REVIEW_AGAIN,
1593
- LEGACY_REVIEW_NOTE,
1594
1581
  ],
1595
1582
  annotationFix:
1596
1583
  "replace the credential in {secret} with a new one, then run `gh secret set {secret}`",
@@ -1866,7 +1853,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1866
1853
  "Add credit to the Anthropic account behind the API key (Claude Console → Plans & Billing), or run on the subscription: set CRYSK_CLAUDE_OAUTH_TOKEN and put subscription first in `credentials.claude` (the default order).",
1867
1854
  "Then ask for a new review:",
1868
1855
  REVIEW_AGAIN,
1869
- LEGACY_REVIEW_NOTE,
1870
1856
  ],
1871
1857
  annotationFix:
1872
1858
  "add credit to the Anthropic account behind the API key (Claude Console → Plans & Billing), or set CRYSK_CLAUDE_OAUTH_TOKEN and put subscription first in `credentials.claude` (the default order)",
@@ -1879,7 +1865,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1879
1865
  fixes: [
1880
1866
  "Re-run after the limit resets (the reset time is in the sentence above):",
1881
1867
  REVIEW_AGAIN,
1882
- LEGACY_REVIEW_NOTE,
1883
1868
  "Or bill per token: set CRYSK_CLAUDE_API_KEY and put api_key first in `credentials.claude` (the default order uses the subscription while it is set):",
1884
1869
  "$ gh secret set CRYSK_CLAUDE_API_KEY",
1885
1870
  ],
@@ -1894,7 +1879,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1894
1879
  fixes: [
1895
1880
  "Wait for the limit to reset, or add credit or raise the quota on the provider account behind the key, then ask for a new review:",
1896
1881
  REVIEW_AGAIN,
1897
- LEGACY_REVIEW_NOTE,
1898
1882
  "Or set a key from an account that has quota:",
1899
1883
  "$ gh secret set {secret}",
1900
1884
  ],
@@ -1907,7 +1891,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1907
1891
  fixes: [
1908
1892
  "Re-run after the limit resets:",
1909
1893
  REVIEW_AGAIN,
1910
- LEGACY_REVIEW_NOTE,
1911
1894
  OPENAI_API_KEY_INSTEAD,
1912
1895
  "$ gh secret set CRYSK_OPENCODE_OPENAI_API_KEY",
1913
1896
  ],
@@ -1932,12 +1915,7 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1932
1915
  what: "the request was refused",
1933
1916
  variants: single(
1934
1917
  PROVIDER_REFUSED_WHY,
1935
- [
1936
- "Ask for a new review once:",
1937
- REVIEW_AGAIN,
1938
- LEGACY_REVIEW_NOTE,
1939
- "If it repeats, report it.",
1940
- ],
1918
+ ["Ask for a new review once:", REVIEW_AGAIN, "If it repeats, report it."],
1941
1919
  "ask for a new review once, and report it if the provider refuses again",
1942
1920
  ),
1943
1921
  },
@@ -1976,7 +1954,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1976
1954
  fixes: [
1977
1955
  "Lower `max-changed-lines` in the workflow's `with:` block (or `max_changed_lines` in the repo config), or exclude paths in `.cryskignore` (`.prheroignore` in a repo set up before the rename), then ask for a new review:",
1978
1956
  REVIEW_AGAIN,
1979
- LEGACY_REVIEW_NOTE,
1980
1957
  ],
1981
1958
  annotationFix:
1982
1959
  "lower `max-changed-lines` (or `max_changed_lines` in the repo config) or exclude paths in `.cryskignore` (`.prheroignore` before the rename)",
@@ -2009,12 +1986,8 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
2009
1986
  what: "The review was cancelled or superseded by a newer push",
2010
1987
  variants: single(
2011
1988
  "a newer run replaces this one, so this result would describe an outdated head",
2012
- [
2013
- "Ask for a review of the current head:",
2014
- REVIEW_AGAIN,
2015
- LEGACY_REVIEW_NOTE,
2016
- ],
2017
- 'ask for a review of the current head with `gh pr comment {pr} --body "/crysk review"` (or "/pr-hero review" on a workflow set up before the rename)',
1989
+ ["Ask for a review of the current head:", REVIEW_AGAIN],
1990
+ 'ask for a review of the current head with `gh pr comment {pr} --body "/crysk review"`',
2018
1991
  ),
2019
1992
  },
2020
1993
  };
@@ -0,0 +1,135 @@
1
+ // The limits the Crysk platform sends with a run (platform-owned-cost L55). The
2
+ // connect step declares the `limits` capability in `X-Crysk-Capabilities`; only
3
+ // then does the `/runs/token` response carry `limits`, and the step hands it to
4
+ // the run step as `CRYSK_PLATFORM_LIMITS`, where the CI limits gate reads it
5
+ // (gates.ts, `evaluatePlatformLimits`).
6
+ //
7
+ // The platform owns the settings, the defaults and the month's spend; the
8
+ // engine only compares, because only it knows whether the run bills an API key.
9
+ // The field is absent when the dispatch was forced (`/crysk review`, `recheck`),
10
+ // and a forced run is therefore never skipped for cost.
11
+ //
12
+ // The platform already checked the numbers and the engine checks again: a field
13
+ // that is not a usable number is dropped, and with nothing left the run is
14
+ // treated as having no limits. Limits are advice for a skip, never a reason to
15
+ // fail the exchange.
16
+ //
17
+ // This module imports nothing, so the connect step (which runs before
18
+ // `bun install`) can load it.
19
+
20
+ export interface PlatformLimits {
21
+ // The per-review limit in effect: repository override, else organization
22
+ // setting, else the platform's default. Always above 0 when present.
23
+ readonly reviewUsd?: number;
24
+ // What the organization's month limit leaves after this calendar month's API
25
+ // spend (UTC), floored at 0. Absent when no month limit is set.
26
+ readonly monthLeftUsd?: number;
27
+ // The platform's estimate for this review, its high side. Absent when the
28
+ // platform cannot price the run.
29
+ readonly estimateUsd?: number;
30
+ // `estimateUsd` split per model role (`hunter.logic`, `refuter`, ...): the
31
+ // platform's setup estimate priced line by line. Present only when the
32
+ // platform priced every line. It lets the engine compare the share of the
33
+ // estimate that runs on an API key instead of the whole of it (S17).
34
+ readonly estimateByRoleUsd?: Readonly<Record<string, number>>;
35
+ }
36
+
37
+ // Which limit a skip names (gates.ts, `evaluatePlatformLimits`): the month's
38
+ // limit is used up, the estimate is over the per-review limit, or the estimate
39
+ // is over what is left of the month.
40
+ export type PlatformLimitHit = "month-used-up" | "review-limit" | "month-left";
41
+
42
+ export const PLATFORM_LIMITS_CAPABILITY = "limits";
43
+
44
+ const finite = (value: unknown): value is number =>
45
+ typeof value === "number" && Number.isFinite(value);
46
+
47
+ // Role keys are the engine's `models` keys (`hunter.<specialty>` at most 64
48
+ // characters after the prefix); the cap keeps a hostile body small.
49
+ const MAX_ROLE_KEY_LENGTH = 72;
50
+ const MAX_ROLES = 32;
51
+
52
+ // The split as sent, or undefined. One bad entry drops the whole field, never
53
+ // the entry: a dropped role would read as free, and the engine's fallback for
54
+ // no split (the whole estimate) is the conservative one.
55
+ function parseEstimateByRole(
56
+ value: unknown,
57
+ ): Readonly<Record<string, number>> | undefined {
58
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
59
+ return undefined;
60
+ }
61
+ const entries = Object.entries(value);
62
+ if (entries.length === 0 || entries.length > MAX_ROLES) return undefined;
63
+ for (const [role, usd] of entries) {
64
+ if (role.length === 0 || role.length > MAX_ROLE_KEY_LENGTH) {
65
+ return undefined;
66
+ }
67
+ if (!finite(usd) || usd < 0) return undefined;
68
+ }
69
+ return Object.fromEntries(entries) as Record<string, number>;
70
+ }
71
+
72
+ // The `/runs/token` field, `{ review_usd?, month_left_usd?, estimate_usd?,
73
+ // estimate_by_role_usd? }`, or undefined when it is absent or holds no usable
74
+ // number. `review_usd` must be above 0 (the platform omits it when there is no
75
+ // limit); the other numbers may be 0.
76
+ export function parsePlatformLimits(
77
+ value: unknown,
78
+ ): PlatformLimits | undefined {
79
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
80
+ return undefined;
81
+ }
82
+ const {
83
+ review_usd: review,
84
+ month_left_usd: monthLeft,
85
+ estimate_usd: estimate,
86
+ estimate_by_role_usd: byRole,
87
+ } = value as Record<string, unknown>;
88
+ // The split only means something beside the estimate it splits.
89
+ const split =
90
+ finite(estimate) && estimate >= 0 ? parseEstimateByRole(byRole) : undefined;
91
+ const limits: {
92
+ reviewUsd?: number;
93
+ monthLeftUsd?: number;
94
+ estimateUsd?: number;
95
+ estimateByRoleUsd?: Readonly<Record<string, number>>;
96
+ } = {
97
+ ...(finite(review) && review > 0 ? { reviewUsd: review } : {}),
98
+ ...(finite(monthLeft) && monthLeft >= 0 ? { monthLeftUsd: monthLeft } : {}),
99
+ ...(finite(estimate) && estimate >= 0 ? { estimateUsd: estimate } : {}),
100
+ ...(split === undefined ? {} : { estimateByRoleUsd: split }),
101
+ };
102
+ return Object.keys(limits).length === 0 ? undefined : limits;
103
+ }
104
+
105
+ // What the connect step writes to its `limits` output: one line of JSON in the
106
+ // response's own field names, numbers only (the split is an object of numbers
107
+ // keyed by role).
108
+ export function serializePlatformLimits(limits: PlatformLimits): string {
109
+ return JSON.stringify({
110
+ ...(limits.reviewUsd === undefined ? {} : { review_usd: limits.reviewUsd }),
111
+ ...(limits.monthLeftUsd === undefined
112
+ ? {}
113
+ : { month_left_usd: limits.monthLeftUsd }),
114
+ ...(limits.estimateUsd === undefined
115
+ ? {}
116
+ : { estimate_usd: limits.estimateUsd }),
117
+ ...(limits.estimateByRoleUsd === undefined
118
+ ? {}
119
+ : { estimate_by_role_usd: limits.estimateByRoleUsd }),
120
+ });
121
+ }
122
+
123
+ // The run step's read of `CRYSK_PLATFORM_LIMITS`. Empty (a standalone run, a
124
+ // forced run, an older platform) or malformed reads as no limits.
125
+ export function readPlatformLimits(
126
+ env: Readonly<Record<string, string | undefined>>,
127
+ ): PlatformLimits | undefined {
128
+ const text = env.CRYSK_PLATFORM_LIMITS;
129
+ if (text === undefined || text === "") return undefined;
130
+ try {
131
+ return parsePlatformLimits(JSON.parse(text));
132
+ } catch {
133
+ return undefined;
134
+ }
135
+ }