clud-bug 0.7.0-rc.1 → 0.7.0-rc.12

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 (119) hide show
  1. package/README.md +20 -0
  2. package/data/canonical-v1.json +37 -0
  3. package/dist/cli/configure-github.d.ts +58 -0
  4. package/dist/cli/configure-github.d.ts.map +1 -0
  5. package/dist/cli/configure-github.js +242 -0
  6. package/dist/cli/configure-github.js.map +1 -0
  7. package/dist/cli/hooks.d.ts +35 -0
  8. package/dist/cli/hooks.d.ts.map +1 -0
  9. package/dist/cli/hooks.js +98 -0
  10. package/dist/cli/hooks.js.map +1 -0
  11. package/dist/cli/index.d.ts +1 -0
  12. package/dist/cli/index.d.ts.map +1 -1
  13. package/dist/cli/index.js +1 -0
  14. package/dist/cli/index.js.map +1 -1
  15. package/dist/cli/main.d.ts.map +1 -1
  16. package/dist/cli/main.js +791 -0
  17. package/dist/cli/main.js.map +1 -1
  18. package/dist/cli/review-prompt.d.ts +28 -0
  19. package/dist/cli/review-prompt.d.ts.map +1 -0
  20. package/dist/cli/review-prompt.js +169 -0
  21. package/dist/cli/review-prompt.js.map +1 -0
  22. package/dist/cli/update.d.ts.map +1 -1
  23. package/dist/cli/update.js +41 -0
  24. package/dist/cli/update.js.map +1 -1
  25. package/dist/core/auto-resolve.d.ts +235 -0
  26. package/dist/core/auto-resolve.d.ts.map +1 -0
  27. package/dist/core/auto-resolve.js +293 -0
  28. package/dist/core/auto-resolve.js.map +1 -0
  29. package/dist/core/budget-plan.d.ts +125 -0
  30. package/dist/core/budget-plan.d.ts.map +1 -0
  31. package/dist/core/budget-plan.js +211 -0
  32. package/dist/core/budget-plan.js.map +1 -0
  33. package/dist/core/configure-github.d.ts +179 -0
  34. package/dist/core/configure-github.d.ts.map +1 -0
  35. package/dist/core/configure-github.js +289 -0
  36. package/dist/core/configure-github.js.map +1 -0
  37. package/dist/core/diff-findings.d.ts +96 -0
  38. package/dist/core/diff-findings.d.ts.map +1 -0
  39. package/dist/core/diff-findings.js +261 -0
  40. package/dist/core/diff-findings.js.map +1 -0
  41. package/dist/core/formal-review.d.ts +79 -0
  42. package/dist/core/formal-review.d.ts.map +1 -0
  43. package/dist/core/formal-review.js +71 -0
  44. package/dist/core/formal-review.js.map +1 -0
  45. package/dist/core/index.d.ts +14 -1
  46. package/dist/core/index.d.ts.map +1 -1
  47. package/dist/core/index.js +67 -1
  48. package/dist/core/index.js.map +1 -1
  49. package/dist/core/inline-threads.d.ts +160 -0
  50. package/dist/core/inline-threads.d.ts.map +1 -0
  51. package/dist/core/inline-threads.js +369 -0
  52. package/dist/core/inline-threads.js.map +1 -0
  53. package/dist/core/multi-pass-aggregate.d.ts +131 -0
  54. package/dist/core/multi-pass-aggregate.d.ts.map +1 -0
  55. package/dist/core/multi-pass-aggregate.js +427 -0
  56. package/dist/core/multi-pass-aggregate.js.map +1 -0
  57. package/dist/core/plan-review.d.ts +57 -0
  58. package/dist/core/plan-review.d.ts.map +1 -0
  59. package/dist/core/plan-review.js +77 -0
  60. package/dist/core/plan-review.js.map +1 -0
  61. package/dist/core/prompt-builder.d.ts +164 -0
  62. package/dist/core/prompt-builder.d.ts.map +1 -0
  63. package/dist/core/prompt-builder.js +419 -0
  64. package/dist/core/prompt-builder.js.map +1 -0
  65. package/dist/core/render.d.ts.map +1 -1
  66. package/dist/core/render.js +1 -19
  67. package/dist/core/render.js.map +1 -1
  68. package/dist/core/resolve-verifier.d.ts +46 -0
  69. package/dist/core/resolve-verifier.d.ts.map +1 -0
  70. package/dist/core/resolve-verifier.js +187 -0
  71. package/dist/core/resolve-verifier.js.map +1 -0
  72. package/dist/core/review-plan.d.ts +219 -0
  73. package/dist/core/review-plan.d.ts.map +1 -0
  74. package/dist/core/review-plan.js +274 -0
  75. package/dist/core/review-plan.js.map +1 -0
  76. package/dist/core/review-schema-zod.d.ts +240 -0
  77. package/dist/core/review-schema-zod.d.ts.map +1 -0
  78. package/dist/core/review-schema-zod.js +218 -0
  79. package/dist/core/review-schema-zod.js.map +1 -0
  80. package/dist/core/review-writeback.d.ts +213 -0
  81. package/dist/core/review-writeback.d.ts.map +1 -0
  82. package/dist/core/review-writeback.js +364 -0
  83. package/dist/core/review-writeback.js.map +1 -0
  84. package/dist/core/skills.d.ts +67 -0
  85. package/dist/core/skills.d.ts.map +1 -1
  86. package/dist/core/skills.js +216 -0
  87. package/dist/core/skills.js.map +1 -1
  88. package/dist/core/version.d.ts +2 -0
  89. package/dist/core/version.d.ts.map +1 -0
  90. package/dist/core/version.js +4 -0
  91. package/dist/core/version.js.map +1 -0
  92. package/package.json +14 -5
  93. package/src/cli/configure-github.ts +329 -0
  94. package/src/cli/hooks.ts +115 -0
  95. package/src/cli/index.ts +6 -0
  96. package/src/cli/main.ts +883 -0
  97. package/src/cli/review-prompt.ts +206 -0
  98. package/src/cli/update.ts +41 -0
  99. package/src/core/auto-resolve.ts +488 -0
  100. package/src/core/budget-plan.ts +324 -0
  101. package/src/core/configure-github.ts +497 -0
  102. package/src/core/diff-findings.ts +323 -0
  103. package/src/core/formal-review.ts +168 -0
  104. package/src/core/index.ts +244 -0
  105. package/src/core/inline-threads.ts +471 -0
  106. package/src/core/multi-pass-aggregate.ts +545 -0
  107. package/src/core/plan-review.ts +136 -0
  108. package/src/core/prompt-builder.ts +561 -0
  109. package/src/core/render.ts +10 -16
  110. package/src/core/resolve-verifier.ts +228 -0
  111. package/src/core/review-plan.ts +485 -0
  112. package/src/core/review-schema-zod.ts +262 -0
  113. package/src/core/review-writeback.ts +586 -0
  114. package/src/core/skills.ts +285 -0
  115. package/src/core/version.ts +3 -0
  116. package/templates/clud-bug-review.md.tmpl +115 -0
  117. package/templates/workflow-py.yml.tmpl +79 -2
  118. package/templates/workflow-ts.yml.tmpl +79 -2
  119. package/templates/workflow.yml.tmpl +160 -2
package/README.md CHANGED
@@ -257,6 +257,26 @@ Every Clud Bug review opens with a status line that tells you exactly what chang
257
257
 
258
258
  Same format every time; zero values are always present so the line is easy to scan and parse.
259
259
 
260
+ ### Auto-resolving review threads (optional PAT)
261
+
262
+ When you push a fix, Clud Bug re-checks each open review thread and, if it verifies the fix
263
+ landed, posts a **✅ Verified fixed** reply on that thread.
264
+
265
+ **Closing the thread automatically is optional.** GitHub doesn't let the built-in Actions
266
+ `GITHUB_TOKEN` resolve review threads, so by default Clud Bug posts the "verified fixed"
267
+ reply and you click **Resolve conversation** to dismiss it — no errors, nothing fails.
268
+
269
+ To have Clud Bug close verified threads for you (matching the hosted App):
270
+
271
+ 1. Create a **fine-grained personal access token** scoped to this repo with **Pull
272
+ requests: write**.
273
+ 2. Add it as a repository secret named **`CLUD_BUG_RESOLVE_PAT`** (Settings → Secrets and
274
+ variables → Actions → New repository secret).
275
+
276
+ The next fix-push then auto-closes verified threads. Without the secret everything still
277
+ works; threads just wait for a manual Resolve. The reply is idempotent — re-pushes that
278
+ don't change the code won't re-post, so the thread never gets spammed.
279
+
260
280
  ## Manual install (advanced)
261
281
 
262
282
  If you don't want to use the CLI, you can install a generic workflow by hand:
@@ -0,0 +1,37 @@
1
+ {
2
+ "$comment": "Canonical branch protection ruleset for SkDD-conformant repos. Applied by `logmind init --configure-github`, `clud-bug init --configure-github`, and `reporulez`. Implements thrillmade/protocol SPEC §7. Schema-locked at v1; major bumps require coordinated tool releases.",
3
+ "version": "v1",
4
+ "spec_version": "0.1.2",
5
+ "branch_protection": {
6
+ "required_status_checks": {
7
+ "strict": true,
8
+ "contexts": [
9
+ "clud-bug-review",
10
+ "check-decisions",
11
+ "check-derived-docs",
12
+ "check-links",
13
+ "test"
14
+ ]
15
+ },
16
+ "required_pull_request_reviews": {
17
+ "required_approving_review_count": 1,
18
+ "dismiss_stale_reviews": false,
19
+ "require_code_owner_reviews": false
20
+ },
21
+ "required_conversation_resolution": true,
22
+ "enforce_admins": false,
23
+ "allow_force_pushes": false,
24
+ "allow_deletions": false,
25
+ "required_linear_history": false,
26
+ "allow_auto_merge": true,
27
+ "delete_branch_on_merge": true,
28
+ "squash_merge_commit_title": "PR_TITLE",
29
+ "squash_merge_commit_message": "PR_BODY"
30
+ },
31
+ "$notes": {
32
+ "required_approving_review_count": "1 — auto-satisfied by clud-bug[bot]'s APPROVE vote on clean reviews for org-member PRs (per SPEC §7.2.1). External-contributor PRs still need a human reviewer because the bot's APPROVE on first-time contributors is policy-gated. Repo-owners MAY raise above 1; tools MUST NOT lower below 1.",
33
+ "enforce_admins": "false so maintainers can land hotfixes outside the gate; the dogfood discipline expects this only for genuine emergencies (clud-bug review still runs but doesn't block)",
34
+ "contexts": "the four logmind workflow check names + clud-bug-review + a generic 'tests' context. Repos may add more, but MUST keep these. If a context name is renamed in workflow YAML, update the ruleset.",
35
+ "required_conversation_resolution": "true is the dogfood-defining rule: clud-bug findings must be resolved before merge"
36
+ }
37
+ }
@@ -0,0 +1,58 @@
1
+ import { loadCanonicalV1, type OctokitLike } from '../core/configure-github.js';
2
+ export interface RunConfigureGithubOptions {
3
+ /** "owner/repo" target — required. */
4
+ target?: string | null;
5
+ /** Target branch (default `main`). */
6
+ branch?: string;
7
+ /** Render diff only; skip PATCH calls. */
8
+ dryRun?: boolean;
9
+ /** Suppress progress chatter; emit only the final `ok` summary. */
10
+ quiet?: boolean;
11
+ /** Emit the SPEC §3.23.1 status payload as JSON instead of key-colon-value. */
12
+ json?: boolean;
13
+ /** Resolver for the GitHub token (tests pass a stub). */
14
+ resolveToken?: () => Promise<string | null>;
15
+ /** Octokit factory (tests inject a fake; defaults to the gh-adapter). */
16
+ octokitFactory?: (token: string) => OctokitLike;
17
+ /** Stdout writer (tests capture). */
18
+ stdout?: (msg: string) => void;
19
+ /** Stderr writer (tests capture). */
20
+ stderr?: (msg: string) => void;
21
+ }
22
+ /** Resolved outcome of a configure-github run, for the §3.23.1 status payload. */
23
+ export interface ConfigureSummary {
24
+ owner: string;
25
+ repo: string;
26
+ /** True when the repo already matches canonical-v1 (idempotent no-op). */
27
+ alreadyCanonical: boolean;
28
+ /** True when this was a --dry-run (no PATCH calls made). */
29
+ dryRun: boolean;
30
+ /** Number of changes (applied, or pending for dry-run; 0 for a no-op). */
31
+ changes: number;
32
+ }
33
+ /**
34
+ * SPEC §3.23.1 (NORMATIVE): emit a single-line status payload carrying
35
+ * `alreadyCanonical` + `rulesetVersion` as named fields — JSON for machine
36
+ * consumption, key-colon-value for humans.
37
+ */
38
+ export declare function formatConfigureSummary(summary: ConfigureSummary, json: boolean): string;
39
+ /**
40
+ * Entry point — wired into `clud-bug.js` dispatch. Returns a Node-style
41
+ * exit code so the dispatcher can `process.exit()` deterministically. We
42
+ * don't call `process.exit` ourselves so tests can drive the function
43
+ * without taking down the harness.
44
+ */
45
+ export declare function runConfigureGithub(options: RunConfigureGithubOptions): Promise<number>;
46
+ /**
47
+ * Builds an `OctokitLike` instance backed by `gh api` shell-outs. This
48
+ * lets us satisfy the structural interface without pulling in
49
+ * `@octokit/rest` as a runtime dep (~200KB). The App passes its real
50
+ * Octokit instance instead.
51
+ */
52
+ export declare function ghCliOctokit(token: string): OctokitLike;
53
+ /**
54
+ * Re-exported so callers can preload the ruleset (e.g. for a `--show-ruleset`
55
+ * flag in future). Currently exists for parity with the App's pattern.
56
+ */
57
+ export { loadCanonicalV1 };
58
+ //# sourceMappingURL=configure-github.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configure-github.d.ts","sourceRoot":"","sources":["../../src/cli/configure-github.ts"],"names":[],"mappings":"AAwBA,OAAO,EAEL,eAAe,EACf,KAAK,WAAW,EAEjB,MAAM,6BAA6B,CAAC;AAErC,MAAM,WAAW,yBAAyB;IACxC,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,mEAAmE;IACnE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,+EAA+E;IAC/E,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC5C,yEAAyE;IACzE,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,WAAW,CAAC;IAChD,qCAAqC;IACrC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,qCAAqC;IACrC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAChC;AAwBD,kFAAkF;AAClF,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,gBAAgB,EAAE,OAAO,CAAC;IAC1B,4DAA4D;IAC5D,MAAM,EAAE,OAAO,CAAC;IAChB,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,CAevF;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,MAAM,CAAC,CAwFjB;AAkBD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAyFvD;AAOD;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,242 @@
1
+ // `clud-bug configure-github` CLI command — applies the SPEC §7 canonical
2
+ // branch protection ruleset to a target repo.
3
+ //
4
+ // External users installing the App expect "best practice branch protection"
5
+ // applied automatically. This command lets them opt in offline + dry-run
6
+ // safely BEFORE the App's auto-setup runs server-side. Same core logic
7
+ // powers both paths (the App imports `applyCanonicalRuleset` from
8
+ // clud-bug/core; this CLI passes a `gh api`-wrapping adapter so users
9
+ // don't need `@octokit/rest` on their machine).
10
+ //
11
+ // Usage:
12
+ //
13
+ // clud-bug configure-github <owner>/<repo>
14
+ // clud-bug configure-github <owner>/<repo> --dry-run
15
+ // clud-bug configure-github <owner>/<repo> --branch develop
16
+ //
17
+ // Auth ladder:
18
+ //
19
+ // 1. `GITHUB_TOKEN` env var (CI-friendly, no `gh` install required)
20
+ // 2. `gh auth token` (developer workstation default)
21
+ //
22
+ // If neither produces a token, exits 1 with a recovery message.
23
+ import { spawn, spawnSync } from 'node:child_process';
24
+ import { applyCanonicalRuleset, loadCanonicalV1, } from '../core/configure-github.js';
25
+ const HELP = `clud-bug configure-github — apply SPEC §7 canonical branch protection.
26
+
27
+ Usage:
28
+ clud-bug configure-github <owner>/<repo> [options]
29
+
30
+ Options:
31
+ --dry-run Compute diff and print it, but do NOT call PATCH endpoints.
32
+ --branch <name> Target branch (default: main).
33
+ --quiet,-q Suppress progress chatter; emit only the final summary.
34
+ --json Emit the status payload as JSON (machine consumption).
35
+ --help,-h Show this help.
36
+
37
+ Auth (resolved in order):
38
+ 1. GITHUB_TOKEN env var (CI-friendly)
39
+ 2. \`gh auth token\` (developer workstation)
40
+
41
+ Exit codes:
42
+ 0 success or already-canonical
43
+ 1 auth missing, PATCH error, or unrecoverable transport failure
44
+ 2 CLI usage error (missing target, bad flag)
45
+ `;
46
+ /**
47
+ * SPEC §3.23.1 (NORMATIVE): emit a single-line status payload carrying
48
+ * `alreadyCanonical` + `rulesetVersion` as named fields — JSON for machine
49
+ * consumption, key-colon-value for humans.
50
+ */
51
+ export function formatConfigureSummary(summary, json) {
52
+ const { owner, repo, alreadyCanonical, dryRun, changes } = summary;
53
+ if (json) {
54
+ return (JSON.stringify({ owner, repo, alreadyCanonical, rulesetVersion: 'v1', dryRun, changes }) + '\n');
55
+ }
56
+ if (alreadyCanonical) {
57
+ return `ok configure-github: owner: ${owner} repo: ${repo} alreadyCanonical: true rulesetVersion: v1\n`;
58
+ }
59
+ const plural = changes === 1 ? '' : 's';
60
+ if (dryRun) {
61
+ return `ok configure-github: dry-run on ${owner}/${repo} — ${changes} change${plural} pending\n`;
62
+ }
63
+ return `ok configure-github: ${owner}/${repo} converged to canonical-v1 (${changes} change${plural})\n`;
64
+ }
65
+ /**
66
+ * Entry point — wired into `clud-bug.js` dispatch. Returns a Node-style
67
+ * exit code so the dispatcher can `process.exit()` deterministically. We
68
+ * don't call `process.exit` ourselves so tests can drive the function
69
+ * without taking down the harness.
70
+ */
71
+ export async function runConfigureGithub(options) {
72
+ const { target, branch = 'main', dryRun = false, quiet = false, json = false, resolveToken = defaultResolveToken, octokitFactory = ghCliOctokit, stdout = (msg) => process.stdout.write(msg), stderr = (msg) => process.stderr.write(msg), } = options;
73
+ if (!target) {
74
+ stderr(HELP);
75
+ return 2;
76
+ }
77
+ const match = /^([^/]+)\/([^/]+)$/.exec(target);
78
+ if (!match) {
79
+ stderr(`clud-bug configure-github: target must be in owner/repo form, got "${target}".\n`);
80
+ return 2;
81
+ }
82
+ const [, owner, repo] = match;
83
+ const token = await resolveToken();
84
+ if (!token) {
85
+ stderr('clud-bug configure-github: no GitHub token found.\n' +
86
+ ' Set GITHUB_TOKEN, or install + auth gh: brew install gh && gh auth login\n');
87
+ return 1;
88
+ }
89
+ if (!quiet) {
90
+ stdout(`\u{1F41B} configure-github: applying canonical-v1 ruleset to ${owner}/${repo} (branch=${branch})\n`);
91
+ }
92
+ // Single-call orchestration: the CLI previously called
93
+ // applyCanonicalRuleset twice in apply mode (dry-run first to display the
94
+ // planned changes, then a real call to apply). That two-read pattern
95
+ // opened a TOCTOU window — concurrent changes between the two reads
96
+ // could make the displayed list diverge from the actually-applied list,
97
+ // and the dry-run cost a redundant API round-trip every time. Drop the
98
+ // preview-first read: pass `dryRun` straight through. The function's
99
+ // idempotency contract (returns `alreadyCanonical: true` + empty changes
100
+ // on a no-op) means we don't need a separate "look before you leap"
101
+ // call. Users who want preview semantics run `--dry-run` first as a
102
+ // distinct invocation — idiomatic CLI behavior. Surfaced by PR #166
103
+ // reviewer (CTO follow-up 2026-06-17).
104
+ const octokit = octokitFactory(token);
105
+ let result;
106
+ try {
107
+ result = await applyCanonicalRuleset(octokit, {
108
+ owner,
109
+ repo,
110
+ branch,
111
+ dryRun,
112
+ });
113
+ }
114
+ catch (err) {
115
+ stderr(`clud-bug configure-github: ${dryRun ? 'failed to read current state' : 'PATCH failed'}: ${stringifyError(err)}\n`);
116
+ return 1;
117
+ }
118
+ if (result.alreadyCanonical) {
119
+ if (!quiet)
120
+ stdout(' No changes — repo already matches canonical-v1.\n');
121
+ stdout(formatConfigureSummary({ owner, repo, alreadyCanonical: true, dryRun, changes: 0 }, json));
122
+ return 0;
123
+ }
124
+ if (!quiet) {
125
+ const verb = dryRun ? 'Planned' : 'Applied';
126
+ stdout(` ${verb} changes (${result.changes.length}):\n`);
127
+ for (const c of result.changes)
128
+ stdout(` - ${c}\n`);
129
+ }
130
+ if (dryRun) {
131
+ stdout(formatConfigureSummary({ owner, repo, alreadyCanonical: false, dryRun: true, changes: result.changes.length }, json));
132
+ return 0;
133
+ }
134
+ stdout(formatConfigureSummary({ owner, repo, alreadyCanonical: false, dryRun: false, changes: result.changes.length }, json));
135
+ return 0;
136
+ }
137
+ /**
138
+ * Auth ladder: env var first, then `gh auth token`. Surfaces a token
139
+ * string on success or `null` if neither source has one (caller prints
140
+ * the recovery hint).
141
+ */
142
+ async function defaultResolveToken() {
143
+ const fromEnv = process.env.GITHUB_TOKEN?.trim();
144
+ if (fromEnv)
145
+ return fromEnv;
146
+ const result = spawnSync('gh', ['auth', 'token'], { encoding: 'utf8' });
147
+ if (result.status === 0) {
148
+ const tok = result.stdout.trim();
149
+ if (tok)
150
+ return tok;
151
+ }
152
+ return null;
153
+ }
154
+ /**
155
+ * Builds an `OctokitLike` instance backed by `gh api` shell-outs. This
156
+ * lets us satisfy the structural interface without pulling in
157
+ * `@octokit/rest` as a runtime dep (~200KB). The App passes its real
158
+ * Octokit instance instead.
159
+ */
160
+ export function ghCliOctokit(token) {
161
+ // We pass GITHUB_TOKEN through the spawn env so gh's API surface picks
162
+ // it up consistently whether the user supplied env or gh auth.
163
+ const env = { ...process.env, GITHUB_TOKEN: token };
164
+ function ghApi(method, path, body) {
165
+ return new Promise((resolve, reject) => {
166
+ const args = ['api', '-X', method];
167
+ if (body !== undefined) {
168
+ args.push('--input', '-');
169
+ }
170
+ args.push(path);
171
+ // Add an Accept header so 404s return the structured error, not a
172
+ // friendlier shell hint. The wrapping err.message detection in
173
+ // `isBranchNotProtected` keys on the structured form.
174
+ args.push('-H', 'Accept: application/vnd.github+json');
175
+ const child = spawn('gh', args, {
176
+ env,
177
+ stdio: ['pipe', 'pipe', 'pipe'],
178
+ });
179
+ let stdout = '';
180
+ let stderr = '';
181
+ child.stdout.on('data', (d) => {
182
+ stdout += d.toString();
183
+ });
184
+ child.stderr.on('data', (d) => {
185
+ stderr += d.toString();
186
+ });
187
+ child.on('error', reject);
188
+ child.on('close', (code) => {
189
+ if (code !== 0) {
190
+ const httpMatch = /HTTP (\d{3})/.exec(stderr);
191
+ const status = httpMatch ? Number(httpMatch[1]) : undefined;
192
+ const err = new Error((stderr.trim() || stdout.trim() || `gh api exited ${code}`).slice(0, 500));
193
+ if (status !== undefined)
194
+ err.status = status;
195
+ reject(err);
196
+ return;
197
+ }
198
+ try {
199
+ resolve(stdout ? JSON.parse(stdout) : {});
200
+ }
201
+ catch (parseErr) {
202
+ reject(parseErr);
203
+ }
204
+ });
205
+ if (body !== undefined) {
206
+ child.stdin.end(JSON.stringify(body));
207
+ }
208
+ else {
209
+ child.stdin.end();
210
+ }
211
+ });
212
+ }
213
+ return {
214
+ repos: {
215
+ async getBranchProtection({ owner, repo, branch }) {
216
+ const data = await ghApi('GET', `/repos/${owner}/${repo}/branches/${branch}/protection`);
217
+ return { data: data };
218
+ },
219
+ async updateBranchProtection({ owner, repo, branch, ...rest }) {
220
+ return ghApi('PUT', `/repos/${owner}/${repo}/branches/${branch}/protection`, rest);
221
+ },
222
+ async get({ owner, repo }) {
223
+ const data = await ghApi('GET', `/repos/${owner}/${repo}`);
224
+ return { data: data };
225
+ },
226
+ async update({ owner, repo, ...rest }) {
227
+ return ghApi('PATCH', `/repos/${owner}/${repo}`, rest);
228
+ },
229
+ },
230
+ };
231
+ }
232
+ function stringifyError(err) {
233
+ if (err instanceof Error)
234
+ return err.message;
235
+ return String(err);
236
+ }
237
+ /**
238
+ * Re-exported so callers can preload the ruleset (e.g. for a `--show-ruleset`
239
+ * flag in future). Currently exists for parity with the App's pattern.
240
+ */
241
+ export { loadCanonicalV1 };
242
+ //# sourceMappingURL=configure-github.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configure-github.js","sourceRoot":"","sources":["../../src/cli/configure-github.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8CAA8C;AAC9C,EAAE;AACF,6EAA6E;AAC7E,yEAAyE;AACzE,uEAAuE;AACvE,kEAAkE;AAClE,sEAAsE;AACtE,gDAAgD;AAChD,EAAE;AACF,SAAS;AACT,EAAE;AACF,6CAA6C;AAC7C,uDAAuD;AACvD,8DAA8D;AAC9D,EAAE;AACF,eAAe;AACf,EAAE;AACF,sEAAsE;AACtE,uDAAuD;AACvD,EAAE;AACF,gEAAgE;AAEhE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,eAAe,GAGhB,MAAM,6BAA6B,CAAC;AAuBrC,MAAM,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;CAoBZ,CAAC;AAcF;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAyB,EAAE,IAAa;IAC7E,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACnE,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,CACL,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,cAAc,EAAE,IAAI,EAA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,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE;gBAC/C,MAAM,IAAI,GAAG,MAAM,KAAK,CACtB,KAAK,EACL,UAAU,KAAK,IAAI,IAAI,aAAa,MAAM,aAAa,CACxD,CAAC;gBACF,OAAO,EAAE,IAAI,EAAE,IAAgF,EAAE,CAAC;YACpG,CAAC;YACD,KAAK,CAAC,sBAAsB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE;gBAC3D,OAAO,KAAK,CACV,KAAK,EACL,UAAU,KAAK,IAAI,IAAI,aAAa,MAAM,aAAa,EACvD,IAAI,CACL,CAAC;YACJ,CAAC;YACD,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE;gBACvB,MAAM,IAAI,GAAG,MAAM,KAAK,CACtB,KAAK,EACL,UAAU,KAAK,IAAI,IAAI,EAAE,CAC1B,CAAC;gBACF,OAAO,EAAE,IAAI,EAAE,IAAgE,EAAE,CAAC;YACpF,CAAC;YACD,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE;gBACnC,OAAO,KAAK,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;YACzD,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,GAAY;IAClC,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,GAAG,CAAC,OAAO,CAAC;IAC7C,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC;AAED;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,35 @@
1
+ /** Stable marker embedded in our hook's prompt so re-runs replace it in place. */
2
+ export declare const CLUD_BUG_HOOK_MARKER = "clud-bug-local-review";
3
+ /**
4
+ * The `prompt` of the Claude Code `type: agent` commit-review hook. Rather than
5
+ * baking a static recipe (which would drift from the repo's skills/config), it
6
+ * tells the subagent to run `clud-bug review-prompt` — the engine-driven verb
7
+ * that emits a recipe tailored to THIS repo's resolved plan — and follow it.
8
+ * The recipe is therefore generated fresh at commit time, always current.
9
+ */
10
+ export declare const COMMIT_REVIEW_PROMPT = "<!-- clud-bug-local-review v1 -->\nYou are clud-bug's local commit review, running as a background subagent on this\nsession's own subscription (no extra auth \u2014 you have git, gh, and file access).\n\nStep 1 \u2014 get your review recipe from clud-bug's engine:\n\n npx clud-bug review-prompt --trigger commit\n\nThat prints a structured review recipe tailored to THIS repo's skills + config (a\nfast single pass for a commit). If `npx clud-bug` isn't available, run the repo's\ninstalled clud-bug CLI instead.\n\nStep 2 \u2014 follow that recipe exactly: review the commit that was just made against\nthe skills it names, and surface any findings back into the session so they can be\nfixed. A clean commit needs only a one-line note.\n\nKeep it tight \u2014 this is the commit-time safety net; the deeper review runs at PR time.";
11
+ /** One Claude Code hook entry: a tool matcher plus its hook list. */
12
+ export interface HookMatcherEntry {
13
+ matcher?: string;
14
+ hooks: Array<Record<string, unknown>>;
15
+ }
16
+ /** Minimal shape of the `.claude/settings.json` we read + merge into. */
17
+ export interface ClaudeSettings {
18
+ hooks?: Record<string, HookMatcherEntry[]>;
19
+ [key: string]: unknown;
20
+ }
21
+ /**
22
+ * Builds the PostToolUse entry that spawns the commit-review subagent: a native
23
+ * `type: agent` hook that is backgrounded (`async`), surfaces findings
24
+ * (`asyncRewake`), and fires only on `git commit` (`if`).
25
+ */
26
+ export declare function buildLocalReviewHook(recipe: string): HookMatcherEntry;
27
+ /**
28
+ * Merges the clud-bug commit-review hook into an existing `.claude/settings.json`
29
+ * object. **Idempotent** (replaces any prior clud-bug entry rather than
30
+ * duplicating) and **non-clobbering** (preserves every other top-level key,
31
+ * every other event, and every other hook). Tolerates a missing/malformed
32
+ * `existing` value.
33
+ */
34
+ export declare function mergeLocalReviewHook(existing: unknown, recipe: string): ClaudeSettings;
35
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/cli/hooks.ts"],"names":[],"mappings":"AAcA,kFAAkF;AAClF,eAAO,MAAM,oBAAoB,0BAA0B,CAAC;AAE5D;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,00BAgBsD,CAAC;AAExF,qEAAqE;AACrE,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACvC;AAED,yEAAyE;AACzE,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAC3C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAcrE;AAUD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAwBtF"}
@@ -0,0 +1,98 @@
1
+ // Wave 6b — Claude Code `type: agent` commit-review hook scaffolding.
2
+ //
3
+ // `clud-bug init --with-hooks` writes a native Claude Code hook that, on every
4
+ // `git commit` the agent makes, spawns a clud-bug review SUBAGENT in the same
5
+ // session — so it runs on the session's subscription (no API key), in the
6
+ // background (the commit never blocks), and surfaces findings back to the agent.
7
+ //
8
+ // The model (see the Wave 6b plan): clud-bug supplies the *recipe* (the
9
+ // agent-hook `prompt`); Claude Code runs it as a subagent. This is the dynamic,
10
+ // always-on counterpart to the `/clud-bug-review` slash command.
11
+ //
12
+ // `type: agent` hooks are documented as experimental; the same outcome is
13
+ // reachable via a `type: command` hook + `additionalContext` if the API shifts.
14
+ /** Stable marker embedded in our hook's prompt so re-runs replace it in place. */
15
+ export const CLUD_BUG_HOOK_MARKER = 'clud-bug-local-review';
16
+ /**
17
+ * The `prompt` of the Claude Code `type: agent` commit-review hook. Rather than
18
+ * baking a static recipe (which would drift from the repo's skills/config), it
19
+ * tells the subagent to run `clud-bug review-prompt` — the engine-driven verb
20
+ * that emits a recipe tailored to THIS repo's resolved plan — and follow it.
21
+ * The recipe is therefore generated fresh at commit time, always current.
22
+ */
23
+ export const COMMIT_REVIEW_PROMPT = `<!-- ${CLUD_BUG_HOOK_MARKER} v1 -->
24
+ You are clud-bug's local commit review, running as a background subagent on this
25
+ session's own subscription (no extra auth — you have git, gh, and file access).
26
+
27
+ Step 1 — get your review recipe from clud-bug's engine:
28
+
29
+ npx clud-bug review-prompt --trigger commit
30
+
31
+ That prints a structured review recipe tailored to THIS repo's skills + config (a
32
+ fast single pass for a commit). If \`npx clud-bug\` isn't available, run the repo's
33
+ installed clud-bug CLI instead.
34
+
35
+ Step 2 — follow that recipe exactly: review the commit that was just made against
36
+ the skills it names, and surface any findings back into the session so they can be
37
+ fixed. A clean commit needs only a one-line note.
38
+
39
+ Keep it tight — this is the commit-time safety net; the deeper review runs at PR time.`;
40
+ /**
41
+ * Builds the PostToolUse entry that spawns the commit-review subagent: a native
42
+ * `type: agent` hook that is backgrounded (`async`), surfaces findings
43
+ * (`asyncRewake`), and fires only on `git commit` (`if`).
44
+ */
45
+ export function buildLocalReviewHook(recipe) {
46
+ return {
47
+ matcher: 'Bash',
48
+ hooks: [
49
+ {
50
+ type: 'agent',
51
+ if: 'Bash(git commit *)',
52
+ async: true,
53
+ asyncRewake: true,
54
+ timeout: 180,
55
+ prompt: recipe,
56
+ },
57
+ ],
58
+ };
59
+ }
60
+ function isOurHook(h) {
61
+ return typeof h?.['prompt'] === 'string' && h['prompt'].includes(CLUD_BUG_HOOK_MARKER);
62
+ }
63
+ function isCludBugReviewEntry(entry) {
64
+ return !!entry && Array.isArray(entry.hooks) && entry.hooks.some(isOurHook);
65
+ }
66
+ /**
67
+ * Merges the clud-bug commit-review hook into an existing `.claude/settings.json`
68
+ * object. **Idempotent** (replaces any prior clud-bug entry rather than
69
+ * duplicating) and **non-clobbering** (preserves every other top-level key,
70
+ * every other event, and every other hook). Tolerates a missing/malformed
71
+ * `existing` value.
72
+ */
73
+ export function mergeLocalReviewHook(existing, recipe) {
74
+ const base = existing && typeof existing === 'object' ? { ...existing } : {};
75
+ const hooks = { ...(base.hooks ?? {}) };
76
+ const priorPost = Array.isArray(hooks.PostToolUse) ? hooks.PostToolUse : [];
77
+ // Preserve every non-clud-bug hook — including any the user co-located INSIDE
78
+ // our own matcher entry: drop only the hook(s) carrying our marker, never the
79
+ // whole entry.
80
+ const ours = buildLocalReviewHook(recipe);
81
+ const otherEntries = [];
82
+ const coLocatedUserHooks = [];
83
+ for (const entry of priorPost) {
84
+ if (isCludBugReviewEntry(entry)) {
85
+ for (const h of entry.hooks)
86
+ if (!isOurHook(h))
87
+ coLocatedUserHooks.push(h);
88
+ }
89
+ else {
90
+ otherEntries.push(entry);
91
+ }
92
+ }
93
+ const ourEntry = coLocatedUserHooks.length > 0 ? { ...ours, hooks: [...coLocatedUserHooks, ...ours.hooks] } : ours;
94
+ hooks.PostToolUse = [...otherEntries, ourEntry];
95
+ base.hooks = hooks;
96
+ return base;
97
+ }
98
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/cli/hooks.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,0EAA0E;AAC1E,iFAAiF;AACjF,EAAE;AACF,wEAAwE;AACxE,gFAAgF;AAChF,iEAAiE;AACjE,EAAE;AACF,0EAA0E;AAC1E,gFAAgF;AAEhF,kFAAkF;AAClF,MAAM,CAAC,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAE5D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,oBAAoB;;;;;;;;;;;;;;;;uFAgBuB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E,CAAC;IAC5C,MAAM,kBAAkB,GAAmC,EAAE,CAAC;IAC9D,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;QAC9B,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK;gBAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;oBAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7E,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IACD,MAAM,QAAQ,GACZ,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,kBAAkB,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACpG,KAAK,CAAC,WAAW,GAAG,CAAC,GAAG,YAAY,EAAE,QAAQ,CAAC,CAAC;IAChD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACnB,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -5,4 +5,5 @@ export { renderBlock, detectSkillRelPath, upsertBlock, hasAgentsMdImport, remove
5
5
  export { computeSkillUsageDelta, mergeSkillUsage, assessSkillHealth, formatHealthDashboard, DEFAULT_GH_RUNNER, fetchUsageArtifacts, aggregateUsageStream, type SkillDelta, type SkillUsageEntry, type SkillDeltaMap, type SkillUsageMap, type SkillHealthStatus, type SkillHealthRow, type GhRunResult, type GhRunner, type FetchUsageArtifactsOptions, type UsageArtifactRecord, } from './skill-usage.js';
6
6
  export { PRICING, computeReviewCost, costPerLOC, cacheHitRate, extractTokensFromLog, rollup, formatRollup, type ModelPricing, type TokenCounts, type CostParts, type ReviewCost, type ExtractedTokens, type ReviewRecord, type RollupGroupStats, type RollupTotal, type RollupTrend, type RollupOutlier, type UnknownModelReview, type Rollup, type FormatRollupOptions, } from './usage.js';
7
7
  export { runUpdate, type RunUpdateOptions, type UpdateChangeRecord, type UpdateSkippedRecord, type RunUpdateResult, } from './update.js';
8
+ export { runConfigureGithub, ghCliOctokit, type RunConfigureGithubOptions, } from './configure-github.js';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,EAC5B,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,mCAAmC,EACxC,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,GAAG,EACH,KAAK,oBAAoB,EACzB,KAAK,UAAU,EACf,KAAK,SAAS,GACf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,MAAM,EACN,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,MAAM,EACX,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,EAC5B,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,mCAAmC,EACxC,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,GAAG,EACH,KAAK,oBAAoB,EACzB,KAAK,UAAU,EACf,KAAK,SAAS,GACf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,MAAM,EACN,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,MAAM,EACX,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,KAAK,yBAAyB,GAC/B,MAAM,uBAAuB,CAAC"}
package/dist/cli/index.js CHANGED
@@ -15,4 +15,5 @@ export { renderBlock, detectSkillRelPath, upsertBlock, hasAgentsMdImport, remove
15
15
  export { computeSkillUsageDelta, mergeSkillUsage, assessSkillHealth, formatHealthDashboard, DEFAULT_GH_RUNNER, fetchUsageArtifacts, aggregateUsageStream, } from './skill-usage.js';
16
16
  export { PRICING, computeReviewCost, costPerLOC, cacheHitRate, extractTokensFromLog, rollup, formatRollup, } from './usage.js';
17
17
  export { runUpdate, } from './update.js';
18
+ export { runConfigureGithub, ghCliOctokit, } from './configure-github.js';
18
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,0CAA0C;AAC1C,EAAE;AACF,oEAAoE;AACpE,uEAAuE;AACvE,iBAAiB;AAEjB,oEAAoE;AACpE,oEAAoE;AACpE,0DAA0D;AAC1D,oCAAoC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,GAW7B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,GAAG,GAIJ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,WAAW,GAGZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,GAWrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,MAAM,EACN,YAAY,GAcb,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,SAAS,GAKV,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,0CAA0C;AAC1C,EAAE;AACF,oEAAoE;AACpE,uEAAuE;AACvE,iBAAiB;AAEjB,oEAAoE;AACpE,oEAAoE;AACpE,0DAA0D;AAC1D,oCAAoC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,GAW7B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,GAAG,GAIJ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,WAAW,GAGZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,GAWrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,MAAM,EACN,YAAY,GAcb,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,SAAS,GAKV,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,kBAAkB,EAClB,YAAY,GAEb,MAAM,uBAAuB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":"AA6KA,iBAAe,IAAI,kBAwBlB;AA0pCD,OAAO,EAAE,IAAI,EAAE,CAAC"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":"AAmPA,iBAAe,IAAI,kBA6BlB;AAk8DD,OAAO,EAAE,IAAI,EAAE,CAAC"}