agent-rulebook 0.2.1 → 0.3.1
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.
- package/README.md +69 -5
- package/dist/commands/dashboard.d.ts +7 -0
- package/dist/commands/dashboard.js +42 -0
- package/dist/commands/dashboard.js.map +1 -0
- package/dist/commands/diagnostics.d.ts +2 -0
- package/dist/commands/diagnostics.js +38 -0
- package/dist/commands/diagnostics.js.map +1 -0
- package/dist/commands/import.d.ts +2 -0
- package/dist/commands/import.js +34 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/pending.d.ts +2 -0
- package/dist/commands/pending.js +27 -0
- package/dist/commands/pending.js.map +1 -0
- package/dist/commands/resolution.js +25 -11
- package/dist/commands/resolution.js.map +1 -1
- package/dist/commands/stats-renderer.d.ts +3 -0
- package/dist/commands/stats-renderer.js +76 -0
- package/dist/commands/stats-renderer.js.map +1 -0
- package/dist/commands/stats.d.ts +4 -0
- package/dist/commands/stats.js +107 -0
- package/dist/commands/stats.js.map +1 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +17 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/sync.js +1 -1
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/usage.d.ts +2 -0
- package/dist/commands/usage.js +25 -0
- package/dist/commands/usage.js.map +1 -0
- package/dist/core/codex-call-parser.d.ts +10 -0
- package/dist/core/codex-call-parser.js +97 -0
- package/dist/core/codex-call-parser.js.map +1 -0
- package/dist/core/codex-usage-import.d.ts +24 -0
- package/dist/core/codex-usage-import.js +259 -0
- package/dist/core/codex-usage-import.js.map +1 -0
- package/dist/core/diagnostic-cluster.d.ts +37 -0
- package/dist/core/diagnostic-cluster.js +20 -0
- package/dist/core/diagnostic-cluster.js.map +1 -0
- package/dist/core/environment-normalization.d.ts +21 -0
- package/dist/core/environment-normalization.js +42 -0
- package/dist/core/environment-normalization.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/invocation-diagnostics.d.ts +40 -0
- package/dist/core/invocation-diagnostics.js +91 -0
- package/dist/core/invocation-diagnostics.js.map +1 -0
- package/dist/core/legacy-candidate.d.ts +159 -0
- package/dist/core/legacy-candidate.js +73 -0
- package/dist/core/legacy-candidate.js.map +1 -0
- package/dist/core/legacy-import-apply.d.ts +215 -0
- package/dist/core/legacy-import-apply.js +172 -0
- package/dist/core/legacy-import-apply.js.map +1 -0
- package/dist/core/legacy-import-manifest.d.ts +197 -0
- package/dist/core/legacy-import-manifest.js +63 -0
- package/dist/core/legacy-import-manifest.js.map +1 -0
- package/dist/core/legacy-scan.d.ts +71 -0
- package/dist/core/legacy-scan.js +99 -0
- package/dist/core/legacy-scan.js.map +1 -0
- package/dist/core/pending-replay.d.ts +4 -0
- package/dist/core/pending-replay.js +96 -0
- package/dist/core/pending-replay.js.map +1 -0
- package/dist/core/resolution-applicability.d.ts +1 -0
- package/dist/core/resolution-applicability.js +28 -11
- package/dist/core/resolution-applicability.js.map +1 -1
- package/dist/core/resolution-ranker.js +9 -2
- package/dist/core/resolution-ranker.js.map +1 -1
- package/dist/core/resolution-search-types.d.ts +9 -0
- package/dist/core/statistics-data.d.ts +98 -0
- package/dist/core/statistics-data.js +53 -0
- package/dist/core/statistics-data.js.map +1 -0
- package/dist/core/statistics-pages.d.ts +3 -0
- package/dist/core/statistics-pages.js +107 -0
- package/dist/core/statistics-pages.js.map +1 -0
- package/dist/core/statistics-query.d.ts +86 -0
- package/dist/core/statistics-query.js +51 -0
- package/dist/core/statistics-query.js.map +1 -0
- package/dist/core/statistics-types.d.ts +286 -0
- package/dist/core/statistics-types.js +2 -0
- package/dist/core/statistics-types.js.map +1 -0
- package/dist/core/statistics.d.ts +5 -0
- package/dist/core/statistics.js +101 -0
- package/dist/core/statistics.js.map +1 -0
- package/dist/core/sync-status.d.ts +53 -0
- package/dist/core/sync-status.js +85 -0
- package/dist/core/sync-status.js.map +1 -0
- package/dist/core/usage-context.d.ts +15 -0
- package/dist/core/usage-context.js +22 -0
- package/dist/core/usage-context.js.map +1 -0
- package/dist/core/usage-observer.d.ts +36 -0
- package/dist/core/usage-observer.js +112 -0
- package/dist/core/usage-observer.js.map +1 -0
- package/dist/core/usage-schema.d.ts +113 -0
- package/dist/core/usage-schema.js +33 -0
- package/dist/core/usage-schema.js.map +1 -0
- package/dist/dashboard/public/api.js +41 -0
- package/dist/dashboard/public/app.js +111 -0
- package/dist/dashboard/public/components/detail-panel.js +21 -0
- package/dist/dashboard/public/components/index.js +216 -0
- package/dist/dashboard/public/components/input-diff.js +15 -0
- package/dist/dashboard/public/diagnostic-detail.js +25 -0
- package/dist/dashboard/public/diagnostics.js +46 -0
- package/dist/dashboard/public/index.html +28 -0
- package/dist/dashboard/public/knowledge.js +57 -0
- package/dist/dashboard/public/overview.js +101 -0
- package/dist/dashboard/public/solution-detail.js +42 -0
- package/dist/dashboard/public/styles.css +205 -0
- package/dist/dashboard/server.d.ts +10 -0
- package/dist/dashboard/server.js +133 -0
- package/dist/dashboard/server.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/observed-transport.d.ts +20 -0
- package/dist/mcp/observed-transport.js +99 -0
- package/dist/mcp/observed-transport.js.map +1 -0
- package/dist/mcp/resolution-change.d.ts +1 -1
- package/dist/mcp/resolution-change.js +24 -9
- package/dist/mcp/resolution-change.js.map +1 -1
- package/dist/mcp/resolutions-commit-change-tool.d.ts +5 -0
- package/dist/mcp/resolutions-commit-change-tool.js +22 -4
- package/dist/mcp/resolutions-commit-change-tool.js.map +1 -1
- package/dist/mcp/resolutions-find-tool.d.ts +1 -2
- package/dist/mcp/resolutions-find-tool.js +43 -8
- package/dist/mcp/resolutions-find-tool.js.map +1 -1
- package/dist/mcp/resolutions-list-facets-tool.d.ts +1 -1
- package/dist/mcp/resolutions-list-facets-tool.js +16 -2
- package/dist/mcp/resolutions-list-facets-tool.js.map +1 -1
- package/dist/mcp/resolutions-report-attempt-tool.d.ts +1 -0
- package/dist/mcp/resolutions-report-attempt-tool.js +44 -55
- package/dist/mcp/resolutions-report-attempt-tool.js.map +1 -1
- package/dist/mcp/schemas.d.ts +299 -14
- package/dist/mcp/schemas.js +31 -10
- package/dist/mcp/schemas.js.map +1 -1
- package/dist/mcp/server.js +20 -5
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/stats-get-tool.d.ts +99 -0
- package/dist/mcp/stats-get-tool.js +17 -0
- package/dist/mcp/stats-get-tool.js.map +1 -0
- package/dist/mcp/tool-call.d.ts +99 -0
- package/dist/mcp/tool-call.js +20 -0
- package/dist/mcp/tool-call.js.map +1 -0
- package/dist/mcp/tool-output.d.ts +9 -0
- package/dist/mcp/tool-output.js +22 -0
- package/dist/mcp/tool-output.js.map +1 -1
- package/dist/mcp/tools.d.ts +182 -27
- package/dist/mcp/tools.js +10 -3
- package/dist/mcp/tools.js.map +1 -1
- package/dist/program.js +14 -0
- package/dist/program.js.map +1 -1
- package/dist/storage/canonical-write-lock.d.ts +2 -0
- package/dist/storage/canonical-write-lock.js +32 -0
- package/dist/storage/canonical-write-lock.js.map +1 -0
- package/dist/storage/diagnostic-store.d.ts +21 -0
- package/dist/storage/diagnostic-store.js +50 -0
- package/dist/storage/diagnostic-store.js.map +1 -0
- package/dist/storage/import-manifest.d.ts +6 -0
- package/dist/storage/import-manifest.js +41 -0
- package/dist/storage/import-manifest.js.map +1 -0
- package/dist/storage/pending-store.d.ts +329 -0
- package/dist/storage/pending-store.js +164 -0
- package/dist/storage/pending-store.js.map +1 -0
- package/dist/storage/resolution-candidate-service.js +2 -1
- package/dist/storage/resolution-candidate-service.js.map +1 -1
- package/dist/storage/resolution-change-transaction.d.ts +41 -3
- package/dist/storage/resolution-change-transaction.js +101 -12
- package/dist/storage/resolution-change-transaction.js.map +1 -1
- package/dist/storage/resolution-home.js +1 -1
- package/dist/storage/resolution-home.js.map +1 -1
- package/dist/storage/resolution-index-check.js +3 -2
- package/dist/storage/resolution-index-check.js.map +1 -1
- package/dist/storage/resolution-indexer.js +3 -1
- package/dist/storage/resolution-indexer.js.map +1 -1
- package/dist/storage/usage-store.d.ts +80 -0
- package/dist/storage/usage-store.js +239 -0
- package/dist/storage/usage-store.js.map +1 -0
- package/package.json +11 -4
package/README.md
CHANGED
|
@@ -6,13 +6,13 @@ 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.
|
|
10
|
-
npx -y agent-rulebook@0.
|
|
9
|
+
npx -y agent-rulebook@0.3.1 --help
|
|
10
|
+
npx -y agent-rulebook@0.3.1 mcp
|
|
11
11
|
agent-rulebook init
|
|
12
12
|
agent-rulebook index rebuild
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
`agent-rulebook@0.
|
|
15
|
+
`agent-rulebook@0.3.1` is an immutable package version. Registry tags such as `latest` are mutable and are not asserted by this artifact. Release receipts in `docs/releases/` record artifact and runtime verification separately. Historical version 0.3.0 passed full registry acceptance on macOS arm64 with Node 26.2.0; see `docs/releases/0.3.0.json`. Use the exact version for reproducible MCP configuration.
|
|
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
|
|
|
@@ -29,7 +29,7 @@ Reset removes only legacy `rules/` and the derived `index/`, then establishes th
|
|
|
29
29
|
|
|
30
30
|
## MCP tools
|
|
31
31
|
|
|
32
|
-
The stdio server exposes
|
|
32
|
+
The 0.3.x stdio server exposes eight client-neutral tools. Historical 0.2.1 has seven tools and does not include stats or the dashboard. The manifest profile is `usage-v1-eight-tools`:
|
|
33
33
|
|
|
34
34
|
- `resolutions.find`: search at the first unexpected problem using observations, hypotheses, and environment.
|
|
35
35
|
- `resolutions.get`: inspect one candidate's applicability, actions, safety, and verification.
|
|
@@ -38,6 +38,7 @@ The stdio server exposes exactly seven client-neutral tools:
|
|
|
38
38
|
- `resolutions.report_attempt`: append a verified, context-scoped attempt outcome.
|
|
39
39
|
- `resolutions.prepare_change`: classify and validate a verified canonical change without writing.
|
|
40
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.
|
|
41
42
|
|
|
42
43
|
Start the server with:
|
|
43
44
|
|
|
@@ -51,7 +52,29 @@ agent-rulebook mcp
|
|
|
51
52
|
2. Select one candidate and progressively call `resolutions.get`, then `resolutions.get_source` only when exact implementation evidence is needed.
|
|
52
53
|
3. Apply one candidate and run its verification. Report the result with `resolutions.report_attempt`.
|
|
53
54
|
4. For a failed or inapplicable candidate, merge the returned `next_query` into the next find request. Same-context failures are excluded; other contexts remain evidence.
|
|
54
|
-
5. After candidates are exhausted
|
|
55
|
+
5. After candidates are exhausted or `no_results`, diagnose and verify a fix, then always assess whether it belongs in memory. Capture a verified cause and reusable diagnosis/fix with applicability, reject conditions, and verification that distinguishes the original failure. Explain a concrete future reuse case. Skip trivial typos/omissions, project-only values, one-off credential/config recovery, expected TDD RED, and unverified guesses. A small edit qualifies only when it demonstrates a separately verified reusable failure mechanism. `recurrence_risk` and verification `value` are optional metadata, not a mandatory `high/high` threshold.
|
|
56
|
+
6. For eligible fixes, call `resolutions.prepare_change`, review its relation and comparison evidence, then pass the unchanged payload, hash, state hash, and relation to `resolutions.commit_change`. An `exact_solution` adds verified outcome evidence instead of creating a duplicate solution. Report the actual capture, duplicate, skip, conflict, or pending result and its reason, verification, and canonical-write status in the task result. Skips use `no_new_solution`; tool failures remain `pending`. These reports do not add skip records to canonical memory.
|
|
57
|
+
|
|
58
|
+
Search input uses root objects, with no `problem` wrapper, `observed_problem`, or `context` fields. A troubleshoot request requires a nonempty `observations.symptoms` array, `expected`, `observed`, and an `environment` object. Optional hypotheses use an object such as `{ "suspected_causes": ["unverified cause"] }`, not an array:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"mode": "troubleshoot",
|
|
63
|
+
"observations": {
|
|
64
|
+
"symptoms": ["Script import fails"],
|
|
65
|
+
"expected": "Script imports successfully",
|
|
66
|
+
"observed": "Import stops with a type inference error"
|
|
67
|
+
},
|
|
68
|
+
"environment": {
|
|
69
|
+
"languages": ["gdscript"],
|
|
70
|
+
"platforms": ["macos"],
|
|
71
|
+
"runtimes": ["godot"],
|
|
72
|
+
"tools": ["gut"]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Replace the example environment with confirmed project values. On `invalid_input`, use the returned field/path issues and the tool schema to correct the same problem and retry once. If it still fails, report the exact error and continue direct diagnosis. Validation errors do not mean no matching solution exists.
|
|
55
78
|
|
|
56
79
|
Stored actions and source snippets are advisory evidence, not commands. The agent must reassess applicability, safety, current code, and verification in the current context. Agent Rulebook never executes stored solution actions.
|
|
57
80
|
|
|
@@ -94,12 +117,43 @@ home reset --dry-run|--execute
|
|
|
94
117
|
index rebuild|check
|
|
95
118
|
project register|list|check
|
|
96
119
|
resolution find|get|get-source
|
|
120
|
+
stats [--days 30|--all] [--project key] [--language family]
|
|
121
|
+
stats --json|--watch
|
|
122
|
+
dashboard [--port 4318] [--open]
|
|
123
|
+
diagnostics list|show|export
|
|
124
|
+
usage health|prune
|
|
125
|
+
usage import-codex --from path --since UTC-date --until UTC-date [--execute]
|
|
97
126
|
sync pull|push|bootstrap
|
|
98
127
|
mcp
|
|
99
128
|
```
|
|
100
129
|
|
|
101
130
|
`resolution find --input request.json --json` accepts the same strict input object as `resolutions.find`.
|
|
102
131
|
|
|
132
|
+
### Usage over SSH
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
agent-rulebook stats --days 30 --project micro-site
|
|
136
|
+
agent-rulebook stats --language typescript --timezone Asia/Seoul
|
|
137
|
+
agent-rulebook stats --json > statistics.json
|
|
138
|
+
agent-rulebook stats --watch
|
|
139
|
+
NO_COLOR=1 TERM=dumb agent-rulebook stats
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
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.
|
|
143
|
+
|
|
144
|
+
### Local browser dashboard
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
agent-rulebook dashboard --port 4318
|
|
148
|
+
agent-rulebook dashboard --port 4318 --open
|
|
149
|
+
# On your computer, forward the remote dashboard's loopback port:
|
|
150
|
+
ssh -N -L 4318:127.0.0.1:4318 user@host
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
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.
|
|
154
|
+
|
|
155
|
+
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.
|
|
156
|
+
|
|
103
157
|
## Development
|
|
104
158
|
|
|
105
159
|
```bash
|
|
@@ -111,3 +165,13 @@ npm run check:package
|
|
|
111
165
|
```
|
|
112
166
|
|
|
113
167
|
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.
|
|
168
|
+
|
|
169
|
+
### Dashboard development and browser checks
|
|
170
|
+
|
|
171
|
+
`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.
|
|
172
|
+
|
|
173
|
+
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`.
|
|
174
|
+
|
|
175
|
+
### Prepare a release candidate
|
|
176
|
+
|
|
177
|
+
`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,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AAI,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7a,CAAC"}
|
|
@@ -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,CAA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,KAAK,EAAE,EAAU,EAAE,OAAO,EAAE,EAAE;QAC3L,MAAM,MAAM,GAAG,eAAe,CAAC,mBAAmB,EAAE,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC,aAAa,KAAK,EAAE,CAAC,CAAC;QACpH,IAAI,CAAC,MAAM,EAAE,CAAC;YAAC,SAAS,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;YAAC,OAAO;QAAC,CAAC;QAC5D,MAAM,OAAO,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAChD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YAAC,MAAM,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,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,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,mBAAmB,CAAC,CAAC,cAAc,CAAC,mBAAmB,EAAE,oEAAoE,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,kCAAkC,CAAC,CAAC,MAAM,CAAC,kBAAkB,EAAE,kDAAkD,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACpY,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,IAA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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
|
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,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 {
|
|
4
|
-
import {
|
|
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
|
|
12
|
-
|
|
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
|
|
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
|
|
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,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"resolution.js","sourceRoot":"","sources":["../../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CAAC,IAAI,CAAC,CAAC;AACjG,CAAC"}
|
|
@@ -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,E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AAa,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>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { resolveRulebookHome } from '../core/index.js';
|
|
2
|
+
import { getStatistics } from '../core/statistics.js';
|
|
3
|
+
import { StatisticsQuerySchema } from '../core/statistics-query.js';
|
|
4
|
+
import { writeJson } from './output.js';
|
|
5
|
+
import { renderStatistics } from './stats-renderer.js';
|
|
6
|
+
export function registerStatsCommand(program) {
|
|
7
|
+
const command = program.command('stats').description('Read usage tables and ASCII graphs; unknown coverage is not zero')
|
|
8
|
+
.option('--days <days>', 'Calendar days, 1..365 (default 30)')
|
|
9
|
+
.option('--all', 'All recorded history; conflicts with --days')
|
|
10
|
+
.option('--project <key>', 'Explicit project key or __unknown__')
|
|
11
|
+
.option('--language <language>', 'Normalized language family')
|
|
12
|
+
.option('--source <source>', 'live (default) or codex_history')
|
|
13
|
+
.option('--usage-kind <kind>', 'production (default) or test')
|
|
14
|
+
.option('--timezone <iana>', 'IANA timezone (default UTC)')
|
|
15
|
+
.option('--json', 'JSON only, suitable for pipes')
|
|
16
|
+
.option('--watch', 'Refresh every 2 seconds in a TTY; q or Ctrl+C to quit');
|
|
17
|
+
command.action(async (options) => {
|
|
18
|
+
const parsed = StatisticsQuerySchema.safeParse({ ...(options.days !== undefined ? { days: /^\d+$/.test(options.days) ? Number(options.days) : NaN } : {}), all: options.all, project_key: options.project, language: options.language, source: options.source, usage_kind: options.usageKind, timezone: options.timezone });
|
|
19
|
+
if (!parsed.success)
|
|
20
|
+
command.error('Invalid statistics filters. Use stats --help.', { code: 'stats.invalid_options' });
|
|
21
|
+
if (options.watch && (options.json || !process.stdout.isTTY || !process.stdin.isTTY))
|
|
22
|
+
command.error('--watch requires interactive stdin/stdout and cannot be combined with --json.', { code: 'stats.watch_requires_tty' });
|
|
23
|
+
const query = parsed.data;
|
|
24
|
+
const read = () => getStatistics(resolveRulebookHome(), query);
|
|
25
|
+
if (options.watch)
|
|
26
|
+
await watchStatistics(read);
|
|
27
|
+
else {
|
|
28
|
+
const data = await read();
|
|
29
|
+
if (options.json)
|
|
30
|
+
writeJson(data);
|
|
31
|
+
else
|
|
32
|
+
process.stdout.write(renderStatistics(data, process.stdout.columns));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return command;
|
|
36
|
+
}
|
|
37
|
+
export async function watchStatistics(read) {
|
|
38
|
+
const input = process.stdin;
|
|
39
|
+
const output = process.stdout;
|
|
40
|
+
const raw = input.isRaw;
|
|
41
|
+
const wasFlowing = input.readableFlowing === true;
|
|
42
|
+
const controls = process.env.TERM !== 'dumb' && process.env.NO_COLOR === undefined;
|
|
43
|
+
let stopped = false;
|
|
44
|
+
let timer;
|
|
45
|
+
let busy = false;
|
|
46
|
+
let finish;
|
|
47
|
+
const done = new Promise((resolve) => { finish = resolve; });
|
|
48
|
+
const stop = () => { if (!stopped) {
|
|
49
|
+
stopped = true;
|
|
50
|
+
if (timer)
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
finish();
|
|
53
|
+
} };
|
|
54
|
+
const key = (data) => { if (/[qQ\x03\x04]/.test(data.toString()))
|
|
55
|
+
stop(); };
|
|
56
|
+
const draw = async () => {
|
|
57
|
+
if (stopped || busy)
|
|
58
|
+
return;
|
|
59
|
+
busy = true;
|
|
60
|
+
try {
|
|
61
|
+
const data = await read();
|
|
62
|
+
if (!stopped)
|
|
63
|
+
output.write(`${controls ? '\x1b[H\x1b[2J' : ''}${renderStatistics(data, output.columns)}Watch: q / Ctrl+C to quit\n`);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
if (!stopped) {
|
|
67
|
+
process.stderr.write('Statistics unavailable; watch stopped.\n');
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
stop();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
busy = false;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const refresh = async () => { await draw(); if (!stopped)
|
|
77
|
+
timer = setTimeout(refresh, 2000); };
|
|
78
|
+
const resize = () => { void draw(); };
|
|
79
|
+
try {
|
|
80
|
+
process.on('SIGINT', stop);
|
|
81
|
+
process.on('SIGTERM', stop);
|
|
82
|
+
input.on('data', key);
|
|
83
|
+
output.on('resize', resize);
|
|
84
|
+
input.setRawMode(true);
|
|
85
|
+
input.resume();
|
|
86
|
+
if (controls)
|
|
87
|
+
output.write('\x1b[?25l');
|
|
88
|
+
void refresh();
|
|
89
|
+
await done;
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
stopped = true;
|
|
93
|
+
if (timer)
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
process.off('SIGINT', stop);
|
|
96
|
+
process.off('SIGTERM', stop);
|
|
97
|
+
input.off('data', key);
|
|
98
|
+
output.off('resize', resize);
|
|
99
|
+
input.setRawMode(raw);
|
|
100
|
+
if (!wasFlowing)
|
|
101
|
+
input.pause();
|
|
102
|
+
if (controls)
|
|
103
|
+
output.write('\x1b[?25h');
|
|
104
|
+
output.write('\n');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=stats.js.map
|