rvlib-shipkit 2.23.0 → 2.25.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/CHANGELOG.md +45 -0
- package/package.json +1 -1
- package/src/agent-time/live.ts +153 -0
- package/src/agent-time/render.ts +28 -14
- package/src/agent-time/report.ts +46 -25
- package/src/agent-time/store.ts +30 -10
- package/src/agent-time/timeline.ts +43 -15
- package/src/annex/offload.ts +16 -7
- package/src/asks/asks-queue.ts +32 -11
- package/src/check.ts +3 -1
- package/src/checks/SK004-gitignore-policy.check.ts +32 -11
- package/src/checks/SK027-agent-wiki-links.check.ts +1 -1
- package/src/checks/SK033-global-contribution.check.ts +1 -1
- package/src/checks/SK036-draft-media-size.check.ts +1 -1
- package/src/checks/SK040-release-words.check.ts +1 -1
- package/src/checks/SK042-post-kinds.check.ts +1 -1
- package/src/checks/SK044-behind-upstream.check.ts +38 -0
- package/src/cli/cmd_Annex.ts +12 -7
- package/src/cli/cmd_Asks.ts +2 -0
- package/src/cli/cmd_Assets.ts +5 -5
- package/src/cli/cmd_Backup.ts +16 -8
- package/src/cli/cmd_Bump.ts +1 -0
- package/src/cli/cmd_Capacity.ts +30 -0
- package/src/cli/cmd_Check.ts +1 -0
- package/src/cli/cmd_Checks.ts +13 -1
- package/src/cli/cmd_Ci.ts +3 -2
- package/src/cli/cmd_Commands.ts +61 -16
- package/src/cli/cmd_ConfigKeys.ts +17 -0
- package/src/cli/cmd_Home.ts +1 -30
- package/src/cli/cmd_Hooks.ts +1 -0
- package/src/cli/cmd_Keys.ts +4 -1
- package/src/cli/cmd_Lanes.ts +35 -0
- package/src/cli/cmd_Mv.ts +7 -7
- package/src/cli/cmd_Rec.ts +22 -7
- package/src/cli/cmd_Reflect.ts +1 -0
- package/src/cli/cmd_Releases.ts +1 -0
- package/src/cli/cmd_Review.ts +200 -49
- package/src/cli/cmd_Secret.ts +41 -2
- package/src/cli/cmd_Shot.ts +16 -4
- package/src/cli/cmd_Status.ts +7 -5
- package/src/cli/cmd_Time.ts +13 -5
- package/src/cli/cmd_Tmp.ts +82 -0
- package/src/cli/cmd_Veille.ts +10 -6
- package/src/cli/cmd_Wiki.ts +1 -0
- package/src/cli/family-help.ts +136 -0
- package/src/cli/family-pages.ts +0 -19
- package/src/cli/kit/calls.ts +35 -0
- package/src/cli/kit/project-cli.ts +2 -12
- package/src/cli/registry.ts +52 -7
- package/src/cli.ts +8 -4
- package/src/collections/pings.ts +1 -1
- package/src/core/capacity.ts +127 -0
- package/src/core/check-runner.ts +91 -16
- package/src/core/floor-resolve.ts +6 -2
- package/src/core/floor.ts +6 -2
- package/src/core/history-files.ts +18 -0
- package/src/core/jobs.ts +35 -16
- package/src/core/layout.ts +2 -2
- package/src/core/motherhome.ts +67 -9
- package/src/core/nearest.ts +16 -0
- package/src/core/remove-tree.ts +19 -0
- package/src/core/runs.ts +12 -3
- package/src/core/slots.ts +49 -12
- package/src/core/throwaway-worktree.ts +22 -4
- package/src/core/trace-audit.ts +21 -5
- package/src/drill/run.ts +5 -2
- package/src/home/daemon-jobs.ts +41 -4
- package/src/home/gui-app/ShipkitGui.swift +1 -0
- package/src/home/home-launchd.ts +11 -3
- package/src/home/home-routes.ts +11 -4
- package/src/home/machine-host.ts +65 -0
- package/src/home/machine-stores.ts +19 -17
- package/src/home/machine-temp.ts +485 -0
- package/src/home/other-macs.ts +74 -0
- package/src/home/run-daemon.ts +10 -2
- package/src/home/serve-web.ts +2 -2
- package/src/home/via-hub.ts +6 -1
- package/src/init-repo.ts +7 -3
- package/src/ledger/gate-checks.ts +3 -2
- package/src/ledger/git-key.ts +25 -4
- package/src/ledger/git-scan.ts +10 -0
- package/src/ledger/ledger.ts +6 -0
- package/src/ledger/store.ts +6 -0
- package/src/media-store/backup/daemon.ts +92 -20
- package/src/media-store/backup/keys.ts +21 -6
- package/src/media-store/backup/manifest.ts +52 -11
- package/src/media-store/backup/restore.ts +17 -10
- package/src/media-store/backup/run.ts +26 -17
- package/src/media-store/backup/sources.ts +168 -22
- package/src/media-store/backup/watch.ts +106 -0
- package/src/media-store/daemon.ts +36 -8
- package/src/media-store/hand.ts +3 -1
- package/src/mv/mv-md.ts +167 -56
- package/src/pb/run-pb.ts +2 -10
- package/src/plan/repo-source.ts +25 -14
- package/src/recordings/model.ts +1 -1
- package/src/reflect/transcript.ts +56 -11
- package/src/release/run-bump.ts +3 -2
- package/src/release/run-release.ts +12 -4
- package/src/releases/from-card.ts +45 -3
- package/src/releases/model.ts +6 -0
- package/src/releases/store.ts +8 -1
- package/src/repo-config.ts +5 -3
- package/src/review/cells.ts +26 -4
- package/src/review/format.ts +34 -10
- package/src/review/media-kind.ts +14 -11
- package/src/review/media-read.ts +6 -5
- package/src/review/model.ts +85 -4
- package/src/review/paste.ts +2 -1
- package/src/review/previews.ts +123 -36
- package/src/review/routes.ts +29 -18
- package/src/review/store.ts +89 -19
- package/src/review/threads.ts +7 -5
- package/src/review/trailer-model.ts +2 -2
- package/src/secrets/copy.ts +110 -0
- package/src/secrets/list.ts +17 -7
- package/src/serve/hub-app/home-strip.css +5 -0
- package/src/serve/hub-app/home-strip.tsx +18 -0
- package/src/serve/hub-app/hub-app.tsx +2 -1
- package/src/serve/hub-app/hub.css +14 -0
- package/src/serve/hub-app/inbox.css +1 -0
- package/src/serve/hub-app/pull-refresh.tsx +88 -0
- package/src/serve/hub-app/review/review-cells.tsx +52 -13
- package/src/serve/hub-app/review/review-list.tsx +6 -1
- package/src/serve/hub-app/review/review-st.ts +6 -5
- package/src/serve/hub-app/review/review-thread.tsx +3 -1
- package/src/serve/hub-app/review/review-views.tsx +18 -11
- package/src/serve/hub-app/review/thread-st.ts +82 -14
- package/src/serve/hub-app/review.css +15 -2
- package/src/serve/hub-runtime.ts +2 -1
- package/src/serve/run-serve.ts +4 -2
- package/src/serve/serve-hub.ts +9 -2
- package/src/shot/client.ts +4 -2
- package/src/shot/serve-shot.ts +71 -2
- package/src/shot/shooter.ts +65 -11
- package/src/shot/shot-ask.ts +32 -9
- package/src/suite/child-tools.ts +45 -0
- package/src/suite/judge-suites.ts +10 -22
- package/src/suite/select.ts +95 -9
- package/src/suite/suite-cli.ts +38 -14
- package/src/suite/suite-cores.ts +68 -0
- package/src/suite/suite-reads-preload.ts +8 -6
- package/src/suite/test-units.ts +31 -12
- package/src/trailer/graph.ts +2 -1
- package/src/ts/config.ts +21 -0
- package/src/ts/rename.ts +37 -13
- package/src/ts/workspaces.ts +45 -0
- package/src/wiki/run-wiki.ts +7 -2
- package/src/wiki/scan-md.ts +2 -1
- package/src/home/claude-temp.ts +0 -139
package/src/cli/cmd_Time.ts
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
// through the agent time index (agent-time/store.ts). REPORT ONLY: exit 0 with
|
|
4
4
|
// a report, 1 when nothing matched, 2 on a bad flag.
|
|
5
5
|
import { Command, Option } from 'clipanion'
|
|
6
|
-
import { resolve } from 'path'
|
|
6
|
+
import { dirname, resolve } from 'path'
|
|
7
7
|
|
|
8
8
|
const BIG_BYTES = 50 * 1024 * 1024
|
|
9
9
|
|
|
10
10
|
export class TimeCommand extends Command {
|
|
11
11
|
static override paths = [['time']]
|
|
12
|
+
static essential = {}
|
|
12
13
|
|
|
13
14
|
static override usage = Command.Usage({
|
|
14
15
|
category: 'Health',
|
|
@@ -18,7 +19,8 @@ export class TimeCommand extends Command {
|
|
|
18
19
|
'The first run builds the index (niced, resumable, progress on stderr); later runs read only what changed. The index keeps sessions Claude Code has pruned.',
|
|
19
20
|
'Views: summary (default), commands, tools, slow, fails, feedback, sessions, turns. A Bash command is grouped by its shape (`git commit`, `bun test <file>`, `sk ci --only lint`).',
|
|
20
21
|
'Turns: every call costs a model turn before it, so the summary gives the model time before each call, the share of single read calls and the share sent in parallel, for the main sessions and the sub-agents; `turns` lists the runs and the read shapes by the model time they cost.',
|
|
21
|
-
'Wall time is cut once per moment: tools in flight, a sub-agent in flight, waiting on
|
|
22
|
+
'Wall time is cut once per moment, and the buckets add up to the wall: tools in flight, a sub-agent in flight, waiting on you (an idle gap past 30 minutes is left out), stopped until a task notification woke it (background wait), stopped with nothing recorded that woke it (unknown), else the agent was in its turn (model).',
|
|
23
|
+
'A background command (run_in_background, or moved there at its timeout) is timed from its start to its task notification, its row marked (bg); a run with no notification is counted as having no end, never as zero.',
|
|
22
24
|
'Commands and prompts are masked through the leak guard keyword list and token shapes before they print.',
|
|
23
25
|
].join(' '),
|
|
24
26
|
examples: [
|
|
@@ -68,7 +70,10 @@ export class TimeCommand extends Command {
|
|
|
68
70
|
const { buildReport } = await import('../agent-time/report.ts')
|
|
69
71
|
const { loadMasker } = await import('../agent-time/mask.ts')
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
// with no repo named: the repo this folder is in, by its main work tree, where its sessions are filed
|
|
74
|
+
const { gitRoot } = await import('../core/git-root.ts')
|
|
75
|
+
const here = gitRoot(process.cwd())
|
|
76
|
+
const repos = repoArgs.length > 0 ? repoArgs.map((r) => resolve(r)) : [here == null ? process.cwd() : dirname(here.commonDir)]
|
|
72
77
|
const slugs = repos.map(projectSlug)
|
|
73
78
|
const keep = this.all ? () => true : (p: string) => slugs.some((s) => p === s || p.startsWith(`${s}--claude-worktrees-`))
|
|
74
79
|
const roots = discoverConfigRoots()
|
|
@@ -86,12 +91,14 @@ export class TimeCommand extends Command {
|
|
|
86
91
|
try { (require('os') as typeof import('os')).setPriority(0, 15) } catch { /* not allowed: index at the normal priority */ }
|
|
87
92
|
}
|
|
88
93
|
const t = performance.now()
|
|
89
|
-
|
|
94
|
+
// off a terminal the first line is the answer: a progress line only for an index that runs long
|
|
95
|
+
if (tty ? t - lastPrint < 200 && p.done < p.files : t - Math.max(lastPrint, tIndex) < 10_000) return
|
|
90
96
|
lastPrint = t
|
|
91
97
|
const line = `index: ${p.done}/${p.files} files, ${(p.doneBytes / 1e9).toFixed(1)}/${(p.bytes / 1e9).toFixed(1)} GB, ${Math.round((t - tIndex) / 1000)}s`
|
|
92
98
|
err.write(tty ? `\r${line}` : `${line}\n`)
|
|
93
99
|
})
|
|
94
|
-
|
|
100
|
+
const indexed = res.bytes >= BIG_BYTES ? `index: read ${res.read} of ${pending} files, ${(res.bytes / 1e9).toFixed(2)} GB in ${(res.ms / 1000).toFixed(1)}s (${agentTimeDbPath()})\n` : ''
|
|
101
|
+
if (tty && indexed !== '') err.write(`\n${indexed}`)
|
|
95
102
|
markGone(db, files, keep)
|
|
96
103
|
const loaded = loadWindow(db, keep, from ?? 0, now)
|
|
97
104
|
const labels = this.all ? [...new Set(loaded.files.map((f) => repoOfProject(f.project)))].sort() : slugs.map((s) => repoOfProject(s))
|
|
@@ -104,6 +111,7 @@ export class TimeCommand extends Command {
|
|
|
104
111
|
const report = buildReport(loaded, { repos: labels, from, to: now, repoOf: (p) => repoOfProject(p) }, loadMasker(repos[0] ?? null))
|
|
105
112
|
if (this.json) this.context.stdout.write(`${JSON.stringify(report)}\n`)
|
|
106
113
|
else this.context.stdout.write(render(report, view, top))
|
|
114
|
+
if (!tty) err.write(indexed)
|
|
107
115
|
return 0
|
|
108
116
|
} finally {
|
|
109
117
|
db.close()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// sk tmp: the machine's temp folders (home/machine-temp.ts): what the last pass measured, with no walk, the pass run
|
|
2
|
+
// now, and the daemon's switch. Every module loads inside execute: the cli registers this file on every `sk` call
|
|
3
|
+
import { Command, Option } from 'clipanion'
|
|
4
|
+
|
|
5
|
+
const DETAILS = `agents and test runs write into three temp roots nothing else trims: claude code's session scratch (/tmp/claude-<uid>/<project>/<session>/), the user's temp dir and /tmp. One pass deletes each unit nothing wrote for 24 h that no live process holds open, has as its working folder or names on its command line or in its environment, and that holds no git work a remote lacks; while the disk is under 40 GB free, units idle 6 h go too, the largest first, until it is back over. A unit is a child of a root, and inside a claude session each piece of its scratchpad, so a session that runs for days loses its old pieces too. Nothing is deleted before the owner turns the switch on (--auto on); then the daemon runs the pass hourly, one process at a time on the machine. What a pass measured is kept, so this command answers at once, where a du over a temp root walks every file again. Page: wiki tools/shipkit/machine-temp.md`
|
|
6
|
+
|
|
7
|
+
type Ctx = { stdout: NodeJS.WritableStream; stderr: NodeJS.WritableStream }
|
|
8
|
+
const io = (c: Ctx): { out: (l: string) => void; err: (l: string) => void } => ({ out: (l) => void c.stdout.write(`${l}\n`), err: (l) => void c.stderr.write(`${l}\n`) })
|
|
9
|
+
|
|
10
|
+
export class TmpCommand extends Command {
|
|
11
|
+
static override paths = [['tmp']]
|
|
12
|
+
static override usage = Command.Usage({
|
|
13
|
+
category: 'Health',
|
|
14
|
+
description: 'the temp folders with no walk: free space, what each root holds, the largest units and why they stay',
|
|
15
|
+
details: DETAILS,
|
|
16
|
+
examples: [
|
|
17
|
+
['where the temp folders stand', 'sk tmp'],
|
|
18
|
+
['the daemon sweeps them hourly from now on', 'sk tmp --auto on'],
|
|
19
|
+
],
|
|
20
|
+
})
|
|
21
|
+
auto = Option.String('--auto', { description: 'on: the daemon\'s hourly retention sweep and sk tmp sweep delete idle temp units; off: nothing deletes (off until the owner turns it on)' })
|
|
22
|
+
top = Option.String('--top', '12', { description: 'how many of the largest kept units to name' })
|
|
23
|
+
|
|
24
|
+
async execute(): Promise<number> {
|
|
25
|
+
const { out, err } = io(this.context)
|
|
26
|
+
const t = await import('../home/machine-temp.ts')
|
|
27
|
+
if (this.auto !== undefined) {
|
|
28
|
+
if (this.auto !== 'on' && this.auto !== 'off') { err(`FAIL: --auto takes on or off, not ${this.auto}`); return 1 }
|
|
29
|
+
if (!t.setTempAuto(this.auto === 'on')) { err('FAIL: the machine db does not open: the switch is not set'); return 1 }
|
|
30
|
+
}
|
|
31
|
+
const { statfsSync } = await import('node:fs')
|
|
32
|
+
const { tmpdir } = await import('node:os')
|
|
33
|
+
const s = statfsSync(tmpdir())
|
|
34
|
+
const free = s.bavail * s.bsize
|
|
35
|
+
const hours = (ms: number): number => ms / 3_600_000
|
|
36
|
+
out(`disk ${t.gb(free)} free${free < t.TEMP_FLOOR_BYTES ? ` (under the ${t.TEMP_FLOOR_BYTES / 1e9} GB floor: units idle ${hours(t.TEMP_GUARD_LOW_MS)} h go too, the largest first, until it is back over)` : ` (a unit idle ${hours(t.TEMP_GUARD_MS)} h goes)`}`)
|
|
37
|
+
out(`the daemon's temp sweep ${t.tempAuto() ? 'on, hourly' : 'off (sk tmp --auto on turns it on)'}`)
|
|
38
|
+
const use = t.tempUse()
|
|
39
|
+
if (use == null) { out(t.tempAuto() ? 'not measured yet: the daemon\'s next hourly sweep measures' : 'not measured yet: a pass measures once the switch is on'); return 0 }
|
|
40
|
+
const mins = Math.round((Date.now() - use.at) / 60_000)
|
|
41
|
+
out(`last pass ${new Date(use.at).toISOString().slice(0, 16)}Z, ${mins} min ago, took ${(use.tookMs / 1000).toFixed(1)} s`)
|
|
42
|
+
for (const p of use.passes) out(`${p.id} ${p.root} kept ${t.gb(p.keptBytes)} in ${p.kept} units freed ${t.gb(p.freed)} in ${p.dropped}${p.failed > 0 ? ` ${p.failed} not deleted` : ''}`)
|
|
43
|
+
const top = use.passes.flatMap((p) => p.top).sort((a, b) => b.bytes - a.bytes).slice(0, Math.max(0, Number(this.top) || 0))
|
|
44
|
+
if (top.length > 0) out('the largest kept:')
|
|
45
|
+
for (const u of top) out(` ${u.floor === true ? 'at least ' : ''}${t.gb(u.bytes)} ${u.why} ${u.path}`)
|
|
46
|
+
out('a du or an rm -rf over a whole temp root walks every file again: this pass is the one walker. `sk tmp sweep` runs it now')
|
|
47
|
+
return 0
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class TmpSweepCommand extends Command {
|
|
52
|
+
static override paths = [['tmp', 'sweep']]
|
|
53
|
+
static override usage = Command.Usage({
|
|
54
|
+
category: 'Health',
|
|
55
|
+
description: 'one pass over the temp folders now: each idle unit no live process uses deleted, or named with --dry',
|
|
56
|
+
details: DETAILS,
|
|
57
|
+
examples: [
|
|
58
|
+
['what a pass would delete, nothing deleted', 'sk tmp sweep --dry'],
|
|
59
|
+
['a pass now', 'sk tmp sweep'],
|
|
60
|
+
['one pass the owner asked for, the switch still off', 'sk tmp sweep --once'],
|
|
61
|
+
],
|
|
62
|
+
})
|
|
63
|
+
dry = Option.Boolean('--dry', false, { description: 'name each unit the pass would delete (idle age, size) and the totals, delete nothing' })
|
|
64
|
+
once = Option.Boolean('--once', false, { description: 'one pass by hand though the switch is off: only when the owner asked for this run' })
|
|
65
|
+
|
|
66
|
+
async execute(): Promise<number> {
|
|
67
|
+
const { out, err } = io(this.context)
|
|
68
|
+
const { sweepTemp, tempAuto } = await import('../home/machine-temp.ts')
|
|
69
|
+
if (!this.dry && !this.once && !tempAuto()) {
|
|
70
|
+
err('FAIL: the owner\'s switch is off, so nothing is deleted: `sk tmp --auto on` is the owner\'s to turn on, `sk tmp sweep --dry` names what a pass would delete, and `--once` runs one pass when the owner asked for it')
|
|
71
|
+
return 1
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
return sweepTemp({ dry: this.dry, print: out, printErr: err }) == null ? 1 : 0
|
|
75
|
+
} catch (e) {
|
|
76
|
+
err(`FAIL: tmp sweep: ${e instanceof Error ? e.message : String(e)}`)
|
|
77
|
+
return 1
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const TMP_COMMANDS = [TmpCommand, TmpSweepCommand]
|
package/src/cli/cmd_Veille.ts
CHANGED
|
@@ -15,10 +15,10 @@ interface Here {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/** the identity named, else the one the current repo's Veille is */
|
|
18
|
-
async function run(context: Ctx, as: string | undefined, body: (h: Here) => Promise<number>): Promise<number> {
|
|
18
|
+
async function run(context: Ctx, as: string | undefined, cmd: string, body: (h: Here) => Promise<number>): Promise<number> {
|
|
19
19
|
const out = (l: string): void => void context.stdout.write(`${l}\n`)
|
|
20
20
|
try {
|
|
21
|
-
const { identityOf, hasVeille } = await import('../veille/identity.ts')
|
|
21
|
+
const { identities, identityOf, hasVeille } = await import('../veille/identity.ts')
|
|
22
22
|
const { veilleAt } = await import('../veille/routes.ts')
|
|
23
23
|
const { storeDir } = await import('../review/store.ts')
|
|
24
24
|
const { findRepoRoot } = await import('../ts/config.ts')
|
|
@@ -30,7 +30,11 @@ async function run(context: Ctx, as: string | undefined, body: (h: Here) => Prom
|
|
|
30
30
|
}
|
|
31
31
|
const here = root == null ? null : veilleAt(root)
|
|
32
32
|
const identity = as === undefined ? here?.identity : identityOf(as)
|
|
33
|
-
if (identity == null)
|
|
33
|
+
if (identity == null) {
|
|
34
|
+
const watched = identities().filter(hasVeille).map((x) => x.id)
|
|
35
|
+
const pick = watched.length === 0 ? 'no identity has a watch list yet' : `name one: ${watched.map((id) => `${cmd} --as ${id}`).join(', ')}`
|
|
36
|
+
throw new Error(`${as === undefined ? 'this repo shows no Veille' : `no identity ${as}`}: ${pick}`)
|
|
37
|
+
}
|
|
34
38
|
if (!hasVeille(identity)) throw new Error(`${identity.id} has no watch list (${identity.watchFile})`)
|
|
35
39
|
const asksDir = here != null && here.identity.id === identity.id ? storeDir(here.asks.root) : null
|
|
36
40
|
return await body({ out, identity, root, asksDir })
|
|
@@ -60,7 +64,7 @@ export class VeilleFeedCommand extends Command {
|
|
|
60
64
|
since = Option.String('--since', '24h', { description: 'the window: 90m, 24h, 3d, 7d' })
|
|
61
65
|
all = Option.Boolean('--all', false, { description: 'the expired and handled posts too' })
|
|
62
66
|
async execute(): Promise<number> {
|
|
63
|
-
return run(this.context, this.as, async (h) => {
|
|
67
|
+
return run(this.context, this.as, `sk ${this.path.join(' ')}`, async (h) => {
|
|
64
68
|
const { feedLine } = await import('../veille/desk.ts')
|
|
65
69
|
const { isPlatform } = await import('../veille/platforms.ts')
|
|
66
70
|
const { interactions } = await import('../veille/asks.ts')
|
|
@@ -97,7 +101,7 @@ export class VeilleReplyCommand extends Command {
|
|
|
97
101
|
text = Option.String('--text', { description: 'the reply' })
|
|
98
102
|
media = Option.String('--media', { description: 'a media file of the drafts it lends, repo relative' })
|
|
99
103
|
async execute(): Promise<number> {
|
|
100
|
-
return run(this.context, this.as, async (h) => {
|
|
104
|
+
return run(this.context, this.as, `sk ${this.path.join(' ')}`, async (h) => {
|
|
101
105
|
const { brief, mediaFor } = await import('../veille/desk.ts')
|
|
102
106
|
const { draftMedia } = await import('../social/media-of.ts')
|
|
103
107
|
const { oursOf, veilleOf } = await import('../veille/service.ts')
|
|
@@ -127,7 +131,7 @@ export class VeillePassCommand extends Command {
|
|
|
127
131
|
as = asOpt()
|
|
128
132
|
why = Option.String('--why', { required: true, description: 'the real reason, one line' })
|
|
129
133
|
async execute(): Promise<number> {
|
|
130
|
-
return run(this.context, this.as, async (h) => {
|
|
134
|
+
return run(this.context, this.as, `sk ${this.path.join(' ')}`, async (h) => {
|
|
131
135
|
const { oursOf, veilleOf } = await import('../veille/service.ts')
|
|
132
136
|
const { desk } = veilleOf(h.identity)
|
|
133
137
|
if (desk.feed({ all: true, ours: oursOf(h.identity) }).every((r) => r.key !== this.key)) throw new Error(`no post ${this.key} in the log: sk veille feed gives the keys`)
|
package/src/cli/cmd_Wiki.ts
CHANGED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// what the cli answers itself where the parser's own text costs a screen: the list of
|
|
2
|
+
// `<bin> <family> --help`, a family name typed as a command, and words no command has.
|
|
3
|
+
// the one constraint a reader breaks first: each answer is a few lines, never the whole registry
|
|
4
|
+
import { nearest } from '../core/nearest.ts'
|
|
5
|
+
import { type CommandRow, compactLine } from './cmd_Commands.ts'
|
|
6
|
+
import { FAMILY_PAGES, pageAt } from './family-pages.ts'
|
|
7
|
+
|
|
8
|
+
export type Said = { lines: string[]; code: number }
|
|
9
|
+
/** a command the parser held the line against, and why it did not fit when it says */
|
|
10
|
+
export type Candidate = { usage: string; reason: string | null }
|
|
11
|
+
/** the command words of a usage line: what stands between the binary and the first flag or argument */
|
|
12
|
+
const commandOf = (usage: string): string => {
|
|
13
|
+
const w = usage.split(' ').slice(1)
|
|
14
|
+
const n = w.findIndex((x) => !/^[a-z][\w-]*$/.test(x))
|
|
15
|
+
return (n < 0 ? w : w.slice(0, n)).join(' ')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const firstWord = (path: string): string => path.split(' ')[0]!
|
|
19
|
+
|
|
20
|
+
/** edits between two words, two swapped neighbours counting as one (`dnoe` for `done`) */
|
|
21
|
+
function editDistance(a: string, b: string): number {
|
|
22
|
+
let before: number[] = []
|
|
23
|
+
let row = Array.from({ length: b.length + 1 }, (_, i) => i)
|
|
24
|
+
for (let i = 1; i <= a.length; i++) {
|
|
25
|
+
const next = [i]
|
|
26
|
+
for (let j = 1; j <= b.length; j++) {
|
|
27
|
+
next[j] = Math.min(row[j]! + 1, next[j - 1]! + 1, row[j - 1]! + (a[i - 1] === b[j - 1] ? 0 : 1))
|
|
28
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) next[j] = Math.min(next[j]!, before[j - 2]! + 1)
|
|
29
|
+
}
|
|
30
|
+
before = row
|
|
31
|
+
row = next
|
|
32
|
+
}
|
|
33
|
+
return row[b.length]!
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** the names one slip of the keyboard away from `want`: one edit, two for a word of five letters or more */
|
|
37
|
+
export function typoOf(want: string, have: readonly string[], max = 3): string[] {
|
|
38
|
+
const w = want.toLowerCase()
|
|
39
|
+
const reach = w.length >= 5 ? 2 : 1
|
|
40
|
+
return have
|
|
41
|
+
.map((n) => [n, editDistance(w, n.toLowerCase())] as const)
|
|
42
|
+
.filter(([, d]) => d <= reach)
|
|
43
|
+
.sort((a, b) => a[1] - b[1])
|
|
44
|
+
.slice(0, max)
|
|
45
|
+
.map(([n]) => n)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const count = (n: number): string => `${n} command${n === 1 ? '' : 's'}`
|
|
49
|
+
const flagsLine = (bin: string): string => `flags and examples of one: ${bin} <command> --help`
|
|
50
|
+
|
|
51
|
+
/** the list `<bin> <words> --help` prints when several commands start with those words: one line each, then
|
|
52
|
+
* the family's page. `self` is where the command that IS those words sits in the parser's list, when one does */
|
|
53
|
+
export function familyList(rows: readonly CommandRow[], bin: string, pages: Readonly<Record<string, string>> | null = FAMILY_PAGES): Said {
|
|
54
|
+
const words = rows.map((r) => r.path.split(' '))
|
|
55
|
+
let n = 0
|
|
56
|
+
while (words.every((w) => w[n] != null && w[n] === words[0]![n])) n++
|
|
57
|
+
const prefix = words[0]!.slice(0, n).join(' ')
|
|
58
|
+
const self = rows.findIndex((r) => r.path === prefix)
|
|
59
|
+
const families = new Set(rows.map((r) => r.category))
|
|
60
|
+
const page = families.size === 1 ? pages?.[[...families][0]!] : undefined
|
|
61
|
+
return {
|
|
62
|
+
code: 0,
|
|
63
|
+
lines: [
|
|
64
|
+
// no word in common (`asks` and `ask`): the first words stand in for it
|
|
65
|
+
`${bin} ${prefix === '' ? [...new Set(rows.map((r) => firstWord(r.path)))].join(', ') : prefix}: ${count(rows.length)}`,
|
|
66
|
+
...rows.map((r) => compactLine(r, bin)),
|
|
67
|
+
`${flagsLine(bin)}${self < 0 ? '' : `; the help of ${bin} ${prefix} alone: ${bin} ${prefix} -h=${self}`}`,
|
|
68
|
+
...(page == null ? [] : [`Read first: ${pageAt(page)}`]),
|
|
69
|
+
],
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** words no command has. A family's name lists the family (exit 0 when help was asked). Anything else names
|
|
74
|
+
* the closest commands, or the one command that lists them all. Null: no word was typed */
|
|
75
|
+
export function unknownCommand(input: readonly string[], rows: readonly CommandRow[], bin: string, pages: Readonly<Record<string, string>> | null = FAMILY_PAGES, candidates: readonly Candidate[] = []): Said | null {
|
|
76
|
+
const flag = input.findIndex((a) => a.startsWith('-'))
|
|
77
|
+
const words = flag < 0 ? [...input] : input.slice(0, flag)
|
|
78
|
+
if (words.length === 0) return null
|
|
79
|
+
const typed = `${bin} ${words.join(' ')}`
|
|
80
|
+
// the parser found the command and the line does not fit it: its usage, never « no command »
|
|
81
|
+
// one command, and the typed words begin with its words: a few candidates alone prove nothing, since a word
|
|
82
|
+
// only a few commands start with (`wiki`, `hooks`) gives a short list too
|
|
83
|
+
const fits = [...new Set(candidates.map((c) => c.usage.replace(/ #\d+\b/g, ' <value>')))]
|
|
84
|
+
const held = [...new Set(candidates.map((c) => commandOf(c.usage)))]
|
|
85
|
+
if (held.length === 1 && held[0] !== '' && `${words.join(' ')} `.startsWith(`${held[0]} `)) {
|
|
86
|
+
const reason = candidates.find((c) => c.reason != null)?.reason?.replace(/\.$/, '') ?? 'a required flag or argument is missing'
|
|
87
|
+
return { code: 1, lines: [`FAIL: ${bin} ${input.join(' ')}: ${reason}`, ...fits.map((u) => ` usage: ${u}`), ` fix: ${bin} ${held[0]} --help`] }
|
|
88
|
+
}
|
|
89
|
+
const family = words.length === 1 ? [...new Set(rows.map((r) => r.category))].find((c) => c.toLowerCase() === words[0]!.toLowerCase()) : undefined
|
|
90
|
+
if (family != null) {
|
|
91
|
+
const mine = rows.filter((r) => r.category === family)
|
|
92
|
+
const help = input.includes('--help') || input.includes('-h')
|
|
93
|
+
const page = pages?.[family]
|
|
94
|
+
return {
|
|
95
|
+
code: help ? 0 : 1,
|
|
96
|
+
lines: [
|
|
97
|
+
help ? `${family}: a family of ${count(mine.length)}` : `FAIL: ${typed} is no command: ${family} is a family of ${count(mine.length)}`,
|
|
98
|
+
...mine.map((r) => compactLine(r, bin)),
|
|
99
|
+
flagsLine(bin),
|
|
100
|
+
...(page == null ? [] : [`Read first: ${pageAt(page)}`]),
|
|
101
|
+
],
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const paths = rows.map((r) => r.path)
|
|
105
|
+
const firsts = [...new Set(paths.map(firstWord))]
|
|
106
|
+
const rest = words.slice(1)
|
|
107
|
+
const close: string[] = []
|
|
108
|
+
const add = (s: string): void => { if (!close.includes(s)) close.push(s) }
|
|
109
|
+
if (words.length === 1 && firsts.includes(words[0]!)) {
|
|
110
|
+
// a word several commands start with and no command is: its list, as a refusal
|
|
111
|
+
const list = familyList(rows.filter((r) => firstWord(r.path) === words[0]), bin, pages)
|
|
112
|
+
return { code: 1, lines: [`FAIL: ${typed} is no command: ${list.lines[0]}`, ...list.lines.slice(1)] }
|
|
113
|
+
}
|
|
114
|
+
if (firsts.includes(words[0]!)) {
|
|
115
|
+
// the first word is a real one: the slip is in the words after it
|
|
116
|
+
// each command of that word against as many typed words as it has, so what follows the slip is kept
|
|
117
|
+
const near = paths
|
|
118
|
+
.filter((p) => firstWord(p) === words[0] && p.includes(' '))
|
|
119
|
+
.map((p) => ({ p, n: p.split(' ').length }))
|
|
120
|
+
.filter(({ p, n }) => typoOf(words.slice(0, n).join(' '), [p]).length > 0)
|
|
121
|
+
for (const { p, n } of near.slice(0, 2)) add([bin, p, ...words.slice(n)].join(' '))
|
|
122
|
+
add(`${bin} ${words[0]} --help`)
|
|
123
|
+
} else {
|
|
124
|
+
for (const f of [...typoOf(words[0]!, firsts), ...nearest(words[0]!, firsts, 3)]) {
|
|
125
|
+
const whole = [f, ...rest].join(' ')
|
|
126
|
+
add(paths.includes(whole) ? `${bin} ${whole}` : rest.length === 0 && paths.includes(f) && !paths.some((p) => p.startsWith(`${f} `)) ? `${bin} ${f}` : `${bin} ${f} --help`)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
code: 1,
|
|
131
|
+
lines: [
|
|
132
|
+
`FAIL: no command « ${typed} »`,
|
|
133
|
+
close.length > 0 ? ` fix: did you mean ${close.slice(0, 3).join(', ')} ?` : ` fix: ${bin} commands --compact lists every command, one line each`,
|
|
134
|
+
],
|
|
135
|
+
}
|
|
136
|
+
}
|
package/src/cli/family-pages.ts
CHANGED
|
@@ -36,22 +36,3 @@ export function pageAt(rel: string): string {
|
|
|
36
36
|
const home = homedir()
|
|
37
37
|
return abs.startsWith(`${home}/`) ? `~${abs.slice(home.length)}` : abs
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
type Listed = { contexts?: { commandClass: { usage?: { category?: string | null } } }[]; commands?: number[]; execute(): Promise<number | void>; context: { stdout: { write(s: string): unknown } } }
|
|
41
|
-
|
|
42
|
-
/** `sk <family> --help` lists the family's commands (clipanion's help for several matches): the family's page
|
|
43
|
-
* follows the list. Any other command passes through */
|
|
44
|
-
export function withFamilyPage<C extends object>(command: C, pages: Readonly<Record<string, string>> = FAMILY_PAGES): C {
|
|
45
|
-
const h = command as C & Listed
|
|
46
|
-
if (!Array.isArray(h.contexts) || !Array.isArray(h.commands) || h.commands.length < 2) return command
|
|
47
|
-
const families = new Set(h.commands.map((i) => h.contexts?.[i]?.commandClass.usage?.category ?? ''))
|
|
48
|
-
const page = families.size === 1 ? pages[[...families][0]!] : undefined
|
|
49
|
-
if (page == null) return command
|
|
50
|
-
const list = h.execute.bind(h)
|
|
51
|
-
h.execute = async () => {
|
|
52
|
-
const code = await list()
|
|
53
|
-
h.context.stdout.write(`Read first: ${pageAt(page)}\n`)
|
|
54
|
-
return code
|
|
55
|
-
}
|
|
56
|
-
return command
|
|
57
|
-
}
|
package/src/cli/kit/calls.ts
CHANGED
|
@@ -36,6 +36,41 @@ export type CallEnd = {
|
|
|
36
36
|
/** where a CLI's calls go: `<root>/.shipkit/logs/<bin>-calls.jsonl` */
|
|
37
37
|
export const callsFile = (root: string, bin: string): string => join(root, LAYOUT.logs, `${bin}-calls.jsonl`)
|
|
38
38
|
|
|
39
|
+
/** the path of the command `parse` resolves (a clipanion `cli.process`), what
|
|
40
|
+
* `matched` logs: `help` for a help request, null when no command matches */
|
|
41
|
+
export function commandPath(parse: () => object): string | null {
|
|
42
|
+
try {
|
|
43
|
+
const c = parse().constructor as { name: string; paths?: string[][] }
|
|
44
|
+
// a command's own help is clipanion's HelpCommand, which carries no path
|
|
45
|
+
const path = c.name === 'HelpCommand' ? 'help' : (c.paths?.[0]?.join(' ') ?? null)
|
|
46
|
+
return path?.startsWith('-') === true ? 'help' : path
|
|
47
|
+
} catch {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** the argv to run when `--help` comes after a command's own args (`review seen <id> --help`): clipanion reads help
|
|
53
|
+
* only right after a command's path, so the line is cut back to the longest prefix that parses as help. Any other
|
|
54
|
+
* argv, and one no prefix of which is help, runs as typed */
|
|
55
|
+
export function helpArgv(argv: readonly string[], parse: (argv: string[]) => object): string[] {
|
|
56
|
+
const isHelp = (a: string): boolean => a === '--help' || a === '-h'
|
|
57
|
+
// a command's help parses to clipanion's HelpCommand, which carries no path
|
|
58
|
+
const parsed = (a: string[]): string | null => {
|
|
59
|
+
try {
|
|
60
|
+
return parse(a).constructor.name
|
|
61
|
+
} catch {
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!argv.some(isHelp) || parsed([...argv]) !== null) return [...argv]
|
|
66
|
+
const words = argv.filter((a) => !isHelp(a))
|
|
67
|
+
for (let n = words.length; n >= 1; n--) {
|
|
68
|
+
const cut = [...words.slice(0, n), '--help']
|
|
69
|
+
if (parsed(cut) === 'HelpCommand') return cut
|
|
70
|
+
}
|
|
71
|
+
return [...argv]
|
|
72
|
+
}
|
|
73
|
+
|
|
39
74
|
/** the env prefix of a CLI: `my-tool` → `MY_TOOL` */
|
|
40
75
|
export const envPrefix = (bin: string): string => bin.toUpperCase().replace(/[^A-Z0-9]/g, '_')
|
|
41
76
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// pages, generated) and `calls` (the log, read back). The bar: the bare
|
|
5
5
|
// listing answers in well under a second.
|
|
6
6
|
import { type BaseContext, Builtins, Cli } from 'clipanion'
|
|
7
|
-
import { callsFile, logCall } from './calls.ts'
|
|
7
|
+
import { callsFile, commandPath, logCall } from './calls.ts'
|
|
8
8
|
import { type Family, familiesFor, listing, listingOf, rootClashes } from './families.ts'
|
|
9
9
|
import type { AskTool, CommandClass, KitContext } from './verb.ts'
|
|
10
10
|
|
|
@@ -47,16 +47,6 @@ export async function projectCli(spec: ProjectCliSpec, argv: readonly string[],
|
|
|
47
47
|
return { cli, context: { root: spec.root, cwd, classes, askTool: spec.askTool } }
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/** the path of the command a call runs, null when none matches */
|
|
51
|
-
function commandOf(cli: Cli<KitContext>, argv: string[], context: KitExtra): string | null {
|
|
52
|
-
try {
|
|
53
|
-
const path = (cli.process(argv, context).constructor as { paths?: string[][] }).paths?.[0]?.join(' ') ?? null
|
|
54
|
-
return path?.startsWith('-') === true ? 'help' : path
|
|
55
|
-
} catch {
|
|
56
|
-
return null
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
50
|
const closedPipe = (e: unknown): boolean => e instanceof Error && 'code' in e && e.code === 'EPIPE'
|
|
61
51
|
|
|
62
52
|
/** the whole entry of a project CLI: log, load, then list or run */
|
|
@@ -66,7 +56,7 @@ export async function runProjectCli(spec: ProjectCliSpec, argv: string[] = proce
|
|
|
66
56
|
const call = logCall(callsFile(spec.root, spec.name), spec.name, argv)
|
|
67
57
|
const t0 = performance.now()
|
|
68
58
|
const { cli, context } = await projectCli(spec, argv)
|
|
69
|
-
call.matched(
|
|
59
|
+
call.matched(commandPath(() => cli.process(argv, context)), performance.now() - t0)
|
|
70
60
|
const word = listingOf(spec.name, argv, cli.definitions())
|
|
71
61
|
if (word !== null) { process.stdout.write(listing(spec.name, cli.definitions(), word, spec.label)); return }
|
|
72
62
|
await cli.runExit(argv, context)
|
package/src/cli/registry.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// (../cli.ts) loads it with an await import, so a file that fails to load is
|
|
4
4
|
// caught there. A new command registers here.
|
|
5
5
|
import { LIB_VERSION } from '../core/lib-version.ts'
|
|
6
|
-
import { Builtins, Cli,
|
|
6
|
+
import { Builtins, Cli, Command } from 'clipanion'
|
|
7
7
|
import { AskNewCommand, AsksCheckCommand, AsksCommand } from './cmd_Asks.ts'
|
|
8
8
|
import { AssetsAddCommand, AssetsCheckCommand, AssetsFillCommand, AssetsGenCommand, AssetsIdentityCommand } from './cmd_Assets.ts'
|
|
9
9
|
import { BumpCommand } from './cmd_Bump.ts'
|
|
@@ -11,8 +11,10 @@ import { CallsCommand } from './cmd_Calls.ts'
|
|
|
11
11
|
import { TimeCommand } from './cmd_Time.ts'
|
|
12
12
|
import { DrillCalibrateCommand, DrillCleanCommand, DrillCloneCommand, DrillCompareCommand, DrillFinishCommand, DrillReportCommand, DrillVerdictCommand } from './cmd_Drill.ts'
|
|
13
13
|
import { CheckCommand } from './cmd_Check.ts'
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { CapacityCommand } from './cmd_Capacity.ts'
|
|
15
|
+
import { LanesCommand } from './cmd_Lanes.ts'
|
|
16
|
+
import { type CommandRow, commandRows, CommandsCommand, type Definition } from './cmd_Commands.ts'
|
|
17
|
+
import { type Candidate, familyList, type Said, unknownCommand } from './family-help.ts'
|
|
16
18
|
import { CrossRepoActivityCommand } from './cmd_CrossRepoActivity.ts'
|
|
17
19
|
import { ConfigKeysCommand } from './cmd_ConfigKeys.ts'
|
|
18
20
|
import { GlobalProcessesCommand, GlobalProcessOpenCommand, GlobalProcessRestartCommand, GlobalProcessStartCommand, GlobalProcessStopCommand } from './cmd_GlobalProcesses.ts'
|
|
@@ -51,18 +53,55 @@ import { MEDIA_COMMANDS } from './cmd_Media.ts'
|
|
|
51
53
|
import { REC_COMMANDS } from './cmd_Rec.ts'
|
|
52
54
|
import { SignSetupCommand } from './cmd_Sign.ts'
|
|
53
55
|
import { ANNEX_COMMANDS } from './cmd_Annex.ts'
|
|
56
|
+
import { TMP_COMMANDS } from './cmd_Tmp.ts'
|
|
54
57
|
import { BACKUP_COMMANDS } from './cmd_Backup.ts'
|
|
55
58
|
import { VEILLE_COMMANDS } from './cmd_Veille.ts'
|
|
56
59
|
import { MESSAGES_COMMANDS } from './cmd_Messages.ts'
|
|
57
60
|
import { TuiCommand } from './cmd_Tui.ts'
|
|
58
|
-
import { SecretListCommand, SecretReadCommand, SecretSetCommand } from './cmd_Secret.ts'
|
|
61
|
+
import { SecretListCommand, SecretReadCommand, SecretSetCommand, SecretCopyCommand } from './cmd_Secret.ts'
|
|
59
62
|
import { WikiLintCommand, WikiServeCommand } from './cmd_Wiki.ts'
|
|
60
63
|
|
|
61
64
|
|
|
62
|
-
/**
|
|
65
|
+
/** an answer the cli gives itself: a few lines and an exit code */
|
|
66
|
+
class SaidCommand extends Command {
|
|
67
|
+
said: Said = { lines: [], code: 0 }
|
|
68
|
+
async execute(): Promise<number> {
|
|
69
|
+
this.context.stdout.write(`${this.said.lines.join('\n')}\n`)
|
|
70
|
+
return this.said.code
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const say = (said: Said): Command => Object.assign(new SaidCommand(), { said })
|
|
74
|
+
|
|
75
|
+
type Listed = { contexts?: { commandClass: { paths?: string[][] } }[]; commands?: number[]; index?: number }
|
|
76
|
+
|
|
77
|
+
/** the parser's two screens become a few lines (cli/family-help.ts): the list of `sk <family> --help`, and
|
|
78
|
+
* words no command has */
|
|
63
79
|
class FamilyHelpCli extends Cli {
|
|
80
|
+
/** every class registered, so `sk commands` reads each command's marks (essential, film) */
|
|
81
|
+
readonly classes: Parameters<Cli['register']>[0][] = []
|
|
82
|
+
override register(c: Parameters<Cli['register']>[0]): void {
|
|
83
|
+
this.classes.push(c)
|
|
84
|
+
super.register(c)
|
|
85
|
+
}
|
|
86
|
+
private rows(): CommandRow[] {
|
|
87
|
+
return commandRows(this.definitions() as Definition[], [], this.binaryName, this.classes)
|
|
88
|
+
}
|
|
64
89
|
override process(...args: unknown[]): Command {
|
|
65
|
-
|
|
90
|
+
let command: Command
|
|
91
|
+
try {
|
|
92
|
+
command = (super.process as (...a: unknown[]) => Command).apply(this, args)
|
|
93
|
+
} catch (e) {
|
|
94
|
+
const input = Array.isArray(args[0]) ? (args[0] as string[]) : (args[0] as { input?: string[] } | undefined)?.input
|
|
95
|
+
const said = input != null && e instanceof Error && e.message.startsWith('Command not found') ? unknownCommand(input, this.rows(), this.binaryName, undefined, (e as { candidates?: Candidate[] }).candidates ?? []) : null
|
|
96
|
+
if (said == null) throw e
|
|
97
|
+
return say(said)
|
|
98
|
+
}
|
|
99
|
+
const h = command as Command & Listed
|
|
100
|
+
// the parser's help for several matches, with no index asked: its list
|
|
101
|
+
if (!Array.isArray(h.contexts) || !Array.isArray(h.commands) || h.commands.length < 2 || (h.index != null && h.index >= 0 && h.index < h.commands.length)) return command
|
|
102
|
+
const byPath = new Map(this.rows().map((r) => [r.path, r]))
|
|
103
|
+
const listed = h.commands.map((i) => byPath.get(h.contexts?.[i]?.commandClass.paths?.[0]?.join(' ') ?? ''))
|
|
104
|
+
return listed.every((r) => r != null) ? say(familyList(listed as CommandRow[], this.binaryName)) : command
|
|
66
105
|
}
|
|
67
106
|
}
|
|
68
107
|
|
|
@@ -75,7 +114,8 @@ export function buildCli(): Cli {
|
|
|
75
114
|
binaryName: 'sk',
|
|
76
115
|
binaryVersion: LIB_VERSION,
|
|
77
116
|
enableCapture: true, // console output pipes into the command streams (testable)
|
|
78
|
-
|
|
117
|
+
// off a terminal (every agent harness) colour codes are bytes nobody reads
|
|
118
|
+
enableColors: process.stdout.isTTY === true && (process.env.NO_COLOR ?? '') === '',
|
|
79
119
|
})
|
|
80
120
|
|
|
81
121
|
cli.register(Builtins.HelpCommand)
|
|
@@ -102,6 +142,7 @@ export function buildCli(): Cli {
|
|
|
102
142
|
for (const c of REC_COMMANDS) cli.register(c)
|
|
103
143
|
cli.register(SignSetupCommand)
|
|
104
144
|
for (const c of ANNEX_COMMANDS) cli.register(c)
|
|
145
|
+
for (const c of TMP_COMMANDS) cli.register(c)
|
|
105
146
|
for (const c of BACKUP_COMMANDS) cli.register(c)
|
|
106
147
|
for (const c of VEILLE_COMMANDS) cli.register(c)
|
|
107
148
|
for (const c of MESSAGES_COMMANDS) cli.register(c)
|
|
@@ -123,6 +164,7 @@ export function buildCli(): Cli {
|
|
|
123
164
|
cli.register(SecretListCommand)
|
|
124
165
|
cli.register(SecretReadCommand)
|
|
125
166
|
cli.register(SecretSetCommand)
|
|
167
|
+
cli.register(SecretCopyCommand)
|
|
126
168
|
cli.register(AssetsFillCommand)
|
|
127
169
|
cli.register(AssetsAddCommand)
|
|
128
170
|
cli.register(AssetsGenCommand)
|
|
@@ -154,6 +196,8 @@ export function buildCli(): Cli {
|
|
|
154
196
|
cli.register(TraceAuditCommand)
|
|
155
197
|
cli.register(UnitsAliasCommand)
|
|
156
198
|
cli.register(CommandsCommand)
|
|
199
|
+
cli.register(CapacityCommand)
|
|
200
|
+
cli.register(LanesCommand)
|
|
157
201
|
cli.register(CallsCommand)
|
|
158
202
|
cli.register(TimeCommand)
|
|
159
203
|
cli.register(DrillReportCommand)
|
|
@@ -165,5 +209,6 @@ export function buildCli(): Cli {
|
|
|
165
209
|
cli.register(DrillCalibrateCommand)
|
|
166
210
|
cli.register(ConfigKeysCommand)
|
|
167
211
|
|
|
212
|
+
CommandsCommand.registered = cli.classes
|
|
168
213
|
return cli
|
|
169
214
|
}
|
package/src/cli.ts
CHANGED
|
@@ -42,6 +42,7 @@ export const loadBoot = (cmd?: string) =>
|
|
|
42
42
|
// started when it is down (autostart.ts), before the command runs
|
|
43
43
|
if (import.meta.main) {
|
|
44
44
|
const raw = process.argv.slice(2)
|
|
45
|
+
const t0 = performance.now()
|
|
45
46
|
let m
|
|
46
47
|
try {
|
|
47
48
|
m = await loadBoot(raw[0])
|
|
@@ -50,12 +51,15 @@ if (import.meta.main) {
|
|
|
50
51
|
throw e
|
|
51
52
|
}
|
|
52
53
|
bootLoaded()
|
|
53
|
-
const [{ buildCli }, { aliasArgs }, { handoff }, { installOneLib }, { callsFile, logCall }, { autostart }, { linkMachineCopy }] = m
|
|
54
|
+
const [{ buildCli }, { aliasArgs }, { handoff }, { installOneLib }, { callsFile, commandPath, helpArgv, logCall }, { autostart }, { linkMachineCopy }] = m
|
|
54
55
|
const argv = aliasArgs(raw)
|
|
55
56
|
handoff(argv)
|
|
56
57
|
installOneLib()
|
|
57
58
|
await linkMachineCopy()
|
|
58
|
-
logCall(callsFile((await import('os')).homedir(), 'sk'), 'sk', argv)
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
const call = logCall(callsFile((await import('os')).homedir(), 'sk'), 'sk', argv)
|
|
60
|
+
const cli = buildCli()
|
|
61
|
+
const run = helpArgv(argv, (a) => cli.process(a))
|
|
62
|
+
call.matched(commandPath(() => cli.process(run)), performance.now() - t0)
|
|
63
|
+
await autostart(run)
|
|
64
|
+
void cli.runExit(run)
|
|
61
65
|
}
|
package/src/collections/pings.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type PingIo = {
|
|
|
22
22
|
/** additive desktop notification on macOS */
|
|
23
23
|
osascript?: boolean
|
|
24
24
|
/** the url appended to the message for what it pings, in the OFF-MACHINE
|
|
25
|
-
* form (
|
|
25
|
+
* form (this Mac's tailnet name, machine-host.ts), a phone can't resolve localhost: the home's
|
|
26
26
|
* inbox on that one item, or on the list for several */
|
|
27
27
|
link?: (fresh: NeedItem[]) => string | undefined
|
|
28
28
|
}
|