@letsrebase/verify 0.0.0-stage → 0.1.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/.claude/commands/rebase-verify.md +118 -0
- package/LICENSE +21 -0
- package/PRIVACY.md +113 -0
- package/README.md +210 -2
- package/SECURITY.md +33 -0
- package/bin/rebase-verify.mjs +700 -0
- package/package.json +38 -4
- package/share/practices.json +224 -0
- package/share/tech-labels.json +57 -0
- package/share/tech-lexicon.json +62 -0
- package/src/adapters/claude-code.mjs +225 -0
- package/src/adapters/codex.mjs +476 -0
- package/src/adapters/cursor.mjs +584 -0
- package/src/adapters/kimi.mjs +594 -0
- package/src/adapters/omp.mjs +59 -0
- package/src/adapters/opencode.mjs +439 -0
- package/src/adapters/pi.mjs +414 -0
- package/src/adapters/tool-vocab.mjs +15 -0
- package/src/agent-run.mjs +10 -0
- package/src/agentic-literacy.mjs +211 -0
- package/src/agents/acp.mjs +364 -0
- package/src/agents/json-answer.mjs +72 -0
- package/src/agents/registry.mjs +370 -0
- package/src/agents/run.mjs +131 -0
- package/src/ai-relationship.mjs +95 -0
- package/src/consistency.mjs +382 -0
- package/src/days.mjs +45 -0
- package/src/digest.mjs +501 -0
- package/src/distribution.mjs +54 -0
- package/src/enrich.mjs +118 -0
- package/src/fingerprint.mjs +134 -0
- package/src/forensics.mjs +178 -0
- package/src/groundedness.mjs +347 -0
- package/src/hub.mjs +136 -0
- package/src/intensity.mjs +132 -0
- package/src/live-status.mjs +79 -0
- package/src/practices-llm.mjs +90 -0
- package/src/practices-rules.mjs +295 -0
- package/src/practices-sample.mjs +111 -0
- package/src/practices.mjs +279 -0
- package/src/profile-llm.mjs +249 -0
- package/src/profile.mjs +497 -0
- package/src/redact.mjs +97 -0
- package/src/sources.mjs +91 -0
- package/src/submit.mjs +65 -0
- package/src/system-text.mjs +3 -0
- package/src/tech-usage.mjs +88 -0
- package/src/trajectory.mjs +264 -0
- package/src/wizard.mjs +411 -0
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// rebase-verify: turn your Claude Code logs into a tamper-evident, PII-redacted
|
|
3
|
+
// work profile (playnew-profile/v1).
|
|
4
|
+
//
|
|
5
|
+
// Sub-commands (default: generate, save locally, no submit):
|
|
6
|
+
//
|
|
7
|
+
// rebase-verify # = rebase-verify generate
|
|
8
|
+
// rebase-verify generate # build out/profile.md + out/candidate.json locally
|
|
9
|
+
// rebase-verify generate --agent <id> [--model <id>]
|
|
10
|
+
// # the same, the narrative written and the practices classified
|
|
11
|
+
// # by one of your coding agents (see src/agents/registry.mjs)
|
|
12
|
+
// rebase-verify prepare # only emit out/narrative-input.json (no narrative), plus
|
|
13
|
+
// # out/practices-input.json and out/practices-sample.json
|
|
14
|
+
// rebase-verify finalize # finalize using --narrative-file out/narrative.json
|
|
15
|
+
// rebase-verify submit # sign in in the browser, then send out/candidate.json to rebase
|
|
16
|
+
// rebase-verify --version | -v # print the package version and exit
|
|
17
|
+
//
|
|
18
|
+
// Everything generated lands in ./out, one folder to inspect, one to delete,
|
|
19
|
+
// one line of .gitignore. Nothing is written to the repo root.
|
|
20
|
+
//
|
|
21
|
+
// Common flags:
|
|
22
|
+
// --root <dir> # logs root (default ~/.claude/projects)
|
|
23
|
+
// --hub <url|preview> # rebase hub for submit (default https://letsrebase.com,
|
|
24
|
+
// # or REBASE_VERIFY_HUB_URL; "preview" = preview.letsrebase.com)
|
|
25
|
+
// --top 4 # force the number of representative projects
|
|
26
|
+
// # (default: adaptive, 3 to 5)
|
|
27
|
+
// --tz Europe/Rome # timezone for day and month counts (activeDays,
|
|
28
|
+
// # streak, technology-usage months). Default UTC;
|
|
29
|
+
// # recorded in the profile.
|
|
30
|
+
// --narrative-file narrative.json
|
|
31
|
+
//
|
|
32
|
+
// Four ways to provide the narrative step (the qualitative prose):
|
|
33
|
+
// A. Inside Claude Code via .claude/commands/rebase-verify.md, uses the
|
|
34
|
+
// candidate's own subscription, no API key needed.
|
|
35
|
+
// B. With the Claude API: set ANTHROPIC_API_KEY and run `generate`.
|
|
36
|
+
// C. Manually: `prepare` -> hand-write narrative.json -> `finalize`.
|
|
37
|
+
// D. With your coding agent over ACP: `generate --agent <id>`.
|
|
38
|
+
|
|
39
|
+
import { homedir } from "node:os";
|
|
40
|
+
import { join } from "node:path";
|
|
41
|
+
import { fileURLToPath } from "node:url";
|
|
42
|
+
import { writeFileSync, existsSync, readFileSync, mkdirSync, rmSync } from "node:fs";
|
|
43
|
+
import { readClaudeCode } from "../src/adapters/claude-code.mjs";
|
|
44
|
+
import { SOURCES, readSource, combineSources, readAllSources } from "../src/sources.mjs";
|
|
45
|
+
import { computeFingerprint } from "../src/fingerprint.mjs";
|
|
46
|
+
import { computeForensics } from "../src/forensics.mjs";
|
|
47
|
+
import { buildDigest } from "../src/digest.mjs";
|
|
48
|
+
import { practicesFiles } from "../src/practices-sample.mjs";
|
|
49
|
+
import { PRACTICES_WARN_WHAT, runPracticesStep } from "../src/practices-llm.mjs";
|
|
50
|
+
import { enrichRepo, describeContextGaps } from "../src/enrich.mjs";
|
|
51
|
+
import { MODEL, anthropicCall, generateNarrative, narrativeInputFor, warnApiKey } from "../src/profile-llm.mjs";
|
|
52
|
+
import { selectRepresentatives, assembleProfile, renderMarkdown, summarizeSources } from "../src/profile.mjs";
|
|
53
|
+
import { resolveHub } from "../src/hub.mjs";
|
|
54
|
+
import { submitProfile, buildPayload } from "../src/submit.mjs";
|
|
55
|
+
import { buildTrajectory } from "../src/trajectory.mjs";
|
|
56
|
+
import { assessGroundedness } from "../src/groundedness.mjs";
|
|
57
|
+
import { assessStructure, assessAgainstLogs, submitBlockers } from "../src/consistency.mjs";
|
|
58
|
+
import { computeAiRelationship } from "../src/ai-relationship.mjs";
|
|
59
|
+
import { computeAgenticLiteracy } from "../src/agentic-literacy.mjs";
|
|
60
|
+
import { computeIntensity } from "../src/intensity.mjs";
|
|
61
|
+
import { computeDistribution } from "../src/distribution.mjs";
|
|
62
|
+
import { computeTechUsage, recordedTechUsageTz } from "../src/tech-usage.mjs";
|
|
63
|
+
import { computeCodePractices, mergeModelPractices, practicesBlock, recordedPracticesTz } from "../src/practices.mjs";
|
|
64
|
+
import { DEFAULT_TZ } from "../src/days.mjs";
|
|
65
|
+
|
|
66
|
+
// Friendly Node floor (package.json `engines` is advisory only when invoked
|
|
67
|
+
// as `node bin/rebase-verify.mjs`). Imports hoist and evaluate before this line
|
|
68
|
+
// runs, so the check only protects us while src/ stays free of import-time
|
|
69
|
+
// Node-20-only syntax and builtins, true today: fetch / FormData /
|
|
70
|
+
// structuredClone all live inside function bodies, and everything parses as
|
|
71
|
+
// ES2022. Without this, old Node dies later with a bare ReferenceError.
|
|
72
|
+
const [nodeMajor, nodeMinor] = process.versions.node.split(".").map(Number);
|
|
73
|
+
if (nodeMajor < 20 || (nodeMajor === 20 && nodeMinor < 12)) {
|
|
74
|
+
console.error(`rebase-verify needs Node 20.12 or newer; you're running ${process.version}.`);
|
|
75
|
+
console.error(`Install a current Node from https://nodejs.org (or: nvm install 20).`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (process.argv[2] === "--version" || process.argv[2] === "-v") {
|
|
80
|
+
const pkgUrl = new URL("../package.json", import.meta.url);
|
|
81
|
+
console.log(JSON.parse(readFileSync(fileURLToPath(pkgUrl), "utf8")).version);
|
|
82
|
+
process.exit(0);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const SUB_COMMANDS = new Set(["generate", "prepare", "finalize", "submit"]);
|
|
86
|
+
|
|
87
|
+
const argv = process.argv.slice(2);
|
|
88
|
+
const sub = argv[0] && !argv[0].startsWith("--") ? argv[0] : "generate";
|
|
89
|
+
if (!SUB_COMMANDS.has(sub)) {
|
|
90
|
+
console.error(`Unknown command: ${sub}. Expected: ${[...SUB_COMMANDS].join(" | ")}`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
const flag = (n, d = null) => {
|
|
94
|
+
const i = argv.indexOf(`--${n}`);
|
|
95
|
+
return i >= 0 && argv[i + 1] && !argv[i + 1].startsWith("--") ? argv[i + 1] : d;
|
|
96
|
+
};
|
|
97
|
+
const has = (n) => argv.includes(`--${n}`);
|
|
98
|
+
|
|
99
|
+
// The `sources` shape readAllSources() expects, read from CLI flags. Called
|
|
100
|
+
// from TWO places (loadProfileInputs and the submit command) that must never
|
|
101
|
+
// drift: submit re-derives ground truth from the SAME source mix the profile
|
|
102
|
+
// was generated from, otherwise a merged profile (claude-code + opencode + codex + pi + omp + cursor + kimi)
|
|
103
|
+
// trips the tamper signal because volume.sessions > re-derived sessions.
|
|
104
|
+
function sourceFlags() {
|
|
105
|
+
return {
|
|
106
|
+
opencode: { root: flag("opencode-root"), disabled: has("no-opencode"), json: has("opencode-json") },
|
|
107
|
+
codex: { root: flag("codex-root"), disabled: has("no-codex") },
|
|
108
|
+
pi: { root: flag("pi-root"), disabled: has("no-pi") },
|
|
109
|
+
omp: { root: flag("omp-root"), disabled: has("no-omp") },
|
|
110
|
+
cursor: { root: flag("cursor-root"), disabled: has("no-cursor") },
|
|
111
|
+
kimi: { root: flag("kimi-root"), disabled: has("no-kimi") },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Validate --tz up front, before reading any logs, an unknown zone should fail
|
|
116
|
+
// fast, not throw mid-pipeline from inside Intl.DateTimeFormat.
|
|
117
|
+
const tzFlag = flag("tz", DEFAULT_TZ);
|
|
118
|
+
try {
|
|
119
|
+
new Intl.DateTimeFormat("en-CA", { timeZone: tzFlag }).format(0);
|
|
120
|
+
} catch {
|
|
121
|
+
console.error(`Invalid --tz "${tzFlag}". Expected an IANA timezone, e.g. UTC or Europe/Rome.`);
|
|
122
|
+
process.exit(2);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Every generated file (narrative-input.json, narrative.json, practices-input.json,
|
|
126
|
+
// practices-sample.json, practices.json, practices-detail.json, agent-log.jsonl,
|
|
127
|
+
// candidate.json, profile.md) lands in ./out, never in the repo root.
|
|
128
|
+
const OUT_DIR = "out";
|
|
129
|
+
const outPath = () => join(process.cwd(), OUT_DIR);
|
|
130
|
+
// Created only once logs were found. A `*` .gitignore inside keeps every file in it out of a commit.
|
|
131
|
+
const ensureOut = () => {
|
|
132
|
+
const out = outPath();
|
|
133
|
+
mkdirSync(out, { recursive: true });
|
|
134
|
+
const ignore = join(out, ".gitignore");
|
|
135
|
+
if (!existsSync(ignore)) writeFileSync(ignore, "*\n");
|
|
136
|
+
return out;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// The wizard, the agent runner and their dependencies load only where they are used, so the
|
|
140
|
+
// sub-commands work in a clone that never ran npm ci.
|
|
141
|
+
async function loadOptional(load) {
|
|
142
|
+
try {
|
|
143
|
+
return await load();
|
|
144
|
+
} catch (e) {
|
|
145
|
+
if (e?.code === "ERR_MODULE_NOT_FOUND" && /@clack\/prompts|@agentclientprotocol/.test(e.message)) {
|
|
146
|
+
die("Run it with npx @letsrebase/verify, or run npm ci in this folder first.");
|
|
147
|
+
}
|
|
148
|
+
throw e;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const loadAgents = () =>
|
|
152
|
+
loadOptional(async () => ({
|
|
153
|
+
registry: await import("../src/agents/registry.mjs"),
|
|
154
|
+
acp: await import("../src/agents/acp.mjs"),
|
|
155
|
+
run: await import("../src/agents/run.mjs"),
|
|
156
|
+
}));
|
|
157
|
+
|
|
158
|
+
// Who wrote what, as the profile records it. The slash command (and a hand-written
|
|
159
|
+
// narrative) reaches `finalize` through files, so its model is not known.
|
|
160
|
+
const SLASH_COMMAND = { agent: "slash-command", model: null };
|
|
161
|
+
const API_KEY_PATH = { agent: "anthropic-api", model: MODEL };
|
|
162
|
+
|
|
163
|
+
const die = (msg, code = 2) => {
|
|
164
|
+
console.error(msg);
|
|
165
|
+
process.exit(code);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// The wizard owns the terminal while it runs: the pipeline's progress lines stay quiet then.
|
|
169
|
+
let QUIET = false;
|
|
170
|
+
const say = (...a) => { if (!QUIET) console.log(...a); };
|
|
171
|
+
const warn = (...a) => { if (!QUIET) console.error(...a); };
|
|
172
|
+
|
|
173
|
+
// The agent behind `generate --agent <id>`, checked before any log is read.
|
|
174
|
+
async function resolveAgent() {
|
|
175
|
+
if (!has("agent")) {
|
|
176
|
+
if (has("model")) die("--model needs --agent <id>.");
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const { AGENTS } = (await loadAgents()).registry;
|
|
180
|
+
const ids = AGENTS.map((a) => a.id).join(", ");
|
|
181
|
+
const id = flag("agent");
|
|
182
|
+
if (!id) die(`--agent needs an id. Agents: ${ids}`);
|
|
183
|
+
const entry = AGENTS.find((a) => a.id === id);
|
|
184
|
+
if (!entry) die(`Unknown agent "${id}". Agents: ${ids}`);
|
|
185
|
+
if (!entry.detect({ env: process.env }).installed) {
|
|
186
|
+
die(entry.kind === "api" ? `${entry.label} is not set up: ${entry.installHint}.` : `${entry.label} is not installed: ${entry.installHint}.`);
|
|
187
|
+
}
|
|
188
|
+
if (flag("narrative-file")) die("--agent writes the narrative itself; drop --narrative-file.");
|
|
189
|
+
if (has("model") && !flag("model")) die("--model needs a model id.");
|
|
190
|
+
return entry;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// One agent run for both steps. Ctrl-C or SIGTERM aborts it (the agent runs in
|
|
194
|
+
// its own process group, so the terminal's signal does not reach it); the run
|
|
195
|
+
// removes its temp dir and transcript before the abort comes back.
|
|
196
|
+
async function runAgentStep(entry, { out, narrativeInput }) {
|
|
197
|
+
const { acp, run } = await loadAgents();
|
|
198
|
+
const { AgentAuthError, AgentStartError, ModelNotOfferedError, ToolUseError } = acp;
|
|
199
|
+
const { runWithAgent } = run;
|
|
200
|
+
const inputFile = join(out, "practices-input.json");
|
|
201
|
+
const practicesInput = existsSync(inputFile) ? JSON.parse(readFileSync(inputFile, "utf8")) : null;
|
|
202
|
+
const model = flag("model");
|
|
203
|
+
console.log(`[4/5] Narrative${practicesInput ? " and practices" : ""} with ${entry.label}${model ? ` (${model})` : ""} ...`);
|
|
204
|
+
const ctl = new AbortController();
|
|
205
|
+
const stop = () => ctl.abort();
|
|
206
|
+
process.once("SIGINT", stop);
|
|
207
|
+
process.once("SIGTERM", stop);
|
|
208
|
+
process.once("SIGHUP", stop);
|
|
209
|
+
try {
|
|
210
|
+
return await runWithAgent({
|
|
211
|
+
agent: entry,
|
|
212
|
+
model,
|
|
213
|
+
narrativeInput,
|
|
214
|
+
practicesInput,
|
|
215
|
+
logFile: join(out, "agent-log.jsonl"),
|
|
216
|
+
signal: ctl.signal,
|
|
217
|
+
onStatus: (s) =>
|
|
218
|
+
console.log(s.step === "narrative" ? " writing the narrative ..." : ` classifying practices, batch ${s.batch} of ${s.total}${s.retry ? " (again)" : ""} ...`),
|
|
219
|
+
});
|
|
220
|
+
} catch (e) {
|
|
221
|
+
if (e?.name === "AbortError") die("Stopped.", 130);
|
|
222
|
+
if (e instanceof AgentAuthError) die(`${entry.label} is not logged in: ${entry.loginHint}.`);
|
|
223
|
+
if (e instanceof ToolUseError) die("The agent tried to use a tool; nothing it wrote was kept.");
|
|
224
|
+
if (e instanceof ModelNotOfferedError) die(`${entry.label} does not offer model "${model}"${e.offered?.length ? `. It offers: ${e.offered.join(", ")}` : ""}.`);
|
|
225
|
+
if (e instanceof AgentStartError) die(`${e.message}.`);
|
|
226
|
+
return die(`${e.message}`);
|
|
227
|
+
} finally {
|
|
228
|
+
process.off("SIGINT", stop);
|
|
229
|
+
process.off("SIGTERM", stop);
|
|
230
|
+
process.off("SIGHUP", stop);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function logsRoot() {
|
|
235
|
+
let root = flag("root", join(homedir(), ".claude", "projects"));
|
|
236
|
+
if (flag("project")) root = join(root, flag("project"));
|
|
237
|
+
return root;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async function loadProfileInputs() {
|
|
241
|
+
const root = logsRoot();
|
|
242
|
+
if (!existsSync(root)) { console.error(`No logs at ${root}.`); process.exit(1); }
|
|
243
|
+
|
|
244
|
+
say(`[1/5] Reading ${root} ...`);
|
|
245
|
+
// Sources: claude-code is always read; opencode is folded in unless
|
|
246
|
+
// --no-opencode says otherwise. --opencode-json forces the JSON backend
|
|
247
|
+
// over the default sqlite (more complete but slower on huge logs).
|
|
248
|
+
const parsed = readAllSources({ claudeRoot: root, sources: sourceFlags() });
|
|
249
|
+
say(` claude-code: ${parsed.sessions.filter(s => s.source === "claude-code").length} sessions`);
|
|
250
|
+
const oc = parsed.sessions.filter(s => s.source === "opencode");
|
|
251
|
+
if (oc.length) {
|
|
252
|
+
// Surface WHICH backend read opencode: the sqlite db is far more complete
|
|
253
|
+
// than the JSON cache, so a silent fallback to JSON is a coverage drop the
|
|
254
|
+
// user should see, not discover later.
|
|
255
|
+
const backend = parsed.backends?.opencode;
|
|
256
|
+
say(` opencode${backend ? ` (${backend})` : ""}: ${oc.length} sessions`);
|
|
257
|
+
}
|
|
258
|
+
const cx = parsed.sessions.filter(s => s.source === "codex");
|
|
259
|
+
if (cx.length) say(` codex: ${cx.length} sessions`);
|
|
260
|
+
const pi = parsed.sessions.filter(s => s.source === "pi");
|
|
261
|
+
if (pi.length) say(` pi: ${pi.length} sessions`);
|
|
262
|
+
const om = parsed.sessions.filter(s => s.source === "omp");
|
|
263
|
+
if (om.length) say(` omp: ${om.length} sessions`);
|
|
264
|
+
const cu = parsed.sessions.filter(s => s.source === "cursor");
|
|
265
|
+
if (cu.length) say(` cursor: ${cu.length} sessions`);
|
|
266
|
+
const ki = parsed.sessions.filter(s => s.source === "kimi");
|
|
267
|
+
if (ki.length) say(` kimi: ${ki.length} sessions`);
|
|
268
|
+
return deriveInputs(parsed, ensureOut());
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Everything computed from the parsed logs; the wizard passes the sources the person chose.
|
|
272
|
+
function deriveInputs(parsed, out) {
|
|
273
|
+
// Timezone the day-based counts (activeDays, streak) are bucketed in. Default
|
|
274
|
+
// UTC (machine-independent); recorded in the profile so the count reproduces.
|
|
275
|
+
// Validated at startup (tzFlag) before any logs are read.
|
|
276
|
+
const tz = tzFlag;
|
|
277
|
+
|
|
278
|
+
say(`[2/5] Fingerprint, manifest, consistency ...`);
|
|
279
|
+
const fingerprint = computeFingerprint(parsed, { tz });
|
|
280
|
+
const forensics = computeForensics(parsed);
|
|
281
|
+
|
|
282
|
+
say(`[3/5] Deep digest + per-repo clustering (PII redacted: ${parsed.redaction.hits}) ...`);
|
|
283
|
+
const digest = buildDigest(parsed, { tz });
|
|
284
|
+
const projects = selectRepresentatives(digest.projects, flag("top") ? +flag("top") : "auto");
|
|
285
|
+
const selected = projects.filter((p) => p.selected);
|
|
286
|
+
say(` ${digest.projectCount} products, ${selected.length}${flag("top") ? "" : " (adaptive 3-5)"} representative: ${selected.map((p) => `${p.repo}[${p.type[0]}]`).join(", ")}`);
|
|
287
|
+
|
|
288
|
+
const enrichments = selected.map((p) => enrichRepo(p.cwdRaw));
|
|
289
|
+
const contextGap = describeContextGaps(enrichments);
|
|
290
|
+
if (contextGap) warn(` note: ${contextGap}`);
|
|
291
|
+
const trajectory = buildTrajectory(parsed);
|
|
292
|
+
const aiRelationship = computeAiRelationship(parsed);
|
|
293
|
+
const agenticLiteracy = computeAgenticLiteracy(parsed);
|
|
294
|
+
const intensity = computeIntensity(parsed, { tz });
|
|
295
|
+
const distribution = computeDistribution(projects);
|
|
296
|
+
const techUsage = computeTechUsage(projects, { tz });
|
|
297
|
+
const practices = practicesBlock(computeCodePractices(parsed, { tz })?.items, { tz });
|
|
298
|
+
const sources = summarizeSources(parsed);
|
|
299
|
+
return { parsed, fingerprint, forensics, projects, selected, enrichments, trajectory, aiRelationship, agenticLiteracy, intensity, distribution, techUsage, practices, sources, out };
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function writeProfile(out, profile, { print = true } = {}) {
|
|
303
|
+
writeFileSync(join(out, "candidate.json"), JSON.stringify(profile, null, 2));
|
|
304
|
+
const md = renderMarkdown(profile);
|
|
305
|
+
writeFileSync(join(out, "profile.md"), md);
|
|
306
|
+
if (!print) return;
|
|
307
|
+
console.log(md);
|
|
308
|
+
console.log(`Saved: ${OUT_DIR}/candidate.json + ${OUT_DIR}/profile.md`);
|
|
309
|
+
console.log(`To send it to rebase when ready: rebase-verify submit`);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// What the agent run adds to the profile: the answers merged into the practices block, who
|
|
313
|
+
// wrote the narrative. The answers stay in practices-detail.json, so a later finalize never
|
|
314
|
+
// reads them as the slash command's.
|
|
315
|
+
function applyAgentRun(out, codePractices, run) {
|
|
316
|
+
if (run.practicesAnswers) writeFileSync(join(out, "practices.json"), JSON.stringify(run.practicesAnswers, null, 2));
|
|
317
|
+
const practices = run.practicesAnswers ? mergePracticesAnswers(out, codePractices, run.used) : codePractices;
|
|
318
|
+
rmSync(join(out, "practices.json"), { force: true });
|
|
319
|
+
return { practices, narrative: run.narrative, generatedBy: { narrative: run.used } };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const narrativeOptionsOf = (i) => ({
|
|
323
|
+
trajectory: i.trajectory,
|
|
324
|
+
aiRelationship: i.aiRelationship,
|
|
325
|
+
agenticLiteracy: i.agenticLiteracy,
|
|
326
|
+
intensity: i.intensity,
|
|
327
|
+
distribution: i.distribution,
|
|
328
|
+
allProjects: i.projects,
|
|
329
|
+
compactionSummaries: i.parsed.compactionSummaries,
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// The model-classified practices: written only when some are published and
|
|
333
|
+
// there is something to read. Both files stay local; the sample file maps the
|
|
334
|
+
// opaque ids back to real sessions and is never sent.
|
|
335
|
+
function writePracticesInput(out, parsed, tz) {
|
|
336
|
+
// A stale sample from an earlier run must never be read by finalize.
|
|
337
|
+
for (const f of ["practices-input.json", "practices-sample.json", "practices-detail.json", "practices.json"]) rmSync(join(out, f), { force: true });
|
|
338
|
+
const shared = JSON.parse(readFileSync(new URL("../share/practices.json", import.meta.url), "utf8"));
|
|
339
|
+
const practices = (shared.practices ?? []).filter((p) => p.method === "model");
|
|
340
|
+
const files = practicesFiles(parsed, { tz, practices });
|
|
341
|
+
if (!files) return;
|
|
342
|
+
writeFileSync(join(out, "practices-input.json"), JSON.stringify(files.input, null, 2));
|
|
343
|
+
writeFileSync(join(out, "practices-sample.json"), JSON.stringify(files.sample, null, 2));
|
|
344
|
+
say(`Wrote ${OUT_DIR}/practices-input.json (${files.sample.length} sessions of your own messages, for your model to classify) and ${OUT_DIR}/practices-sample.json (local only).`);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async function cmdGenerate() {
|
|
348
|
+
const entry = await resolveAgent();
|
|
349
|
+
console.log(`\nrebase-verify generate\n`);
|
|
350
|
+
const { parsed, fingerprint, forensics, projects, selected, enrichments, trajectory, aiRelationship, agenticLiteracy, intensity, distribution, techUsage, practices: codePractices, sources, out } = await loadProfileInputs();
|
|
351
|
+
if (entry) rmSync(join(out, "agent-log.jsonl"), { force: true });
|
|
352
|
+
writePracticesInput(out, parsed, tzFlag);
|
|
353
|
+
const narrativeOptions = {
|
|
354
|
+
trajectory,
|
|
355
|
+
aiRelationship,
|
|
356
|
+
agenticLiteracy,
|
|
357
|
+
intensity,
|
|
358
|
+
distribution,
|
|
359
|
+
allProjects: projects,
|
|
360
|
+
compactionSummaries: parsed.compactionSummaries,
|
|
361
|
+
};
|
|
362
|
+
let practices;
|
|
363
|
+
let narrative;
|
|
364
|
+
let generatedBy;
|
|
365
|
+
if (entry) {
|
|
366
|
+
// Nothing is written until the agent has answered both steps and every answer checked out.
|
|
367
|
+
const run = await runAgentStep(entry, { out, narrativeInput: narrativeInputFor(selected, enrichments, narrativeOptions) });
|
|
368
|
+
({ practices, narrative, generatedBy } = applyAgentRun(out, codePractices, run));
|
|
369
|
+
} else {
|
|
370
|
+
const key = process.env.ANTHROPIC_API_KEY;
|
|
371
|
+
const step = await runPracticesStep(out, {
|
|
372
|
+
key, call: key ? anthropicCall(key) : null,
|
|
373
|
+
warn: () => warnApiKey(PRACTICES_WARN_WHAT),
|
|
374
|
+
});
|
|
375
|
+
practices = step === "written" ? mergePracticesAnswers(out, codePractices, API_KEY_PATH) : codePractices;
|
|
376
|
+
if (step === "written") rmSync(join(out, "practices.json"), { force: true });
|
|
377
|
+
|
|
378
|
+
console.log(`[4/5] Narrative ...`);
|
|
379
|
+
const generated = await generateNarrative(selected, enrichments, { overrideFile: flag("narrative-file"), ...narrativeOptions });
|
|
380
|
+
narrative = generated.narrative;
|
|
381
|
+
if (!narrative) {
|
|
382
|
+
writeFileSync(join(out, "narrative-input.json"), JSON.stringify(generated.input, null, 2));
|
|
383
|
+
console.log(` no narrative yet (no API key, no --narrative-file).`);
|
|
384
|
+
console.log(` From a clone, inside Claude Code: /rebase-verify (writes ${OUT_DIR}/narrative.json and finalizes)`);
|
|
385
|
+
console.log(` Manual: write ${OUT_DIR}/narrative.json, then rebase-verify finalize`);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (generated.source === "api") generatedBy = { narrative: API_KEY_PATH };
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
console.log(`[5/5] Assembling and saving ...\n`);
|
|
392
|
+
writeProfile(out, assembleWithGroundedness({
|
|
393
|
+
projects, narrative, fingerprint, forensics, trajectory, aiRelationship, agenticLiteracy, intensity, distribution, techUsage, practices, sources, generatedBy,
|
|
394
|
+
manifestHash: fingerprint.manifest.bundleHash,
|
|
395
|
+
}));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Assemble + compute groundedness on the assembled draft + re-assemble with
|
|
399
|
+
// the score embedded. Centralised so generate and finalize share it.
|
|
400
|
+
function assembleWithGroundedness(args) {
|
|
401
|
+
// The raw vocabularyCandidates never enter the profile (they can carry
|
|
402
|
+
// client names), so a narrative that omitted its filtered pick leaves
|
|
403
|
+
// newVocabulary empty. Say so instead of failing silently.
|
|
404
|
+
if (args.narrative && args.trajectory?.vocabularyCandidates?.length && !args.narrative.trajectory?.vocabulary_adopted?.length) {
|
|
405
|
+
warn(` note: the narrative has no trajectory.vocabulary_adopted, newVocabulary stays empty (raw candidates are never used; re-run the narrative step to fill it)`);
|
|
406
|
+
}
|
|
407
|
+
const draft = assembleProfile(args);
|
|
408
|
+
const groundedness = assessGroundedness(draft);
|
|
409
|
+
return assembleProfile({ ...args, groundedness });
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
async function cmdPrepare() {
|
|
413
|
+
console.log(`\nrebase-verify prepare\n`);
|
|
414
|
+
const { parsed, projects, selected, enrichments, trajectory, aiRelationship, agenticLiteracy, intensity, distribution, out } = await loadProfileInputs();
|
|
415
|
+
writePracticesInput(out, parsed, tzFlag);
|
|
416
|
+
const input = narrativeInputFor(selected, enrichments, {
|
|
417
|
+
trajectory,
|
|
418
|
+
aiRelationship,
|
|
419
|
+
agenticLiteracy,
|
|
420
|
+
intensity,
|
|
421
|
+
distribution,
|
|
422
|
+
allProjects: projects,
|
|
423
|
+
compactionSummaries: parsed.compactionSummaries,
|
|
424
|
+
});
|
|
425
|
+
writeFileSync(join(out, "narrative-input.json"), JSON.stringify(input, null, 2));
|
|
426
|
+
console.log(`Wrote ${OUT_DIR}/narrative-input.json.`);
|
|
427
|
+
console.log(`Next: write ${OUT_DIR}/narrative.json (rules in the slash command), then rebase-verify finalize`);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// The model's answers, when the person's model wrote out/practices.json: checked
|
|
431
|
+
// against the sample file written at prepare (never resampled), then merged into
|
|
432
|
+
// the block, with who classified them. A bad or unreadable file stops the step;
|
|
433
|
+
// nothing is saved.
|
|
434
|
+
function mergePracticesAnswers(out, codeBlock, classifiedBy) {
|
|
435
|
+
const answersFile = join(out, "practices.json");
|
|
436
|
+
if (!existsSync(answersFile)) return codeBlock;
|
|
437
|
+
const sampleFile = join(out, "practices-sample.json");
|
|
438
|
+
const fail = (msg) => { console.error(`${msg} Fix it, or delete ${OUT_DIR}/practices.json to leave the model practices out.`); process.exit(2); };
|
|
439
|
+
const read = (file) => { try { return JSON.parse(readFileSync(file, "utf8")); } catch { return undefined; } };
|
|
440
|
+
const sample = read(sampleFile);
|
|
441
|
+
if (!Array.isArray(sample)) fail(`Missing or unreadable ${sampleFile}: run rebase-verify prepare again.`);
|
|
442
|
+
const answers = read(answersFile);
|
|
443
|
+
if (answers === undefined) fail(`${answersFile} is not valid JSON.`);
|
|
444
|
+
const shared = JSON.parse(readFileSync(new URL("../share/practices.json", import.meta.url), "utf8"));
|
|
445
|
+
const ids = (shared.practices ?? []).filter((p) => p.method === "model").map((p) => p.id);
|
|
446
|
+
try {
|
|
447
|
+
const { block, detail } = mergeModelPractices(codeBlock, answers, sample, ids, { tz: tzFlag, classifiedBy });
|
|
448
|
+
writeFileSync(join(out, "practices-detail.json"), JSON.stringify(detail, null, 2));
|
|
449
|
+
say(`Merged the model's answers for ${sample.length} sessions (per-session detail in ${OUT_DIR}/practices-detail.json, local only).`);
|
|
450
|
+
return block;
|
|
451
|
+
} catch (e) {
|
|
452
|
+
return fail(`${answersFile}: ${e.message}.`);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
async function cmdFinalize() {
|
|
457
|
+
console.log(`\nrebase-verify finalize\n`);
|
|
458
|
+
const narrativeFile = flag("narrative-file", join(outPath(), "narrative.json"));
|
|
459
|
+
if (!existsSync(narrativeFile)) {
|
|
460
|
+
console.error(`Missing ${narrativeFile}. Run rebase-verify prepare first, then write ${OUT_DIR}/narrative.json.`);
|
|
461
|
+
process.exit(2);
|
|
462
|
+
}
|
|
463
|
+
const { parsed, fingerprint, forensics, projects, selected, enrichments, trajectory, aiRelationship, agenticLiteracy, intensity, distribution, techUsage, practices, sources, out } = await loadProfileInputs();
|
|
464
|
+
const merged = mergePracticesAnswers(out, practices, SLASH_COMMAND);
|
|
465
|
+
const { narrative } = await generateNarrative(selected, enrichments, {
|
|
466
|
+
overrideFile: narrativeFile,
|
|
467
|
+
trajectory,
|
|
468
|
+
aiRelationship,
|
|
469
|
+
agenticLiteracy,
|
|
470
|
+
intensity,
|
|
471
|
+
distribution,
|
|
472
|
+
allProjects: projects,
|
|
473
|
+
compactionSummaries: parsed.compactionSummaries,
|
|
474
|
+
});
|
|
475
|
+
writeProfile(out, assembleWithGroundedness({
|
|
476
|
+
projects, narrative, fingerprint, forensics, trajectory, aiRelationship, agenticLiteracy, intensity, distribution, techUsage, practices: merged, sources,
|
|
477
|
+
generatedBy: { narrative: SLASH_COMMAND },
|
|
478
|
+
manifestHash: fingerprint.manifest.bundleHash,
|
|
479
|
+
}));
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
async function cmdSubmit({ yes = false } = {}) {
|
|
483
|
+
// Profiles live in ./out; fall back to the repo root for profiles
|
|
484
|
+
// generated by a version that still wrote there.
|
|
485
|
+
let profilePath = join(process.cwd(), OUT_DIR, "candidate.json");
|
|
486
|
+
if (!existsSync(profilePath) && existsSync(join(process.cwd(), "candidate.json"))) {
|
|
487
|
+
profilePath = join(process.cwd(), "candidate.json");
|
|
488
|
+
console.log(`(using ./candidate.json from an older run, new runs write to ${OUT_DIR}/)`);
|
|
489
|
+
}
|
|
490
|
+
if (!existsSync(profilePath)) {
|
|
491
|
+
console.error(`No ${OUT_DIR}/candidate.json yet. Generate the profile first: rebase-verify generate`);
|
|
492
|
+
process.exit(2);
|
|
493
|
+
}
|
|
494
|
+
const profile = JSON.parse(readFileSync(profilePath, "utf8"));
|
|
495
|
+
const hub = resolveHub(flag("hub"));
|
|
496
|
+
const links = (profile.projects || []).filter((p) => p.artifact).length;
|
|
497
|
+
|
|
498
|
+
console.log(`\nrebase-verify submit\n`);
|
|
499
|
+
console.log(`About to send to rebase (${hub}):`);
|
|
500
|
+
console.log(` profile: ${profile.volume?.sessions} sessions, ${profile.volume?.products} products`);
|
|
501
|
+
console.log(` artifact links: ${links}`);
|
|
502
|
+
console.log(`\nYou sign in in the browser first, so rebase knows it is you; no name, email or city is sent with the profile.`);
|
|
503
|
+
console.log(`A person at rebase reads it before it counts. If they approve it, your profile gets «Verificato da rebase»,`);
|
|
504
|
+
console.log(`companies rebase works with can see its summary, its domains of work and the sectors of its representative projects, next to your name and your card (written by your model, reviewed by you), for example in the talent cloud or when rebase proposes you for a project, and its text is used to write your anonymous card.`);
|
|
505
|
+
console.log(`It is kept at most 12 months, and you can delete it from your member area.`);
|
|
506
|
+
console.log(`Controller: Rebase S.r.l. (VAT IT 14971460960). Details: https://letsrebase.com/privacy and PRIVACY.md.`);
|
|
507
|
+
console.log(`NOT sent: raw logs, local repo context, third-party proper names.`);
|
|
508
|
+
console.log(`Repository names (repoLabel) are stripped from the payload before it leaves your machine.`);
|
|
509
|
+
console.log(`Inspect the exact outgoing payload: rebase-verify submit --dry-run`);
|
|
510
|
+
|
|
511
|
+
// Pre-flight groundedness: how much of the prose is anchored in the data.
|
|
512
|
+
// Recomputed on the file as it is NOW, not trusted from the embedded score.
|
|
513
|
+
const g = assessGroundedness(profile);
|
|
514
|
+
console.log(`\nGroundedness check`);
|
|
515
|
+
if (g.score == null) {
|
|
516
|
+
console.log(` not enough verifiable anchors in the prose (n/a)`);
|
|
517
|
+
} else {
|
|
518
|
+
console.log(` ${g.score}% of prose anchors are supported by the structured data (${g.supported}/${g.total})`);
|
|
519
|
+
}
|
|
520
|
+
if (g.anomalies.length) {
|
|
521
|
+
console.log(` Unverifiable in your logs:`);
|
|
522
|
+
for (const a of g.anomalies) console.log(` - ${a.where}: "${a.anchor}" (${a.kind})`);
|
|
523
|
+
console.log(` Consider regenerating, or editing candidate.json before submitting.`);
|
|
524
|
+
}
|
|
525
|
+
const embedded = profile.groundedness?.score;
|
|
526
|
+
if (g.score != null && embedded != null && Math.abs(g.score - embedded) > 5) {
|
|
527
|
+
console.log(` Note: the file says groundedness ${embedded}% but it recomputes to ${g.score}%, candidate.json was edited after generation.`);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// Pre-flight consistency: structural invariants, then re-derivation from
|
|
531
|
+
// the logs (the ground truth the profile claims to describe).
|
|
532
|
+
console.log(`\nConsistency check`);
|
|
533
|
+
const issues = [...assessStructure(profile).issues];
|
|
534
|
+
let excessClaims = 0;
|
|
535
|
+
let root = flag("root", join(homedir(), ".claude", "projects"));
|
|
536
|
+
if (flag("project")) root = join(root, flag("project"));
|
|
537
|
+
if (existsSync(root)) {
|
|
538
|
+
// Re-derive from the SAME source mix the profile was generated from
|
|
539
|
+
// (see sourceFlags()'s comment for why this must never drift).
|
|
540
|
+
const parsed = readAllSources({ claudeRoot: root, sources: sourceFlags() });
|
|
541
|
+
// Re-derive day-based intensity and tech-usage months in the zone the
|
|
542
|
+
// profile RECORDED, never the machine zone, so the comparison measures
|
|
543
|
+
// the data, not the bucketing.
|
|
544
|
+
const techTz = recordedTechUsageTz(profile);
|
|
545
|
+
const digest = buildDigest(parsed, { tz: techTz });
|
|
546
|
+
const intensity = computeIntensity(parsed, { tz: profile.intensity?.timezone || DEFAULT_TZ });
|
|
547
|
+
const techUsage = computeTechUsage(digest.projects, { tz: techTz });
|
|
548
|
+
const practices = computeCodePractices(parsed, { tz: recordedPracticesTz(profile) });
|
|
549
|
+
const logs = assessAgainstLogs(profile, digest.projects, { intensity, techUsage, practices });
|
|
550
|
+
issues.push(...logs.issues);
|
|
551
|
+
excessClaims = logs.excessClaims || 0;
|
|
552
|
+
for (const w of logs.warnings) console.log(` ~ ${w}`);
|
|
553
|
+
} else {
|
|
554
|
+
console.log(` ~ no logs at ${root}, skipping log re-derivation (pass --root if they live elsewhere)`);
|
|
555
|
+
}
|
|
556
|
+
if (issues.length) {
|
|
557
|
+
console.log(` The structured data does not match ${existsSync(root) ? "your logs / its own invariants" : "its own invariants"}:`);
|
|
558
|
+
for (const i of issues) console.log(` - ${i}`);
|
|
559
|
+
if (excessClaims > 0) {
|
|
560
|
+
// Claims exceed what the logs can prove now. Since normal use only ever
|
|
561
|
+
// GROWS the logs, the usual cause is Claude Code's cleanup pruning the
|
|
562
|
+
// oldest sessions between generation and submit, not anything the
|
|
563
|
+
// candidate did wrong.
|
|
564
|
+
console.log(` Your profile claims more than your logs can prove right now. The usual cause:`);
|
|
565
|
+
console.log(` Claude Code prunes sessions older than its cleanup period (~30 days by default),`);
|
|
566
|
+
console.log(` and the oldest part of your window aged out after the profile was generated.`);
|
|
567
|
+
console.log(` Nothing is wrong with what you did: the numbers are just stale.`);
|
|
568
|
+
console.log(` Fix: regenerate now and submit right away (rebase-verify generate, or re-run /rebase-verify).`);
|
|
569
|
+
} else {
|
|
570
|
+
console.log(` If your logs were pruned since generation, regenerate (rebase-verify generate).`);
|
|
571
|
+
}
|
|
572
|
+
} else {
|
|
573
|
+
console.log(` structured data is internally consistent and matches your logs`);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const blockers = submitBlockers({ issues, groundedness: g, force: has("force") });
|
|
577
|
+
const printBlockers = () => {
|
|
578
|
+
for (const b of blockers) {
|
|
579
|
+
if (b.kind === "consistency") {
|
|
580
|
+
console.error(`\nConsistency check failed (${b.count} issue${b.count > 1 ? "s" : ""}). Submission blocked.`);
|
|
581
|
+
console.error(`Regenerate the profile (rebase-verify generate) or pass --force to bypass.`);
|
|
582
|
+
console.error(`Note: the intake re-checks groundedness and these invariants server-side.`);
|
|
583
|
+
} else if (b.kind === "groundedness-unscored") {
|
|
584
|
+
console.error(`\nGroundedness could not be scored: the prose has too few checkable anchors for the screen to run. Submission blocked.`);
|
|
585
|
+
console.error(`Regenerate the profile (rebase-verify generate) or pass --force to bypass.`);
|
|
586
|
+
console.error(`Note: the intake flags unscoreable prose server-side as well.`);
|
|
587
|
+
} else if (b.kind === "groundedness-low") {
|
|
588
|
+
console.error(`\nGroundedness is low (${b.score}%). Submission blocked.`);
|
|
589
|
+
console.error(`Regenerate the profile (rebase-verify generate) or pass --force to bypass.`);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// --dry-run: write the EXACT outgoing JSON (repository names stripped) and
|
|
595
|
+
// stop before any network call, so a candidate under NDA can read the very
|
|
596
|
+
// bytes that would leave the machine. The file is written even when submit
|
|
597
|
+
// would be blocked: inspection is the point; the exit code says which.
|
|
598
|
+
if (has("dry-run")) {
|
|
599
|
+
const previewPath = join(ensureOut(), "payload-preview.json");
|
|
600
|
+
writeFileSync(previewPath, JSON.stringify(buildPayload(profile), null, 2) + "\n");
|
|
601
|
+
console.log(`\nWrote ${OUT_DIR}/payload-preview.json, the exact JSON \`submit --yes\` would POST (repository names and contact stripped). Nothing was sent.`);
|
|
602
|
+
if (blockers.length) {
|
|
603
|
+
console.error(`\nsubmit would be blocked:`);
|
|
604
|
+
printBlockers();
|
|
605
|
+
process.exit(2);
|
|
606
|
+
}
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (!(yes || has("yes"))) {
|
|
611
|
+
console.log(`\nTo confirm: rebase-verify submit --yes`);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
if (blockers.length) {
|
|
615
|
+
printBlockers();
|
|
616
|
+
process.exit(2);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
try {
|
|
620
|
+
const res = await submitProfile(profilePath, { hub: flag("hub") });
|
|
621
|
+
console.log(`\nSent. Your profile is waiting as a draft: a person at rebase will read it before it counts.`);
|
|
622
|
+
if (res.review_url) console.log(`See its status here: ${res.review_url}`);
|
|
623
|
+
} catch (e) {
|
|
624
|
+
console.error(`\nSubmit failed: ${e.message}`);
|
|
625
|
+
process.exit(1);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
if (sub !== "generate" && (has("agent") || has("model"))) die("--agent and --model work with generate only.");
|
|
630
|
+
|
|
631
|
+
// No subcommand, a real terminal on both ends and no --yes: the wizard. Everything else is
|
|
632
|
+
// the sub-commands as they always were.
|
|
633
|
+
const interactive = !(argv[0] && !argv[0].startsWith("--")) && process.stdin.isTTY && process.stdout.isTTY && !has("yes");
|
|
634
|
+
|
|
635
|
+
async function cmdWizard() {
|
|
636
|
+
const { wizard, clack, live, agents } = await loadOptional(async () => ({
|
|
637
|
+
wizard: await import("../src/wizard.mjs"),
|
|
638
|
+
clack: await import("@clack/prompts"),
|
|
639
|
+
live: await import("../src/live-status.mjs"),
|
|
640
|
+
agents: await loadAgents(),
|
|
641
|
+
}));
|
|
642
|
+
const rejected = wizard.rejectedFlags(has);
|
|
643
|
+
if (rejected) die(rejected);
|
|
644
|
+
const { availableAgents, defaultAgent } = agents.registry;
|
|
645
|
+
const entry = await resolveAgent();
|
|
646
|
+
const out = outPath();
|
|
647
|
+
const root = logsRoot();
|
|
648
|
+
const flags = sourceFlags();
|
|
649
|
+
const pkg = JSON.parse(readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf8"));
|
|
650
|
+
const code = await wizard.runWizard({
|
|
651
|
+
ui: { ...clack, live: live.liveStatus },
|
|
652
|
+
out,
|
|
653
|
+
flags: { version: pkg.version, agent: entry?.id, model: flag("model") ?? undefined },
|
|
654
|
+
deps: {
|
|
655
|
+
sources: SOURCES.filter((s) => s.id === "claude-code" || !flags[s.id]?.disabled),
|
|
656
|
+
readSource: (id) =>
|
|
657
|
+
id === "claude-code" && !existsSync(root)
|
|
658
|
+
? { source: "claude-code", files: [], sessions: [], compactionSummaries: [], redaction: { hits: 0, charsRemoved: 0 } }
|
|
659
|
+
: readSource(id, { claudeRoot: root, sources: flags }),
|
|
660
|
+
combine: combineSources,
|
|
661
|
+
availableAgents: (sessionsBySource) => availableAgents({ sessionsBySource }),
|
|
662
|
+
defaultAgent,
|
|
663
|
+
prepare: (parsed) => {
|
|
664
|
+
QUIET = true;
|
|
665
|
+
ensureOut();
|
|
666
|
+
rmSync(join(out, "agent-log.jsonl"), { force: true });
|
|
667
|
+
const inputs = deriveInputs(parsed, out);
|
|
668
|
+
writePracticesInput(out, parsed, tzFlag);
|
|
669
|
+
const inputFile = join(out, "practices-input.json");
|
|
670
|
+
return {
|
|
671
|
+
inputs,
|
|
672
|
+
narrativeInput: narrativeInputFor(inputs.selected, inputs.enrichments, narrativeOptionsOf(inputs)),
|
|
673
|
+
practicesInput: existsSync(inputFile) ? JSON.parse(readFileSync(inputFile, "utf8")) : null,
|
|
674
|
+
};
|
|
675
|
+
},
|
|
676
|
+
startAgent: agents.acp.startAgent,
|
|
677
|
+
runWithAgent: agents.run.runWithAgent,
|
|
678
|
+
finish: ({ inputs }, run) => {
|
|
679
|
+
const { practices, narrative, generatedBy } = applyAgentRun(out, inputs.practices, run);
|
|
680
|
+
const profile = assembleWithGroundedness({
|
|
681
|
+
...inputs, narrative, practices, generatedBy,
|
|
682
|
+
manifestHash: inputs.fingerprint.manifest.bundleHash,
|
|
683
|
+
});
|
|
684
|
+
writeProfile(out, profile, { print: false });
|
|
685
|
+
QUIET = false;
|
|
686
|
+
return {
|
|
687
|
+
sessions: profile.volume?.sessions ?? 0,
|
|
688
|
+
products: profile.volume?.products ?? 0,
|
|
689
|
+
practices: profile.practices?.items ?? [],
|
|
690
|
+
summary: profile.summary ?? null,
|
|
691
|
+
};
|
|
692
|
+
},
|
|
693
|
+
submit: () => cmdSubmit({ yes: true }),
|
|
694
|
+
},
|
|
695
|
+
});
|
|
696
|
+
process.exit(code);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
const main = interactive ? cmdWizard : { generate: cmdGenerate, prepare: cmdPrepare, finalize: cmdFinalize, submit: cmdSubmit }[sub];
|
|
700
|
+
main().catch((e) => { console.error("Error:", e.message); process.exit(1); });
|