agent-rulebook 0.2.0 → 0.3.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 (181) hide show
  1. package/README.md +58 -4
  2. package/dist/commands/dashboard.d.ts +7 -0
  3. package/dist/commands/dashboard.js +42 -0
  4. package/dist/commands/dashboard.js.map +1 -0
  5. package/dist/commands/diagnostics.d.ts +2 -0
  6. package/dist/commands/diagnostics.js +38 -0
  7. package/dist/commands/diagnostics.js.map +1 -0
  8. package/dist/commands/home.d.ts +2 -0
  9. package/dist/commands/home.js +59 -0
  10. package/dist/commands/home.js.map +1 -0
  11. package/dist/commands/import.d.ts +2 -0
  12. package/dist/commands/import.js +34 -0
  13. package/dist/commands/import.js.map +1 -0
  14. package/dist/commands/pending.d.ts +2 -0
  15. package/dist/commands/pending.js +27 -0
  16. package/dist/commands/pending.js.map +1 -0
  17. package/dist/commands/resolution.js +25 -11
  18. package/dist/commands/resolution.js.map +1 -1
  19. package/dist/commands/stats-renderer.d.ts +3 -0
  20. package/dist/commands/stats-renderer.js +76 -0
  21. package/dist/commands/stats-renderer.js.map +1 -0
  22. package/dist/commands/stats.d.ts +4 -0
  23. package/dist/commands/stats.js +107 -0
  24. package/dist/commands/stats.js.map +1 -0
  25. package/dist/commands/status.d.ts +2 -0
  26. package/dist/commands/status.js +17 -0
  27. package/dist/commands/status.js.map +1 -0
  28. package/dist/commands/sync.js +1 -1
  29. package/dist/commands/sync.js.map +1 -1
  30. package/dist/commands/usage.d.ts +2 -0
  31. package/dist/commands/usage.js +25 -0
  32. package/dist/commands/usage.js.map +1 -0
  33. package/dist/core/codex-call-parser.d.ts +10 -0
  34. package/dist/core/codex-call-parser.js +97 -0
  35. package/dist/core/codex-call-parser.js.map +1 -0
  36. package/dist/core/codex-usage-import.d.ts +24 -0
  37. package/dist/core/codex-usage-import.js +259 -0
  38. package/dist/core/codex-usage-import.js.map +1 -0
  39. package/dist/core/diagnostic-cluster.d.ts +37 -0
  40. package/dist/core/diagnostic-cluster.js +20 -0
  41. package/dist/core/diagnostic-cluster.js.map +1 -0
  42. package/dist/core/environment-normalization.d.ts +21 -0
  43. package/dist/core/environment-normalization.js +42 -0
  44. package/dist/core/environment-normalization.js.map +1 -0
  45. package/dist/core/index.d.ts +1 -0
  46. package/dist/core/index.js +1 -0
  47. package/dist/core/index.js.map +1 -1
  48. package/dist/core/invocation-diagnostics.d.ts +40 -0
  49. package/dist/core/invocation-diagnostics.js +91 -0
  50. package/dist/core/invocation-diagnostics.js.map +1 -0
  51. package/dist/core/legacy-candidate.d.ts +159 -0
  52. package/dist/core/legacy-candidate.js +73 -0
  53. package/dist/core/legacy-candidate.js.map +1 -0
  54. package/dist/core/legacy-import-apply.d.ts +215 -0
  55. package/dist/core/legacy-import-apply.js +172 -0
  56. package/dist/core/legacy-import-apply.js.map +1 -0
  57. package/dist/core/legacy-import-manifest.d.ts +197 -0
  58. package/dist/core/legacy-import-manifest.js +63 -0
  59. package/dist/core/legacy-import-manifest.js.map +1 -0
  60. package/dist/core/legacy-scan.d.ts +71 -0
  61. package/dist/core/legacy-scan.js +99 -0
  62. package/dist/core/legacy-scan.js.map +1 -0
  63. package/dist/core/pending-replay.d.ts +4 -0
  64. package/dist/core/pending-replay.js +96 -0
  65. package/dist/core/pending-replay.js.map +1 -0
  66. package/dist/core/resolution-applicability.d.ts +1 -0
  67. package/dist/core/resolution-applicability.js +28 -11
  68. package/dist/core/resolution-applicability.js.map +1 -1
  69. package/dist/core/resolution-ranker.js +9 -2
  70. package/dist/core/resolution-ranker.js.map +1 -1
  71. package/dist/core/resolution-search-types.d.ts +9 -0
  72. package/dist/core/statistics-data.d.ts +98 -0
  73. package/dist/core/statistics-data.js +53 -0
  74. package/dist/core/statistics-data.js.map +1 -0
  75. package/dist/core/statistics-pages.d.ts +3 -0
  76. package/dist/core/statistics-pages.js +107 -0
  77. package/dist/core/statistics-pages.js.map +1 -0
  78. package/dist/core/statistics-query.d.ts +86 -0
  79. package/dist/core/statistics-query.js +51 -0
  80. package/dist/core/statistics-query.js.map +1 -0
  81. package/dist/core/statistics-types.d.ts +286 -0
  82. package/dist/core/statistics-types.js +2 -0
  83. package/dist/core/statistics-types.js.map +1 -0
  84. package/dist/core/statistics.d.ts +5 -0
  85. package/dist/core/statistics.js +101 -0
  86. package/dist/core/statistics.js.map +1 -0
  87. package/dist/core/sync-status.d.ts +53 -0
  88. package/dist/core/sync-status.js +85 -0
  89. package/dist/core/sync-status.js.map +1 -0
  90. package/dist/core/usage-context.d.ts +15 -0
  91. package/dist/core/usage-context.js +22 -0
  92. package/dist/core/usage-context.js.map +1 -0
  93. package/dist/core/usage-observer.d.ts +36 -0
  94. package/dist/core/usage-observer.js +112 -0
  95. package/dist/core/usage-observer.js.map +1 -0
  96. package/dist/core/usage-schema.d.ts +113 -0
  97. package/dist/core/usage-schema.js +33 -0
  98. package/dist/core/usage-schema.js.map +1 -0
  99. package/dist/dashboard/public/api.js +41 -0
  100. package/dist/dashboard/public/app.js +111 -0
  101. package/dist/dashboard/public/components/detail-panel.js +21 -0
  102. package/dist/dashboard/public/components/index.js +216 -0
  103. package/dist/dashboard/public/components/input-diff.js +15 -0
  104. package/dist/dashboard/public/diagnostic-detail.js +25 -0
  105. package/dist/dashboard/public/diagnostics.js +46 -0
  106. package/dist/dashboard/public/index.html +28 -0
  107. package/dist/dashboard/public/knowledge.js +57 -0
  108. package/dist/dashboard/public/overview.js +101 -0
  109. package/dist/dashboard/public/solution-detail.js +42 -0
  110. package/dist/dashboard/public/styles.css +205 -0
  111. package/dist/dashboard/server.d.ts +10 -0
  112. package/dist/dashboard/server.js +133 -0
  113. package/dist/dashboard/server.js.map +1 -0
  114. package/dist/index.d.ts +4 -0
  115. package/dist/index.js +3 -0
  116. package/dist/index.js.map +1 -1
  117. package/dist/mcp/observed-transport.d.ts +20 -0
  118. package/dist/mcp/observed-transport.js +99 -0
  119. package/dist/mcp/observed-transport.js.map +1 -0
  120. package/dist/mcp/resolution-change.d.ts +1 -1
  121. package/dist/mcp/resolution-change.js +24 -9
  122. package/dist/mcp/resolution-change.js.map +1 -1
  123. package/dist/mcp/resolutions-commit-change-tool.d.ts +5 -0
  124. package/dist/mcp/resolutions-commit-change-tool.js +22 -4
  125. package/dist/mcp/resolutions-commit-change-tool.js.map +1 -1
  126. package/dist/mcp/resolutions-find-tool.d.ts +1 -2
  127. package/dist/mcp/resolutions-find-tool.js +43 -8
  128. package/dist/mcp/resolutions-find-tool.js.map +1 -1
  129. package/dist/mcp/resolutions-list-facets-tool.d.ts +1 -1
  130. package/dist/mcp/resolutions-list-facets-tool.js +16 -2
  131. package/dist/mcp/resolutions-list-facets-tool.js.map +1 -1
  132. package/dist/mcp/resolutions-report-attempt-tool.d.ts +1 -0
  133. package/dist/mcp/resolutions-report-attempt-tool.js +44 -55
  134. package/dist/mcp/resolutions-report-attempt-tool.js.map +1 -1
  135. package/dist/mcp/schemas.d.ts +299 -14
  136. package/dist/mcp/schemas.js +31 -10
  137. package/dist/mcp/schemas.js.map +1 -1
  138. package/dist/mcp/server.js +20 -5
  139. package/dist/mcp/server.js.map +1 -1
  140. package/dist/mcp/stats-get-tool.d.ts +99 -0
  141. package/dist/mcp/stats-get-tool.js +17 -0
  142. package/dist/mcp/stats-get-tool.js.map +1 -0
  143. package/dist/mcp/tool-call.d.ts +99 -0
  144. package/dist/mcp/tool-call.js +20 -0
  145. package/dist/mcp/tool-call.js.map +1 -0
  146. package/dist/mcp/tool-output.d.ts +9 -0
  147. package/dist/mcp/tool-output.js +22 -0
  148. package/dist/mcp/tool-output.js.map +1 -1
  149. package/dist/mcp/tools.d.ts +182 -27
  150. package/dist/mcp/tools.js +9 -2
  151. package/dist/mcp/tools.js.map +1 -1
  152. package/dist/program.js +16 -0
  153. package/dist/program.js.map +1 -1
  154. package/dist/storage/canonical-write-lock.d.ts +2 -0
  155. package/dist/storage/canonical-write-lock.js +32 -0
  156. package/dist/storage/canonical-write-lock.js.map +1 -0
  157. package/dist/storage/diagnostic-store.d.ts +21 -0
  158. package/dist/storage/diagnostic-store.js +50 -0
  159. package/dist/storage/diagnostic-store.js.map +1 -0
  160. package/dist/storage/import-manifest.d.ts +6 -0
  161. package/dist/storage/import-manifest.js +41 -0
  162. package/dist/storage/import-manifest.js.map +1 -0
  163. package/dist/storage/pending-store.d.ts +329 -0
  164. package/dist/storage/pending-store.js +164 -0
  165. package/dist/storage/pending-store.js.map +1 -0
  166. package/dist/storage/resolution-candidate-service.js +2 -1
  167. package/dist/storage/resolution-candidate-service.js.map +1 -1
  168. package/dist/storage/resolution-change-transaction.d.ts +41 -3
  169. package/dist/storage/resolution-change-transaction.js +101 -12
  170. package/dist/storage/resolution-change-transaction.js.map +1 -1
  171. package/dist/storage/resolution-home.d.ts +2 -1
  172. package/dist/storage/resolution-home.js +5 -2
  173. package/dist/storage/resolution-home.js.map +1 -1
  174. package/dist/storage/resolution-index-check.js +3 -2
  175. package/dist/storage/resolution-index-check.js.map +1 -1
  176. package/dist/storage/resolution-indexer.js +3 -1
  177. package/dist/storage/resolution-indexer.js.map +1 -1
  178. package/dist/storage/usage-store.d.ts +80 -0
  179. package/dist/storage/usage-store.js +239 -0
  180. package/dist/storage/usage-store.js.map +1 -0
  181. package/package.json +11 -4
package/README.md CHANGED
@@ -6,19 +6,30 @@ Agent Rulebook is a local-first Resolution Memory for coding agents. It stores o
6
6
 
7
7
  ```bash
8
8
  npm install -g agent-rulebook
9
- npx -y agent-rulebook@0.2.0 --help
10
- npx -y agent-rulebook@0.2.0 mcp
9
+ npx -y agent-rulebook@0.3.0 --help
10
+ npx -y agent-rulebook@0.3.0 mcp
11
11
  agent-rulebook init
12
12
  agent-rulebook index rebuild
13
13
  ```
14
14
 
15
- `agent-rulebook@0.2.0` is an immutable package version. Registry tags such as `latest` are mutable and are not asserted by this artifact. This source revision describes a local release candidate until registry acceptance is recorded.
15
+ `agent-rulebook@0.3.0` is an immutable package version. This source candidate has not been published yet. Registry tags such as `latest` are mutable and are not asserted by this artifact. This source revision describes a local release candidate until registry acceptance is recorded.
16
16
 
17
17
  The home defaults to `~/.agent-rulebook` and can be overridden with `AGENT_RULEBOOK_HOME`. Portable Git data is limited to `config.yaml`, `problems/`, `solutions/`, and `outcomes/`. `projects.local.yaml`, `index/`, and `logs/` stay local.
18
18
 
19
+ For an explicitly approved clean break from a legacy rules home, preview the exact deletion allowlist first. Execution requires an exact resolved home, the confirmation phrase, a Git worktree, and `remote.origin.agentRulebookPrivacy=private`:
20
+
21
+ ```bash
22
+ agent-rulebook home reset --dry-run --json
23
+ agent-rulebook home reset --execute \
24
+ --expected-home /absolute/path/to/.agent-rulebook \
25
+ --confirm 'RESET LEGACY RULEBOOK' --json
26
+ ```
27
+
28
+ Reset removes only legacy `rules/` and the derived `index/`, then establishes the v3 bootstrap files and directories. It preserves `.git`, its remote/history, `projects.local.yaml`, and logs.
29
+
19
30
  ## MCP tools
20
31
 
21
- The stdio server exposes exactly seven client-neutral tools:
32
+ The source candidate stdio server exposes eight client-neutral tools. Published 0.2.1 remains the historical seven-tool artifact; it does not include stats or the dashboard. The candidate manifest profile is `usage-v1-eight-tools`, intended for the next 0.3.x release:
22
33
 
23
34
  - `resolutions.find`: search at the first unexpected problem using observations, hypotheses, and environment.
24
35
  - `resolutions.get`: inspect one candidate's applicability, actions, safety, and verification.
@@ -27,6 +38,7 @@ The stdio server exposes exactly seven client-neutral tools:
27
38
  - `resolutions.report_attempt`: append a verified, context-scoped attempt outcome.
28
39
  - `resolutions.prepare_change`: classify and validate a verified canonical change without writing.
29
40
  - `resolutions.commit_change`: revalidate an unchanged payload/hash and commit atomically.
41
+ - `stats.get`: read bounded local counts, rates, coverage and health without recording the query or launching a browser.
30
42
 
31
43
  Start the server with:
32
44
 
@@ -79,15 +91,47 @@ Bootstrap clones canonical data, validates the v3 config and allowlist, and rebu
79
91
 
80
92
  ```text
81
93
  init
94
+ home reset --dry-run|--execute
82
95
  index rebuild|check
83
96
  project register|list|check
84
97
  resolution find|get|get-source
98
+ stats [--days 30|--all] [--project key] [--language family]
99
+ stats --json|--watch
100
+ dashboard [--port 4318] [--open]
101
+ diagnostics list|show|export
102
+ usage health|prune
103
+ usage import-codex --from path --since UTC-date --until UTC-date [--execute]
85
104
  sync pull|push|bootstrap
86
105
  mcp
87
106
  ```
88
107
 
89
108
  `resolution find --input request.json --json` accepts the same strict input object as `resolutions.find`.
90
109
 
110
+ ### Usage over SSH
111
+
112
+ ```bash
113
+ agent-rulebook stats --days 30 --project micro-site
114
+ agent-rulebook stats --language typescript --timezone Asia/Seoul
115
+ agent-rulebook stats --json > statistics.json
116
+ agent-rulebook stats --watch
117
+ NO_COLOR=1 TERM=dumb agent-rulebook stats
118
+ ```
119
+
120
+ Stats uses local read-only data and never opens a browser or records its own queries. ASCII tables and daily bars work without a UI dependency; unknown history is labeled rather than displayed as zero. Ratios include their denominator and sample size. Default source/kind is `live/production`; choose `--source codex_history` or `--usage-kind test` explicitly. `--days` accepts 1–365 calendar days, `--all` is mutually exclusive, and `--timezone` defaults to UTC. JSON has no ANSI or progress output. Interactive `--watch` refreshes every two seconds, follows terminal width and restores input/cursor state on q, Ctrl+C, SIGINT or SIGTERM; it requires TTY input/output and cannot be combined with JSON. Use the plain command for screen-reader output or pipes.
121
+
122
+ ### Local browser dashboard
123
+
124
+ ```bash
125
+ agent-rulebook dashboard --port 4318
126
+ agent-rulebook dashboard --port 4318 --open
127
+ # On your computer, forward the remote dashboard's loopback port:
128
+ ssh -N -L 4318:127.0.0.1:4318 user@host
129
+ ```
130
+
131
+ The dashboard command prints its URL and binds only to `127.0.0.1`; default startup does not launch a browser. Use `--open` explicitly for the OS default browser, or open the printed URL yourself. For SSH, run the server remotely without `--open`, forward the same local port, then visit `http://127.0.0.1:4318` on your computer. Ctrl+C/SIGTERM closes the server. MCP startup stays independent. OS browser handoff and real SSH experience require verification on the target machine.
132
+
133
+ HTTP serves only GET routes for stats, knowledge, diagnostics and local status plus allowlisted compiled assets. Host/Origin checks, a self-only content security policy, no-store and no wildcard CORS protect the local endpoint. The server cannot execute solution actions, write canonical records or read arbitrary requested filesystem paths. Node and browser TypeScript builds use separate configs; `npm run build` compiles both and copies only allowed HTML/CSS/ESM assets, resolved independently of the command's cwd. Run `npm run typecheck:dashboard` for the DOM-only client check.
134
+
91
135
  ## Development
92
136
 
93
137
  ```bash
@@ -99,3 +143,13 @@ npm run check:package
99
143
  ```
100
144
 
101
145
  The derived index uses the pinned native `better-sqlite3` driver. The package contains compiled runtime files, this README, package metadata, and the license; tests, fixtures, source trees, local databases, and personal paths are excluded.
146
+
147
+ ### Dashboard development and browser checks
148
+
149
+ `npm run build` emits production assets only. `npm run dashboard:dev` serves an isolated temporary Rulebook home on port 4319, plus `/__gallery` using the production primitives. It never reads the configured real home. Stop with Ctrl+C to remove its temporary data. Gallery source and fixtures are excluded from the npm files allowlist and production routes.
150
+
151
+ For repeatable CI, `npm run test:browser -- tests/browser/dashboard-gallery.spec.ts` launches the installed Chrome channel in an isolated Playwright context; it requires Chrome and does not use personal browser profiles. `npm run test:browser -- --list` checks discovery only. When an agent must use the connected Chrome surface, execute the same filter/reset/sort/retry/skip-link assertions through that surface against this isolated fixture server and record that evidence separately; discovery is not a browser pass. Node/API tests remain in Vitest. Browser suite source types can be checked with `./node_modules/.bin/tsc -p tsconfig.browser-tests.json`.
152
+
153
+ ### Prepare a release candidate
154
+
155
+ `npm run prepare-release` requires committed, clean source and an unused exact registry version. It records source identity, tarball SHA-256/SHA-512, eight-tool manifest, full regression, cold/warm CLI/MCP/dashboard checks and rollback target in `docs/releases/<version>-candidate.json`. Artifacts live in immutable `.release-candidates/<sha256>/` directories. `--prepare-only` runs focused artifact checks and marks the receipt **pending full regression**. Neither mode publishes or changes the installed MCP pin. See `docs/releases/0.3.0-rollout.md` for the separate operational sequence and platform limits.
@@ -0,0 +1,7 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerDashboardCommand(program: Command): Command;
3
+ export declare function dashboardOpener(url: string, platform?: NodeJS.Platform): {
4
+ command: string;
5
+ args: string[];
6
+ };
7
+ export declare function openDashboardUrl(url: string): Promise<void>;
@@ -0,0 +1,42 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { resolveRulebookHome } from '../core/index.js';
3
+ import { startDashboardServer } from '../dashboard/server.js';
4
+ export function registerDashboardCommand(program) {
5
+ const command = program.command('dashboard').description('Serve the read-only browser dashboard on 127.0.0.1')
6
+ .option('--port <port>', 'Local port; 0 chooses a free port for tests', '4318').option('--open', 'Explicitly open the URL in the default browser')
7
+ .addHelpText('after', '\nSSH: run without --open on the remote, then ssh -N -L 4318:127.0.0.1:4318 user@host and browse http://127.0.0.1:4318 locally.');
8
+ command.action(async (options) => {
9
+ if (!/^\d+$/.test(options.port) || Number(options.port) > 65535)
10
+ command.error('Invalid dashboard port (0..65535).');
11
+ let running;
12
+ try {
13
+ running = await startDashboardServer({ home: resolveRulebookHome(), port: Number(options.port) });
14
+ }
15
+ catch (error) {
16
+ command.error(error.code === 'EADDRINUSE' ? 'Dashboard port is in use. Choose another --port.' : 'Dashboard could not start.');
17
+ }
18
+ process.stdout.write(`Agent Rulebook dashboard: ${running.url}\nRead-only local server. Ctrl+C to stop.\n`);
19
+ if (options.open)
20
+ await openDashboardUrl(running.url).catch(() => process.stderr.write('Browser could not be opened; use the printed URL.\n'));
21
+ await new Promise((resolve) => {
22
+ const stop = () => { process.off('SIGINT', stop); process.off('SIGTERM', stop); void running.close().then(resolve, () => { process.exitCode = 1; resolve(); }); };
23
+ process.on('SIGINT', stop);
24
+ process.on('SIGTERM', stop);
25
+ });
26
+ });
27
+ return command;
28
+ }
29
+ export function dashboardOpener(url, platform = process.platform) {
30
+ if (!/^http:\/\/127\.0\.0\.1:[0-9]{1,5}$/.test(url))
31
+ throw new Error('invalid_dashboard_url');
32
+ if (platform === 'darwin')
33
+ return { command: 'open', args: [url] };
34
+ if (platform === 'win32')
35
+ return { command: 'rundll32.exe', args: ['url.dll,FileProtocolHandler', url] };
36
+ return { command: 'xdg-open', args: [url] };
37
+ }
38
+ export async function openDashboardUrl(url) {
39
+ const launcher = dashboardOpener(url);
40
+ await new Promise((resolve, reject) => { const child = spawn(launcher.command, launcher.args, { stdio: 'ignore', shell: false }); const timer = setTimeout(() => { child.kill(); reject(new Error('browser_open_timeout')); }, 5000); child.once('error', (e) => { clearTimeout(timer); reject(e); }); child.once('exit', (code) => { clearTimeout(timer); code === 0 ? resolve() : reject(new Error('browser_open_failed')); }); });
41
+ }
42
+ //# sourceMappingURL=dashboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashboard.js","sourceRoot":"","sources":["../../src/commands/dashboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,MAAM,UAAU,wBAAwB,CAAC,OAAgB;IACvD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC,oDAAoD,CAAC;SAC3G,MAAM,CAAC,eAAe,EAAE,6CAA6C,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,gDAAgD,CAAC;SACjJ,WAAW,CAAC,OAAO,EAAE,iIAAiI,CAAC,CAAC;IAC3J,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK;YAAE,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACrH,IAAI,OAAyD,CAAC;QAC9D,IAAI,CAAC;YAAC,OAAO,GAAG,MAAM,oBAAoB,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,C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IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7a,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerDiagnosticsCommand(program: Command): void;
@@ -0,0 +1,38 @@
1
+ import { writeFile } from 'node:fs/promises';
2
+ import { resolveRulebookHome } from '../core/index.js';
3
+ import { clusterDiagnostics, exportDiagnosticFixture } from '../core/diagnostic-cluster.js';
4
+ import { readDiagnostics } from '../storage/diagnostic-store.js';
5
+ import { writeJson } from './output.js';
6
+ export function registerDiagnosticsCommand(program) {
7
+ const command = program.command('diagnostics').description('Inspect safe rejected-call shapes; raw inputs are not retained');
8
+ command.command('list').option('--json').action((options) => {
9
+ const data = readDiagnostics(resolveRulebookHome());
10
+ const clusters = clusterDiagnostics(data.diagnostics, data.events);
11
+ if (options.json)
12
+ writeJson({ status: data.status, clusters });
13
+ else {
14
+ process.stdout.write('COUNT\tTOOL\tREPRESENTATIVE ID\tSUCCESSFUL EXPLICIT RETRIES\n');
15
+ for (const cluster of clusters)
16
+ process.stdout.write(`${cluster.count}\t${cluster.tool}\t${cluster.representative_id}\t${cluster.successful_retry_count}\n`);
17
+ }
18
+ });
19
+ command.command('show').argument('<id>').option('--json').action((id) => {
20
+ const data = readDiagnostics(resolveRulebookHome());
21
+ writeJson(data.diagnostics.find(({ diagnostic_id }) => diagnostic_id === id) ?? { status: 'not_found' });
22
+ });
23
+ command.command('export').argument('<id>').option('--output <json>', 'Write a new JSON fixture; existing files are never overwritten').option('--json').action(async (id, options) => {
24
+ const record = readDiagnostics(resolveRulebookHome()).diagnostics.find(({ diagnostic_id }) => diagnostic_id === id);
25
+ if (!record) {
26
+ writeJson({ status: 'not_found' });
27
+ return;
28
+ }
29
+ const fixture = exportDiagnosticFixture(record);
30
+ if (options.output) {
31
+ await writeFile(options.output, `${JSON.stringify(fixture, null, 2)}\n`, { flag: 'wx', mode: 0o600 });
32
+ writeJson({ status: 'exported', diagnostic_id: id, kind: fixture.kind, raw_payload_retained: false });
33
+ }
34
+ else
35
+ writeJson(fixture);
36
+ });
37
+ }
38
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/commands/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,UAAU,0BAA0B,CAAC,OAAgB;IACzD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,WAAW,CAAC,gEAAgE,CAAC,CAAC;IAC7H,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QAC1D,MAAM,IAAI,GAAG,eAAe,CAAC,mBAAmB,EAAE,CAAC,CAAC;QAAC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACxH,IAAI,OAAO,CAAC,IAAI;YAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;aAC1D,CAAC;YAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAC;YAAC,KAAK,MAAM,OAAO,IAAI,QAAQ;gBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,IAA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AAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YAAC,SAAS,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC,CAAC;QAAC,CAAC;;YAChO,SAAS,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerHomeCommand(program: Command): Command;
@@ -0,0 +1,59 @@
1
+ import { inspectRemotePrivacy, resolveRulebookHome } from '../core/index.js';
2
+ import { executeLegacyReset, previewLegacyReset } from '../storage/index.js';
3
+ import { writeJson } from './output.js';
4
+ export function registerHomeCommand(program) {
5
+ const homeCommand = program
6
+ .command('home')
7
+ .description('Manage the local Resolution Memory home');
8
+ homeCommand
9
+ .command('reset')
10
+ .description('Preview or execute the guarded legacy-to-v3 clean reset')
11
+ .option('--dry-run', 'Preview the exact deletion allowlist without writing')
12
+ .option('--execute', 'Execute the guarded reset')
13
+ .option('--expected-home <path>', 'Exact home path required for execution')
14
+ .option('--confirm <phrase>', 'Exact confirmation phrase required for execution')
15
+ .option('--json', 'Print JSON output')
16
+ .action(async (options) => {
17
+ if (options.dryRun === options.execute)
18
+ throw new Error('Choose exactly one of --dry-run or --execute');
19
+ const home = resolveRulebookHome();
20
+ const preview = await previewLegacyReset(home);
21
+ if (options.dryRun === true) {
22
+ emit(options, {
23
+ status: 'preview',
24
+ home: preview.home,
25
+ deletion_targets: preview.deletionTargets,
26
+ rewritten: preview.rewritten,
27
+ preserved: preview.preserved,
28
+ });
29
+ return;
30
+ }
31
+ if (options.expectedHome === undefined)
32
+ throw new Error('--expected-home is required for execution');
33
+ const privacy = await inspectRemotePrivacy(home);
34
+ if (privacy.privacy !== 'private')
35
+ throw new Error('Reset requires a verified private Git remote');
36
+ const result = await executeLegacyReset({
37
+ home,
38
+ expectedHome: options.expectedHome,
39
+ confirmation: options.confirm ?? '',
40
+ privateGitVerified: true,
41
+ });
42
+ emit(options, {
43
+ status: 'reset',
44
+ home: result.home,
45
+ deleted: result.deletionTargets,
46
+ rewritten: result.rewritten,
47
+ preserved: result.preserved,
48
+ private_remote_verified: true,
49
+ });
50
+ });
51
+ return program;
52
+ }
53
+ function emit(options, value) {
54
+ if (options.json === true)
55
+ writeJson(value);
56
+ else
57
+ process.stdout.write(`${JSON.stringify(value)}\n`);
58
+ }
59
+ //# sourceMappingURL=home.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"home.js","sourceRoot":"","sources":["../../src/commands/home.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAUxC,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,MAAM,WAAW,GAAG,OAAO;SACxB,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,yCAAyC,CAAC,CAAC;IAE1D,WAAW;SACR,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,yDAAyD,CAAC;SACtE,MAAM,CAAC,WAAW,EAAE,sDAAsD,CAAC;SAC3E,MAAM,CAAC,WAAW,EAAE,2BAA2B,CAAC;SAChD,MAAM,CAAC,wBAAwB,EAAE,wCAAwC,CAAC;SAC1E,MAAM,CAAC,oBAAoB,EAAE,kDAAkD,CAAC;SAChF,MAAM,CAAC,QAAQ,EAAE,mBAAmB,CAAC;SACrC,MAAM,CAAC,KAAK,EAAE,OAAqB,EAAE,EAAE;QACtC,IAAI,OAAO,CAAC,MAAM,KAAK,OAAO,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QACxG,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E,SAAS,CAAC,KAAK,CAAC,CAAC;;QACvC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerImportCommand(program: Command): void;
@@ -0,0 +1,34 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { resolveRulebookHome } from '../core/index.js';
3
+ import { scanLegacySnapshot } from '../core/legacy-scan.js';
4
+ import { readImportManifest, writeImportManifest } from '../storage/import-manifest.js';
5
+ import { listLegacyCandidates, stageLegacyManifest } from '../core/legacy-import-manifest.js';
6
+ import { executeLegacyImport, previewLegacyImport } from '../core/legacy-import-apply.js';
7
+ import { writeJson } from './output.js';
8
+ export function registerImportCommand(program) {
9
+ const command = program.command('import').description('Explicitly review historical rules from immutable Git objects');
10
+ command.command('apply').requiredOption('--manifest <path>').requiredOption('--verified <json>', 'Selected entry IDs with current test evidence and candidate hashes').option('--dry-run', 'Preview only (default)').option('--execute', 'Apply the exact reviewed preview').option('--preview <json>', 'Saved JSON from dry-run; required with --execute').option('--json').action(async (options) => {
11
+ if (options.execute && (options.dryRun || !options.preview))
12
+ throw new Error('execute_requires_preview_and_no_dry_run');
13
+ const evidence = JSON.parse(await readFile(options.verified, 'utf8'));
14
+ const home = resolveRulebookHome();
15
+ writeJson(options.execute ? await executeLegacyImport(options.manifest, home, evidence, JSON.parse(await readFile(options.preview, 'utf8'))) : await previewLegacyImport(options.manifest, home, evidence));
16
+ });
17
+ command.command('stage').requiredOption('--manifest <path>').option('--drafts <json>', 'Reviewed problem/solution contracts keyed by entry_id; no current verification implied').option('--json').action(async (options) => writeJson(await stageLegacyManifest(options.manifest, resolveRulebookHome(), options.drafts ? JSON.parse(await readFile(options.drafts, 'utf8')) : undefined)));
18
+ command.command('list').requiredOption('--manifest <path>').option('--json').action(async (options) => {
19
+ const result = listLegacyCandidates(await readImportManifest(options.manifest));
20
+ if (options.json)
21
+ writeJson(result);
22
+ else {
23
+ process.stdout.write('ENTRY\tSTATUS\tRELATION\tMISSING FIELDS\n');
24
+ for (const item of result.items)
25
+ process.stdout.write(`${item.entry_id}\t${item.status}\t${item.relation ?? '-'}\t${item.missing_fields?.join(', ') ?? '-'}\n`);
26
+ }
27
+ });
28
+ command.command('scan').requiredOption('--repo <path>').requiredOption('--ref <ref>').requiredOption('--output <manifest>', 'Use home/imports/*.manifest.json or an explicit temporary path').option('--json').action(async (options) => {
29
+ const manifest = await scanLegacySnapshot(options.repo, options.ref);
30
+ await writeImportManifest(options.output, resolveRulebookHome(), manifest);
31
+ writeJson({ status: 'scanned', source_commit: manifest.source_commit, source_checksum: manifest.source_checksum, counts: manifest.counts, total: manifest.entries.length });
32
+ });
33
+ }
34
+ //# sourceMappingURL=import.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import.js","sourceRoot":"","sources":["../../src/commands/import.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC9F,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,+DAA+D,CAAC,CAAC;IACvH,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,mBAAm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AAE,QAAQ,CAAC,CAAC;QAC3E,SAAS,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,QAAQ,CAAC,aAAa,EAAE,eAAe,EAAE,QAAQ,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9K,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Command } from 'commander';
2
+ export declare function registerPendingCommand(program: Command): void;
@@ -0,0 +1,27 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { resolveRulebookHome } from '../core/index.js';
3
+ import { McpResolutionsReportAttemptInputSchema } from '../mcp/schemas.js';
4
+ import { discardPending, enqueuePending, listPending, readPending } from '../storage/pending-store.js';
5
+ import { retryPending } from '../core/pending-replay.js';
6
+ import { writeJson } from './output.js';
7
+ export function registerPendingCommand(program) {
8
+ const pending = program.command('pending').description('Inspect and explicitly retry locally deferred verified writes');
9
+ pending.command('list').option('--json').action(async (options) => {
10
+ const items = await listPending(resolveRulebookHome());
11
+ if (options.json)
12
+ writeJson({ status: 'ok', items });
13
+ else {
14
+ process.stdout.write('ID\tSTATUS\tRETRIES\n');
15
+ for (const item of items)
16
+ process.stdout.write(`${item.pending_id}\t${item.status}\t${item.retries}\n`);
17
+ }
18
+ });
19
+ pending.command('show').argument('<id>').option('--json').action(async (id) => writeJson((await readPending(resolveRulebookHome(), id)) ?? { status: 'not_found' }));
20
+ pending.command('enqueue').requiredOption('--input <json>', 'Validated change/attempt envelope with optional verification provenance').option('--json').action(async (options) => writeJson(await enqueuePending(resolveRulebookHome(), JSON.parse(await readFile(options.input, 'utf8')))));
21
+ pending.command('retry').argument('<id>').option('--environment <json>', 'Freshly inspected environment JSON; missing provenance requires review').option('--json').action(async (id, options) => {
22
+ const environment = options.environment ? McpResolutionsReportAttemptInputSchema.shape.environment.parse(JSON.parse(await readFile(options.environment, 'utf8'))) : undefined;
23
+ writeJson(await retryPending(resolveRulebookHome(), id, environment));
24
+ });
25
+ pending.command('discard').argument('<id>').option('--json').action(async (id) => writeJson(await discardPending(resolveRulebookHome(), id)));
26
+ }
27
+ //# sourceMappingURL=pending.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pending.js","sourceRoot":"","sources":["../../src/commands/pending.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,sCAAsC,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AACvG,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,UAAU,sBAAsB,CAAC,OAAgB;IACrD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,+DAA+D,CAAC,CAAC;IACxH,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QAChE,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,mBAAmB,EAAE,CAAC,CAAC;QACvD,IAAI,OAAO,CAAC,IAAI;YAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;aAChD,CAAC;YAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAAC,KAAK,MAAM,IAAI,IAAI,KAAK;gBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,MAAM,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,CAAC;IACxE,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,EAAU,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,cAAc,CAAC,mBAAmB,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACxJ,CAAC"}
@@ -1,29 +1,43 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { resolveRulebookHome } from '../core/index.js';
3
- import { McpResolutionsFindInputSchema } from '../mcp/schemas.js';
4
- import { handleResolutionsFind } from '../mcp/resolutions-find-tool.js';
5
- import { handleResolutionsGet } from '../mcp/resolutions-get-tool.js';
6
- import { handleResolutionsGetSource } from '../mcp/resolutions-get-source-tool.js';
3
+ import { callResolutionTool } from '../mcp/tool-call.js';
4
+ import { object, UsageObserver } from '../core/usage-observer.js';
7
5
  import { writeJson } from './output.js';
8
6
  export function registerResolutionCommand(program) {
9
7
  const resolution = program.command('resolution').description('Find and inspect Resolution Memory v3 solutions');
10
8
  resolution.command('find').requiredOption('--input <json>', 'JSON file containing a resolutions.find request').option('--json').action(async (options) => {
11
- const input = McpResolutionsFindInputSchema.parse(JSON.parse(await readFile(options.input, 'utf8')));
12
- emit(await handleResolutionsFind(input, { rulebookHome: resolveRulebookHome() }), options.json);
9
+ const home = resolveRulebookHome();
10
+ const observer = new UsageObserver(home, 'cli');
11
+ let input;
12
+ try {
13
+ input = JSON.parse(await readFile(options.input, 'utf8'));
14
+ }
15
+ catch (error) {
16
+ const call = observer.begin('resolutions.find', undefined);
17
+ observer.complete(call, { error: { code: -32700 } });
18
+ throw error;
19
+ }
20
+ emit(await observedCall(observer, 'resolutions.find', input), options.json);
13
21
  });
14
- resolution.command('get').argument('<solution-handle>').option('--json').action(async (solutionHandle, options) => {
15
- emit(await handleResolutionsGet({ solution_handle: solutionHandle }, { rulebookHome: resolveRulebookHome() }), options.json);
22
+ resolution.command('get').argument('<solution-handle>').option('--json').option('--usage-context <json>', 'Optional trace metadata JSON').action(async (solutionHandle, options) => {
23
+ emit(await observedCall(new UsageObserver(resolveRulebookHome(), 'cli'), 'resolutions.get', { solution_handle: solutionHandle, ...(options.usageContext ? { usage_context: JSON.parse(options.usageContext) } : {}) }), options.json);
16
24
  });
17
- resolution.command('get-source').argument('<solution-handle>').argument('<source-handle>').option('--json').action(async (solutionHandle, sourceHandle, options) => {
18
- emit(await handleResolutionsGetSource({ solution_handle: solutionHandle, source_handle: sourceHandle }, { rulebookHome: resolveRulebookHome() }), options.json);
25
+ resolution.command('get-source').argument('<solution-handle>').argument('<source-handle>').option('--json').option('--usage-context <json>', 'Optional trace metadata JSON').action(async (solutionHandle, sourceHandle, options) => {
26
+ emit(await observedCall(new UsageObserver(resolveRulebookHome(), 'cli'), 'resolutions.get_source', { solution_handle: solutionHandle, source_handle: sourceHandle, ...(options.usageContext ? { usage_context: JSON.parse(options.usageContext) } : {}) }), options.json);
19
27
  });
20
28
  return program;
21
29
  }
30
+ async function observedCall(observer, name, input) {
31
+ const call = observer.begin(name, input);
32
+ const result = await callResolutionTool(name, input, { rulebookHome: observer.home });
33
+ const usage = observer.complete(call, result);
34
+ return { ...result, _meta: { ...object(result._meta), ...(usage ? { usage } : {}) } };
35
+ }
22
36
  function emit(result, json) {
23
37
  const block = result.content[0];
24
38
  if (block?.type !== 'text')
25
39
  throw new Error('Resolution command expected JSON text output');
26
- const parsed = JSON.parse(block.text ?? '');
40
+ const parsed = { ...JSON.parse(block.text ?? ''), ...(result._meta ? { _meta: result._meta } : {}) };
27
41
  if (json === true)
28
42
  writeJson(parsed);
29
43
  else
@@ -1 +1 @@
1
- {"version":3,"file":"resolution.js","sourceRoot":"","sources":["../../src/commands/resolution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,mBAAmB,EAAE,M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AG,MAAM,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAChI,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAAC,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;AACvI,CAAC;AACD,SAAS,IAAI,CAAC,MAA4F,EAAE,IAAc;IACxH,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAChC,IAAI,KAAK,EAAE,IAAI,KAAK,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAC5F,MAAM,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACrG,IAAI,IAAI,KAAK,IAAI;QAAE,SAAS,CAAC,MAAM,CAAC,CAAC;;QAAM,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACjG,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Statistics } from '../core/statistics-types.js';
2
+ /** ASCII-only output is readable over SSH, dumb terminals and pipes; no ANSI in data. */
3
+ export declare function renderStatistics(data: Statistics, columns?: number): string;
@@ -0,0 +1,76 @@
1
+ /** ASCII-only output is readable over SSH, dumb terminals and pipes; no ANSI in data. */
2
+ export function renderStatistics(data, columns = 80) {
3
+ const width = Math.max(20, Math.min(160, Math.floor(columns) || 80));
4
+ const lines = [];
5
+ const line = (text = '') => lines.push(fit(text, width));
6
+ const metric = (label, value) => {
7
+ const text = `${label.padEnd(Math.min(26, Math.floor(width / 2)))} ${value ?? 'unknown'}`;
8
+ if (text.length <= width)
9
+ line(text);
10
+ else {
11
+ line(label);
12
+ line(` ${value ?? 'unknown'}`);
13
+ }
14
+ };
15
+ line('AGENT RULEBOOK / USAGE');
16
+ line(`${data.query.source}/${data.query.usage_kind} | ${data.query.timezone}`);
17
+ line(`From: ${data.query.applied_from ?? 'all recorded history'}`);
18
+ line(`To: ${data.query.applied_to} (exclusive)`);
19
+ if (data.query.project_key || data.query.language)
20
+ line(`Filter: ${data.query.project_key ?? 'all projects'} / ${data.query.language ?? 'all languages'}`);
21
+ line(`Coverage: ${data.coverage.status} | health: ${data.health.status}`);
22
+ line(`Recorded from: ${data.coverage.recorded_from ?? 'not recorded'}`);
23
+ line(`Pruned intervals: ${data.coverage.pruned_intervals.length}`);
24
+ line();
25
+ line('CURRENT KNOWLEDGE (unique IDs / revisions)');
26
+ metric('Problems', data.inventory.problems);
27
+ metric('Solutions / revisions', `${number(data.inventory.solutions)} / ${number(data.inventory.revisions)}`);
28
+ metric('Stored outcomes', data.inventory.outcomes);
29
+ metric('New IDs (live receipts)', data.growth.observed_new_solutions);
30
+ line();
31
+ line('SELECTED ACTIVITY');
32
+ metric('All calls / finds', `${number(data.activity.invocations)} / ${number(data.activity.find_calls)}`);
33
+ metric('Candidate hit rate', percent(data.activity.hit_rate));
34
+ metric('Input error rate', percent(data.activity.validation_error_rate));
35
+ metric('No results / exhausted', `${number(data.activity.no_results)} / ${number(data.activity.exhausted)}`);
36
+ metric('Interrupted / pending', `${number(data.activity.interrupted)} / ${number(data.activity.pending)}`);
37
+ metric('Storage success', percent(data.activity.storage_success_rate));
38
+ metric('Missing trace', percent(data.activity.trace_missing_rate));
39
+ metric('Recorded solve rate', percent(data.outcomes.solve_rate));
40
+ line('Solve: solved / (solved + failed + regressed)');
41
+ line(`Inapplicable: ${number(data.outcomes.counts?.inapplicable ?? null)}; inconclusive: ${number(data.outcomes.counts?.inconclusive ?? null)}`);
42
+ line('Unknown periods are not measured zero.');
43
+ line();
44
+ line('DAILY FINDS (* partial; ? unknown; last 10 days)');
45
+ const days = data.timeline.slice(-10);
46
+ const maximum = Math.max(1, ...days.map((d) => d.find_calls ?? 0));
47
+ for (const day of days) {
48
+ const prefix = `${day.date}${day.partial ? '*' : ' '} ${day.find_calls ?? '?'} `;
49
+ const bar = day.find_calls === null ? '?' : '#'.repeat(Math.round(day.find_calls / maximum * Math.max(1, width - prefix.length)));
50
+ line(prefix + bar);
51
+ }
52
+ for (const [title, items] of [['LANGUAGES', data.breakdowns.languages], ['PROJECTS (unknown retained)', data.breakdowns.projects]]) {
53
+ line();
54
+ line(title);
55
+ if (!items.length)
56
+ line('No observed rows');
57
+ for (const item of items.slice(0, 5))
58
+ metric(item.key, item.count);
59
+ }
60
+ line();
61
+ line(`REJECTED CALL CLUSTERS (${number(data.diagnostics.count)} calls)`);
62
+ for (const cluster of data.diagnostics.clusters.slice(0, 3)) {
63
+ line(`${cluster.count} x ${cluster.tool}`);
64
+ line(` ${cluster.issues[0]?.path ?? '?'}: ${cluster.issues[0]?.expected ?? '?'} <- ${cluster.issues[0]?.received ?? '?'}`);
65
+ }
66
+ line();
67
+ line(`Index: ${data.health.index}; pending: ${number(data.health.pending_count)}`);
68
+ line(`Import backlog: ${number(data.health.import_backlog)}; sync: ${data.health.sync.remote_state}`);
69
+ line(`Git ${data.health.sync.divergence}; remote ${data.health.sync.remote_check}`);
70
+ line('Full denominators, filters and evidence: stats --json');
71
+ return `${lines.join('\n')}\n`;
72
+ }
73
+ const number = (value) => value === null ? 'unknown' : String(value);
74
+ function percent(value) { return `${value.value === null ? 'unknown' : `${(value.value * 100).toFixed(1)}%`} (${number(value.numerator)}/${number(value.denominator)}, n=${number(value.sample_size)})`; }
75
+ function fit(value, width) { const safe = value.replace(/[^\x20-\x7e]/g, '?'); return safe.length <= width ? safe : `${safe.slice(0, width - 3)}...`; }
76
+ //# sourceMappingURL=stats-renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stats-renderer.js","sourceRoot":"","sources":["../../src/commands/stats-renderer.ts"],"names":[],"mappings":"AAEA,yFAAyF;AACzF,MAAM,UAAU,gBAAgB,CAAC,IAAgB,EAAE,OAAO,GAAG,EAAE;IAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACrE,MAAM,KAAK,GAAa,EAAE,CAAC;IAAC,MAAM,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACrF,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,KAA6B,EAAE,EAAE;QAC9D,MAAM,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,SAAS,EAAE,CAAC;QAC1F,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK;YAAE,IAAI,CAAC,IAAI,CAAC,CAAC;aAChC,CAAC;YAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAAC,IAAI,CAAC,KAAK,KAAK,IAAI,SAAS,EAAE,CAAC,CAAC;QAAC,CAAC;IACxD,CAAC,CAAC;IACF,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC/B,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,UA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C;AACjC,CAAC;AACD,MAAM,MAAM,GAAG,CAAC,KAAoB,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACpF,SAAS,OAAO,CAAC,KAAY,IAAI,OAAO,GAAG,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;AACjN,SAAS,GAAG,CAAC,KAAa,EAAE,KAAa,IAAI,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Command } from 'commander';
2
+ import { getStatistics } from '../core/statistics.js';
3
+ export declare function registerStatsCommand(program: Command): Command;
4
+ export declare function watchStatistics(read: () => ReturnType<typeof getStatistics>): Promise<void>;