@losthex/scribe 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,491 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.all = exports.has = exports.str = void 0;
5
+ exports.parseArgs = parseArgs;
6
+ exports.shortRemote = shortRemote;
7
+ exports.main = main;
8
+ /**
9
+ * `scribe` — the Scribe CLI: sign in once, plant the zero-touch local
10
+ * collector, and amend your own daily report (SPEC-002, DATA-ITD-005).
11
+ *
12
+ * scribe login browser sign-in, tokens in the keychain
13
+ * scribe install --project X plant the global post-commit hook
14
+ * scribe amend "<note>" one bullet on today's report
15
+ * scribe capture queue the commit that just landed (hook)
16
+ * scribe flush push the queue to /amend
17
+ * scribe mcp stdio proxy to the Scribe MCP server
18
+ * scribe status auth, hook health, queue
19
+ * scribe log everything ever sent
20
+ * scribe uninstall remove the hook, keep the state
21
+ *
22
+ * This file is the surface: argument parsing, printing, exit codes. Every
23
+ * decision it makes lives in a module next to it, so the logic is testable
24
+ * without a terminal.
25
+ */
26
+ const node_child_process_1 = require("node:child_process");
27
+ const node_fs_1 = require("node:fs");
28
+ const node_path_1 = require("node:path");
29
+ const config_1 = require("./config");
30
+ const git_1 = require("./git");
31
+ const install_1 = require("./install");
32
+ const keychain_1 = require("./keychain");
33
+ const lock_1 = require("./lock");
34
+ const login_1 = require("./login");
35
+ const mcp_1 = require("./mcp");
36
+ const paths_1 = require("./paths");
37
+ const queue_1 = require("./queue");
38
+ const send_1 = require("./send");
39
+ const tokens_1 = require("./tokens");
40
+ const VERSION = readVersion();
41
+ function readVersion() {
42
+ for (const candidate of [
43
+ (0, node_path_1.join)(__dirname, '..', 'package.json'),
44
+ (0, node_path_1.join)(__dirname, 'package.json'),
45
+ ]) {
46
+ try {
47
+ return JSON.parse((0, node_fs_1.readFileSync)(candidate, 'utf8')).version;
48
+ }
49
+ catch {
50
+ // Try the next one; the version is cosmetic.
51
+ }
52
+ }
53
+ return '0.0.0';
54
+ }
55
+ const USAGE = `scribe ${VERSION} — Scribe local collector and amendments
56
+
57
+ Usage:
58
+ scribe login [--issuer URL] [--no-browser]
59
+ scribe install --project SLUG [--match PATTERN]... [--amend-url URL] [--mcp-url URL]
60
+ [--issuer URL] [--force]
61
+ scribe amend "<note>" [--date YYYY-MM-DD] [--project SLUG]
62
+ scribe flush [--quiet]
63
+ scribe capture [--quiet] [--no-flush]
64
+ scribe mcp [--url URL] [--issuer URL]
65
+ scribe status
66
+ scribe log [--limit N] [--json]
67
+ scribe uninstall
68
+ scribe --version | --help
69
+
70
+ Environment:
71
+ SCRIBE_ISSUER / OPENAUTH_ISSUER issuer URL (INFRA-ITD-004)
72
+ SCRIBE_AMEND_URL amend endpoint URL
73
+ SCRIBE_MCP_URL MCP endpoint URL (SPEC-008)
74
+ SCRIBE_HOME state directory (default ~/.config/scribe)
75
+ SCRIBE_TOKEN_STORE=file skip the OS keyring (containers, CI)
76
+
77
+ Adding Scribe to an agent harness:
78
+ Harnesses with remote-MCP OAuth take the URL directly — paste
79
+ <mcp url> and sign in with Google when the browser opens.
80
+ Everything else runs the stdio proxy:
81
+ { "mcpServers": { "scribe": { "command": "scribe", "args": ["mcp"] } } }
82
+ `;
83
+ function parseArgs(argv) {
84
+ const [command = 'help', ...rest] = argv;
85
+ const positionals = [];
86
+ const flags = {};
87
+ const add = (name, value) => {
88
+ flags[name] = [...(flags[name] ?? []), value];
89
+ };
90
+ for (let i = 0; i < rest.length; i += 1) {
91
+ const token = rest[i];
92
+ if (!token.startsWith('--')) {
93
+ positionals.push(token);
94
+ continue;
95
+ }
96
+ const [name, inline] = token.slice(2).split('=');
97
+ if (inline !== undefined)
98
+ add(name, inline);
99
+ else if (rest[i + 1] !== undefined && !rest[i + 1].startsWith('--'))
100
+ add(name, rest[(i += 1)]);
101
+ else
102
+ add(name, true);
103
+ }
104
+ return { command, positionals, flags };
105
+ }
106
+ /** Last string value given for a flag. */
107
+ const str = (args, name) => {
108
+ const values = (args.flags[name] ?? []).filter((v) => typeof v === 'string');
109
+ return values[values.length - 1];
110
+ };
111
+ exports.str = str;
112
+ /** Whether a flag was given at all. */
113
+ const has = (args, name) => name in args.flags;
114
+ exports.has = has;
115
+ /** Every value of a repeatable flag, comma-separated values included. */
116
+ const all = (args, name) => (args.flags[name] ?? [])
117
+ .filter((v) => typeof v === 'string')
118
+ .flatMap((value) => value.split(','))
119
+ .map((value) => value.trim())
120
+ .filter(Boolean);
121
+ exports.all = all;
122
+ function issuerFor(ctx) {
123
+ return (0, config_1.requireSetting)((0, config_1.resolveSetting)((0, exports.str)(ctx.args, 'issuer'), process.env.SCRIBE_ISSUER ?? process.env.OPENAUTH_ISSUER, ctx.config.issuer), 'issuer', 'pass --issuer or run `scribe install --issuer <url>`');
124
+ }
125
+ function amendUrlFor(ctx) {
126
+ return (0, config_1.requireSetting)((0, config_1.resolveSetting)((0, exports.str)(ctx.args, 'amend-url'), process.env.SCRIBE_AMEND_URL, ctx.config.amendUrl), 'amend url', 'pass --amend-url or run `scribe install --amend-url <url>`');
127
+ }
128
+ function mcpUrlFor(ctx) {
129
+ return (0, config_1.requireSetting)((0, config_1.resolveSetting)((0, exports.str)(ctx.args, 'url'), process.env.SCRIBE_MCP_URL, ctx.config.mcpUrl), 'mcp url', 'pass --url or run `scribe install --mcp-url <url>`');
130
+ }
131
+ function sessionFor(ctx, issuer) {
132
+ return new tokens_1.Session({
133
+ issuer,
134
+ store: (0, keychain_1.tokenStore)(issuer, {
135
+ fallbackPath: (0, node_path_1.join)(ctx.paths.home, 'credentials.json'),
136
+ warn: (message) => console.warn(`scribe: ${message}`),
137
+ }),
138
+ });
139
+ }
140
+ function today() {
141
+ // The engineer's own local day — the report is theirs (DS-002).
142
+ const now = new Date();
143
+ const local = new Date(now.getTime() - now.getTimezoneOffset() * 60_000);
144
+ return local.toISOString().slice(0, 10);
145
+ }
146
+ /** The absolute path of this CLI, for embedding into the git hook. */
147
+ function scribeBinPath() {
148
+ const bin = (0, node_path_1.join)(__dirname, 'index.js');
149
+ return (0, node_fs_1.existsSync)(bin) ? bin : process.argv[1];
150
+ }
151
+ // ---------------------------------------------------------------------------
152
+ // Commands
153
+ // ---------------------------------------------------------------------------
154
+ async function cmdLogin(ctx) {
155
+ const issuer = issuerFor(ctx);
156
+ const session = sessionFor(ctx, issuer);
157
+ const tokens = await (0, login_1.login)({
158
+ issuer,
159
+ log: (message) => console.log(message),
160
+ ...((0, exports.has)(ctx.args, 'no-browser') && { open: () => { } }),
161
+ });
162
+ const stored = session.save(tokens);
163
+ console.log(`Signed in as ${stored.email ?? 'unknown'} — tokens stored in ` +
164
+ `${(0, keychain_1.tokenStore)(issuer, { fallbackPath: (0, node_path_1.join)(ctx.paths.home, 'credentials.json') }).describe()}`);
165
+ if (!ctx.config.issuer)
166
+ (0, config_1.saveConfig)({ ...ctx.config, issuer }, ctx.paths);
167
+ return 0;
168
+ }
169
+ async function cmdInstall(ctx) {
170
+ const project = (0, exports.str)(ctx.args, 'project');
171
+ if (!project) {
172
+ console.error('scribe install: --project <slug> is required (the engagement this machine works on)');
173
+ return 2;
174
+ }
175
+ const patterns = (0, exports.all)(ctx.args, 'match');
176
+ // With no --match, the slug itself is the pattern: `--project bonterra`
177
+ // captures repos whose remote or path mentions bonterra.
178
+ const match = patterns.length > 0 ? patterns : [project];
179
+ let config = (0, config_1.upsertEngagement)(ctx.config, project, match);
180
+ const issuer = (0, config_1.resolveSetting)((0, exports.str)(ctx.args, 'issuer'), process.env.SCRIBE_ISSUER ?? process.env.OPENAUTH_ISSUER, config.issuer);
181
+ const amendUrl = (0, config_1.resolveSetting)((0, exports.str)(ctx.args, 'amend-url'), process.env.SCRIBE_AMEND_URL, config.amendUrl);
182
+ const mcpUrl = (0, config_1.resolveSetting)((0, exports.str)(ctx.args, 'mcp-url'), process.env.SCRIBE_MCP_URL, config.mcpUrl);
183
+ config = {
184
+ ...config,
185
+ ...(issuer && { issuer: issuer.replace(/\/+$/, '') }),
186
+ ...(amendUrl && { amendUrl: amendUrl.replace(/\/+$/, '') }),
187
+ ...(mcpUrl && { mcpUrl: mcpUrl.replace(/\/+$/, '') }),
188
+ };
189
+ const result = (0, install_1.installHook)({
190
+ paths: ctx.paths,
191
+ scribeBin: scribeBinPath(),
192
+ scribeHome: process.env.SCRIBE_HOME ?? null,
193
+ force: (0, exports.has)(ctx.args, 'force'),
194
+ });
195
+ (0, config_1.saveConfig)({ ...config, hook: result.state }, ctx.paths);
196
+ console.log(`Scribe is collecting for: ${config.engagements.map((e) => e.project).join(', ')}`);
197
+ console.log(` repos matching: ${match.join(', ')}`);
198
+ for (const note of result.notes)
199
+ console.log(` ${note}`);
200
+ console.log(` state: ${ctx.paths.home}`);
201
+ if (!config.amendUrl)
202
+ console.log(' note: no amend url configured yet — captures will queue');
203
+ const session = config.issuer ? sessionFor(ctx, config.issuer) : null;
204
+ if (!session?.isLoggedIn)
205
+ console.log(' next: run `scribe login`');
206
+ return 0;
207
+ }
208
+ async function cmdCapture(ctx) {
209
+ const quiet = (0, exports.has)(ctx.args, 'quiet');
210
+ const say = (message) => {
211
+ if (!quiet)
212
+ console.log(message);
213
+ };
214
+ const repo = (0, git_1.repoIdentity)();
215
+ if (!repo) {
216
+ say('scribe capture: not inside a git repository');
217
+ return 0;
218
+ }
219
+ const engagement = (0, config_1.matchEngagement)(ctx.config.engagements, [repo.remote, repo.root, repo.name]);
220
+ if (!engagement) {
221
+ // Not a mandated engagement: nothing is captured, nothing is sent.
222
+ say(`scribe capture: ${repo.name} matches no configured engagement — nothing captured`);
223
+ return 0;
224
+ }
225
+ const facts = (0, git_1.commitFacts)();
226
+ if (!facts) {
227
+ say('scribe capture: no commit to read');
228
+ return 0;
229
+ }
230
+ const entry = (0, queue_1.newEntry)({
231
+ project: engagement.project,
232
+ commit: {
233
+ repo: repo.remote ? shortRemote(repo.remote) : repo.name,
234
+ branch: repo.branch,
235
+ hash: facts.hash,
236
+ subject: facts.subject,
237
+ at: facts.at,
238
+ filesChanged: facts.filesChanged,
239
+ },
240
+ });
241
+ (0, queue_1.appendEntry)(ctx.paths.queue, entry);
242
+ say(`scribe: queued ${entry.commit.hash.slice(0, 7)} for ${engagement.project} (${entry.day})`);
243
+ if (!(0, exports.has)(ctx.args, 'no-flush'))
244
+ spawnDetachedFlush();
245
+ return 0;
246
+ }
247
+ /** `git@host:org/repo.git` / `https://host/org/repo.git` → `org/repo`. */
248
+ function shortRemote(remote) {
249
+ const withoutSuffix = remote.replace(/\.git$/, '');
250
+ const path = withoutSuffix.includes('://')
251
+ ? new URL(withoutSuffix).pathname
252
+ : withoutSuffix.split(':').slice(1).join(':');
253
+ const parts = path.split('/').filter(Boolean);
254
+ return parts.slice(-2).join('/') || withoutSuffix;
255
+ }
256
+ /**
257
+ * Flushing must never make a commit wait, and it must survive the hook's
258
+ * shell exiting — so it is a detached child with no stdio, running the same
259
+ * CLI. The lock file keeps a burst of commits to one flush.
260
+ */
261
+ function spawnDetachedFlush() {
262
+ try {
263
+ (0, node_child_process_1.spawn)(process.execPath, [(0, node_path_1.join)(__dirname, 'index.js'), 'flush', '--quiet'], {
264
+ detached: true,
265
+ stdio: 'ignore',
266
+ }).unref();
267
+ }
268
+ catch {
269
+ // No flush now; the next capture or `scribe flush` picks the queue up.
270
+ }
271
+ }
272
+ async function cmdFlush(ctx) {
273
+ const quiet = (0, exports.has)(ctx.args, 'quiet');
274
+ const say = (message) => {
275
+ if (!quiet)
276
+ console.log(message);
277
+ };
278
+ const issuer = issuerFor(ctx);
279
+ const amendUrl = amendUrlFor(ctx);
280
+ const session = sessionFor(ctx, issuer);
281
+ const result = await (0, lock_1.withLock)(ctx.paths.lock, () => (0, send_1.flush)({ paths: ctx.paths, amendUrl, session, log: say }));
282
+ if (!result.acquired) {
283
+ say('scribe flush: another flush is already running');
284
+ return 0;
285
+ }
286
+ const report = result.value;
287
+ say(`flushed: ${report.commitsSent} commit(s) in ${report.sent} batch(es), ` +
288
+ `${report.deferred} deferred, ${report.rejected} rejected, ${report.expired} expired`);
289
+ if (report.needsLogin) {
290
+ console.error('scribe: the queue needs a sign-in — run `scribe login`');
291
+ return 1;
292
+ }
293
+ return report.errors.length > 0 && report.sent === 0 ? 1 : 0;
294
+ }
295
+ async function cmdAmend(ctx) {
296
+ const note = ctx.args.positionals.join(' ').trim();
297
+ if (!note) {
298
+ console.error('scribe amend: give me the note — scribe amend "what you did, one line"');
299
+ return 2;
300
+ }
301
+ const issuer = issuerFor(ctx);
302
+ const amendUrl = amendUrlFor(ctx);
303
+ const session = sessionFor(ctx, issuer);
304
+ if (!session.isLoggedIn)
305
+ throw new tokens_1.NotLoggedInError();
306
+ const day = (0, exports.str)(ctx.args, 'date') ?? today();
307
+ const payload = (0, send_1.payloadForNote)(note, day, (0, exports.str)(ctx.args, 'project'));
308
+ let result = await (0, send_1.postAmendment)(amendUrl, payload, await session.accessToken());
309
+ if (result.status === 401) {
310
+ const refreshed = await session.refresh();
311
+ if (refreshed)
312
+ result = await (0, send_1.postAmendment)(amendUrl, payload, refreshed);
313
+ }
314
+ if (result.status >= 200 && result.status < 300) {
315
+ console.log(`Amended ${day}: ${note}`);
316
+ return 0;
317
+ }
318
+ console.error(`scribe amend: not sent (${result.status || 'no response'}): ${result.error ?? 'unknown error'}`);
319
+ return 1;
320
+ }
321
+ /**
322
+ * The stdio↔HTTP bridge (SPEC-008). Long-running by design: it lives as
323
+ * long as the harness keeps stdin open, and every diagnostic goes to
324
+ * stderr so stdout stays pure JSON-RPC.
325
+ */
326
+ async function cmdMcp(ctx) {
327
+ const issuer = issuerFor(ctx);
328
+ const url = mcpUrlFor(ctx);
329
+ const session = sessionFor(ctx, issuer);
330
+ if (!session.isLoggedIn)
331
+ throw new tokens_1.NotLoggedInError();
332
+ console.error(`scribe mcp: proxying stdio to ${url} as ${session.email ?? 'unknown'}`);
333
+ await (0, mcp_1.runProxy)(process.stdin, {
334
+ url,
335
+ token: () => session.accessToken(),
336
+ refresh: () => session.refresh(),
337
+ write: (line) => process.stdout.write(`${line}\n`),
338
+ log: (message) => console.error(message),
339
+ });
340
+ return 0;
341
+ }
342
+ async function cmdStatus(ctx) {
343
+ const row = (label, value) => console.log(` ${label.padEnd(13)}${value}`);
344
+ const issuer = (0, config_1.resolveSetting)((0, exports.str)(ctx.args, 'issuer'), process.env.SCRIBE_ISSUER ?? process.env.OPENAUTH_ISSUER, ctx.config.issuer);
345
+ console.log(`scribe ${VERSION}`);
346
+ row('state', ctx.paths.home);
347
+ row('issuer', issuer ?? 'not configured');
348
+ row('amend url', ctx.config.amendUrl ?? process.env.SCRIBE_AMEND_URL ?? 'not configured');
349
+ row('mcp url', ctx.config.mcpUrl ?? process.env.SCRIBE_MCP_URL ?? 'not configured');
350
+ if (!issuer) {
351
+ row('auth', 'no issuer configured — run `scribe install --issuer <url>`');
352
+ }
353
+ else {
354
+ const store = (0, keychain_1.tokenStore)(issuer, { fallbackPath: (0, node_path_1.join)(ctx.paths.home, 'credentials.json') });
355
+ const session = new tokens_1.Session({ issuer, store });
356
+ if (!session.isLoggedIn) {
357
+ row('auth', `signed out (${store.describe()}) — run \`scribe login\``);
358
+ }
359
+ else {
360
+ row('auth', `${session.email ?? 'unknown'} — token ${describeExpiry(session.expiresAt)}, ` +
361
+ `in ${store.describe()}`);
362
+ }
363
+ }
364
+ row('engagements', ctx.config.engagements.length === 0
365
+ ? 'none — run `scribe install --project <slug> --match <pattern>`'
366
+ : ctx.config.engagements.map((e) => `${e.project} (${e.match.join(', ')})`).join('; '));
367
+ const health = (0, install_1.hookHealth)(ctx.config, ctx.paths, scribeBinPath());
368
+ row('hook', health.installed
369
+ ? `${(0, node_path_1.join)(health.path ?? '', 'post-commit')}${health.chained ? ` → chains ${health.chained}` : ''}`
370
+ : 'not installed — run `scribe install`');
371
+ for (const problem of health.problems)
372
+ row('', `! ${problem}`);
373
+ const localHooksPath = (0, git_1.gitConfig)('core.hooksPath', 'local');
374
+ if (localHooksPath) {
375
+ row('', `! this repo sets core.hooksPath=${localHooksPath}, which overrides the global hook`);
376
+ row('', " commits here are not captured (the repo's own tooling keeps working)");
377
+ }
378
+ const queue = (0, queue_1.readQueue)(ctx.paths.queue);
379
+ const due = queue.filter((entry) => (0, queue_1.isDue)(entry, new Date()));
380
+ row('queue', queue.length === 0
381
+ ? 'empty'
382
+ : `${queue.length} commit(s), ${due.length} due now, ${(0, queue_1.batches)(queue).length} batch(es)` +
383
+ `${oldest(queue)}`);
384
+ for (const entry of queue.filter((e) => e.lastError).slice(0, 3)) {
385
+ row('', `! ${entry.commit.hash.slice(0, 7)}: ${entry.lastError}`);
386
+ }
387
+ const sent = (0, queue_1.readOutcomes)(ctx.paths.sent);
388
+ const commits = sent.reduce((total, outcome) => total + outcome.entries.length, 0);
389
+ row('sent', sent.length === 0
390
+ ? 'nothing yet'
391
+ : `${commits} commit(s) in ${sent.length} batch(es), last ${sent[sent.length - 1].at}`);
392
+ const rejected = (0, queue_1.readOutcomes)(ctx.paths.dead);
393
+ if (rejected.length > 0) {
394
+ row('rejected', `${rejected.reduce((t, o) => t + o.entries.length, 0)} commit(s) — see \`scribe log --json\``);
395
+ }
396
+ const holder = (0, lock_1.lockHolder)(ctx.paths.lock);
397
+ if (holder)
398
+ row('flush lock', `held by pid ${holder}`);
399
+ return health.problems.length > 0 ? 1 : 0;
400
+ }
401
+ function describeExpiry(expiresAt) {
402
+ if (expiresAt === null)
403
+ return 'expiry unknown (refresh on demand)';
404
+ const ms = expiresAt - Date.now();
405
+ if (ms <= 0)
406
+ return 'expired (refreshes on next send)';
407
+ const hours = Math.round(ms / 3_600_000);
408
+ return hours >= 48 ? `valid ${Math.round(hours / 24)}d` : `valid ${hours}h`;
409
+ }
410
+ function oldest(queue) {
411
+ const days = [...new Set(queue.map((entry) => entry.day))].sort();
412
+ return days.length > 0 ? `, oldest day ${days[0]}` : '';
413
+ }
414
+ async function cmdLog(ctx) {
415
+ const limit = Number((0, exports.str)(ctx.args, 'limit') ?? 20);
416
+ const outcomes = [...(0, queue_1.readOutcomes)(ctx.paths.sent), ...(0, queue_1.readOutcomes)(ctx.paths.dead)].sort((a, b) => a.at.localeCompare(b.at));
417
+ if ((0, exports.has)(ctx.args, 'json')) {
418
+ console.log(JSON.stringify(outcomes.slice(-limit), null, 2));
419
+ return 0;
420
+ }
421
+ if (outcomes.length === 0) {
422
+ console.log('scribe has sent nothing yet.');
423
+ return 0;
424
+ }
425
+ console.log('Everything scribe has sent (newest last):');
426
+ for (const outcome of outcomes.slice(-limit)) {
427
+ const verdict = outcome.status >= 200 && outcome.status < 300 ? 'sent' : `refused (${outcome.status})`;
428
+ console.log(`\n${outcome.at} ${verdict}${outcome.error ? ` — ${outcome.error}` : ''}`);
429
+ for (const entry of outcome.entries) {
430
+ console.log(` ${entry.day} ${entry.project} ${entry.commit.repo}` +
431
+ `${entry.commit.branch ? `@${entry.commit.branch}` : ''} ` +
432
+ `${entry.commit.hash.slice(0, 7)} ${entry.commit.subject}` +
433
+ ` (${entry.commit.filesChanged} file(s))`);
434
+ }
435
+ }
436
+ return 0;
437
+ }
438
+ async function cmdUninstall(ctx) {
439
+ const { notes } = (0, install_1.uninstallHook)(ctx.config, ctx.paths);
440
+ const { hook: _removed, ...rest } = ctx.config;
441
+ (0, config_1.saveConfig)(rest, ctx.paths);
442
+ for (const note of notes)
443
+ console.log(` ${note}`);
444
+ console.log(`Queue and history are untouched in ${ctx.paths.home}.`);
445
+ return 0;
446
+ }
447
+ // ---------------------------------------------------------------------------
448
+ // Entry point
449
+ // ---------------------------------------------------------------------------
450
+ const COMMANDS = {
451
+ login: cmdLogin,
452
+ install: cmdInstall,
453
+ capture: cmdCapture,
454
+ flush: cmdFlush,
455
+ amend: cmdAmend,
456
+ mcp: cmdMcp,
457
+ status: cmdStatus,
458
+ log: cmdLog,
459
+ uninstall: cmdUninstall,
460
+ };
461
+ async function main(argv) {
462
+ const args = parseArgs(argv);
463
+ if (args.command === '--version' || args.command === '-v') {
464
+ console.log(VERSION);
465
+ return 0;
466
+ }
467
+ if (args.command === 'help' || args.command === '--help' || args.command === '-h') {
468
+ console.log(USAGE);
469
+ return 0;
470
+ }
471
+ const command = COMMANDS[args.command];
472
+ if (!command) {
473
+ console.error(`scribe: unknown command \`${args.command}\`\n\n${USAGE}`);
474
+ return 2;
475
+ }
476
+ const paths = (0, paths_1.resolvePaths)();
477
+ return command({ paths, config: (0, config_1.loadConfig)(paths), args });
478
+ }
479
+ if (require.main === module) {
480
+ main(process.argv.slice(2))
481
+ .then((code) => process.exit(code))
482
+ .catch((err) => {
483
+ if (err instanceof tokens_1.NotLoggedInError) {
484
+ console.error(`scribe: ${err.message}`);
485
+ process.exit(1);
486
+ }
487
+ console.error(`scribe: ${err instanceof Error ? err.message : String(err)}`);
488
+ process.exit(1);
489
+ });
490
+ }
491
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AA2GA,8BAmBC;AAqMD,kCAOC;AA6PD,oBAiBC;AAvlBD;;;;;;;;;;;;;;;;;GAiBG;AACH,2DAA2C;AAC3C,qCAAmD;AACnD,yCAAiC;AAEjC,qCAQkB;AAClB,+BAA6D;AAC7D,uCAAmE;AACnE,yCAAwC;AACxC,iCAA8C;AAC9C,mCAAgC;AAChC,+BAAiC;AACjC,mCAAmD;AACnD,mCAQiB;AACjB,iCAA8D;AAC9D,qCAAqD;AAErD,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;AAE9B,SAAS,WAAW;IAClB,KAAK,MAAM,SAAS,IAAI;QACtB,IAAA,gBAAI,EAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC;QACrC,IAAA,gBAAI,EAAC,SAAS,EAAE,cAAc,CAAC;KAChC,EAAE,CAAC;QACF,IAAI,CAAC;YACH,OAAQ,IAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,SAAS,EAAE,MAAM,CAAC,CAAyB,CAAC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AAW,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC7E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.surveyHooks = surveyHooks;
4
+ exports.installHook = installHook;
5
+ exports.uninstallHook = uninstallHook;
6
+ exports.hookHealth = hookHealth;
7
+ /**
8
+ * `scribe install` / `scribe uninstall` — the filesystem and git-config
9
+ * side of the zero-touch collector (DATA-ITD-005).
10
+ *
11
+ * Install is once, at engagement onboarding, and after it the engineer does
12
+ * nothing day to day — the friction that killed Toggl (DATA-ITD-001) is the
13
+ * thing this command exists to avoid. Uninstall puts the machine back:
14
+ * their own hook returns to `post-commit`, and `core.hooksPath` goes back to
15
+ * unset if Scribe was the one that set it.
16
+ *
17
+ * The decision-making is in hook.ts (pure); this file performs it.
18
+ */
19
+ const node_fs_1 = require("node:fs");
20
+ const node_path_1 = require("node:path");
21
+ const git_1 = require("./git");
22
+ const hook_1 = require("./hook");
23
+ function surveyHooks(paths) {
24
+ const globalHooksPath = (0, git_1.gitConfig)('core.hooksPath', 'global');
25
+ const hooksPath = globalHooksPath ?? paths.hooks;
26
+ const postCommit = (0, node_path_1.join)(hooksPath, 'post-commit');
27
+ return {
28
+ globalHooksPath,
29
+ defaultHooksPath: paths.hooks,
30
+ existingPostCommit: (0, node_fs_1.existsSync)(postCommit) ? (0, node_fs_1.readFileSync)(postCommit, 'utf8') : null,
31
+ adoptedExists: (0, node_fs_1.existsSync)((0, node_path_1.join)(hooksPath, hook_1.ADOPTED_NAME)),
32
+ };
33
+ }
34
+ function installHook({ paths, scribeBin, scribeHome = null, force = false, }) {
35
+ const survey = surveyHooks(paths);
36
+ const plan = (0, hook_1.planHookInstall)(survey);
37
+ if (plan.conflict && !force)
38
+ throw new Error(plan.conflict);
39
+ const notes = [];
40
+ (0, node_fs_1.mkdirSync)(plan.hooksPath, { recursive: true });
41
+ const postCommit = (0, node_path_1.join)(plan.hooksPath, 'post-commit');
42
+ if (plan.adoptExisting) {
43
+ // Move, don't copy: leaving both in place would run it twice.
44
+ (0, node_fs_1.renameSync)(postCommit, (0, node_path_1.join)(plan.hooksPath, hook_1.ADOPTED_NAME));
45
+ (0, node_fs_1.chmodSync)((0, node_path_1.join)(plan.hooksPath, hook_1.ADOPTED_NAME), 0o755);
46
+ notes.push(`adopted your existing post-commit hook as ${hook_1.ADOPTED_NAME} — the shim runs it first`);
47
+ }
48
+ else if (plan.conflict && force) {
49
+ const backup = (0, node_path_1.join)(plan.hooksPath, `post-commit.replaced-${Date.now()}`);
50
+ (0, node_fs_1.copyFileSync)(postCommit, backup);
51
+ notes.push(`--force: kept a copy of the previous post-commit at ${backup}`);
52
+ }
53
+ else if (plan.chained) {
54
+ notes.push(`still chaining to ${hook_1.ADOPTED_NAME} from an earlier install`);
55
+ }
56
+ (0, node_fs_1.writeFileSync)(postCommit, (0, hook_1.postCommitHook)({ scribeBin, scribeHome }), { mode: 0o755 });
57
+ (0, node_fs_1.chmodSync)(postCommit, 0o755);
58
+ if (plan.setGlobalHooksPath) {
59
+ (0, git_1.setGitConfig)('core.hooksPath', plan.hooksPath, 'global');
60
+ notes.push(`set core.hooksPath (global) to ${plan.hooksPath}`);
61
+ }
62
+ else {
63
+ notes.push(`honoured your existing core.hooksPath: ${plan.hooksPath}`);
64
+ }
65
+ if (plan.reinstall)
66
+ notes.push('replaced the previous Scribe shim');
67
+ return {
68
+ plan,
69
+ state: {
70
+ path: plan.hooksPath,
71
+ chained: plan.chained,
72
+ ownsHooksPath: plan.setGlobalHooksPath,
73
+ installedAt: new Date().toISOString(),
74
+ },
75
+ notes,
76
+ };
77
+ }
78
+ /**
79
+ * Removes the shim and restores whatever it displaced. Anything Scribe did
80
+ * not create is left exactly where the engineer had it.
81
+ */
82
+ function uninstallHook(config, paths) {
83
+ const notes = [];
84
+ const hooksPath = config.hook?.path ?? (0, git_1.gitConfig)('core.hooksPath', 'global') ?? paths.hooks;
85
+ const postCommit = (0, node_path_1.join)(hooksPath, 'post-commit');
86
+ if ((0, node_fs_1.existsSync)(postCommit) && (0, hook_1.isScribeHook)((0, node_fs_1.readFileSync)(postCommit, 'utf8'))) {
87
+ (0, node_fs_1.rmSync)(postCommit, { force: true });
88
+ notes.push(`removed ${postCommit}`);
89
+ const adopted = (0, node_path_1.join)(hooksPath, hook_1.ADOPTED_NAME);
90
+ if ((0, node_fs_1.existsSync)(adopted)) {
91
+ (0, node_fs_1.renameSync)(adopted, postCommit);
92
+ (0, node_fs_1.chmodSync)(postCommit, 0o755);
93
+ notes.push('restored your own post-commit hook');
94
+ }
95
+ }
96
+ else if ((0, node_fs_1.existsSync)(postCommit)) {
97
+ notes.push(`left ${postCommit} alone — it is not Scribe's`);
98
+ }
99
+ if (config.hook?.ownsHooksPath) {
100
+ (0, git_1.unsetGitConfig)('core.hooksPath', 'global');
101
+ notes.push('unset core.hooksPath (global) — Scribe had set it');
102
+ }
103
+ else if (config.hook) {
104
+ notes.push(`left core.hooksPath alone: ${hooksPath} was yours`);
105
+ }
106
+ return { notes };
107
+ }
108
+ function hookHealth(config, paths, scribeBin) {
109
+ const problems = [];
110
+ const globalHooksPath = (0, git_1.gitConfig)('core.hooksPath', 'global');
111
+ const hooksPath = config.hook?.path ?? globalHooksPath;
112
+ if (!hooksPath) {
113
+ return { installed: false, path: null, current: false, chained: null, problems };
114
+ }
115
+ const postCommit = (0, node_path_1.join)(hooksPath, 'post-commit');
116
+ const contents = (0, node_fs_1.existsSync)(postCommit) ? (0, node_fs_1.readFileSync)(postCommit, 'utf8') : null;
117
+ const installed = contents !== null && (0, hook_1.isScribeHook)(contents);
118
+ if (!installed)
119
+ problems.push(`no Scribe post-commit hook at ${postCommit} — run \`scribe install\``);
120
+ if (globalHooksPath !== hooksPath) {
121
+ problems.push(`core.hooksPath is ${globalHooksPath ?? 'unset'} but the hook lives in ${hooksPath}` +
122
+ ' — git will not run it');
123
+ }
124
+ const current = installed && contents === (0, hook_1.postCommitHook)({ scribeBin, scribeHome: pinnedHome(contents) });
125
+ if (installed && !current) {
126
+ problems.push('the installed hook differs from this version of scribe — re-run `scribe install`');
127
+ }
128
+ return {
129
+ installed,
130
+ path: hooksPath,
131
+ current,
132
+ chained: (0, node_fs_1.existsSync)((0, node_path_1.join)(hooksPath, hook_1.ADOPTED_NAME)) ? hook_1.ADOPTED_NAME : null,
133
+ problems,
134
+ };
135
+ }
136
+ /** Reads back the SCRIBE_HOME an installed shim was pinned to, if any. */
137
+ function pinnedHome(contents) {
138
+ return contents.match(/^SCRIBE_HOME="([^"]*)"$/m)?.[1] ?? null;
139
+ }
140
+ //# sourceMappingURL=install.js.map