@able-autonomy/able 0.0.21 → 0.2.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/able.ts +9 -2
- package/config.ts +11 -0
- package/package.json +1 -1
- package/src/bloat/apply.test.ts +81 -0
- package/src/bloat/apply.ts +49 -0
- package/src/{agents → bloat}/blocks.ts +2 -2
- package/src/{agents → bloat}/checks.ts +2 -2
- package/src/bloat/compare.ts +63 -0
- package/src/{agents → bloat}/findings.ts +11 -7
- package/src/{agents → bloat}/grid.ts +4 -4
- package/src/bloat/index.ts +258 -0
- package/src/{agents → bloat}/load.ts +2 -2
- package/src/{agents → bloat}/picker.ts +3 -3
- package/src/bloat/report.ts +286 -0
- package/src/{agents → bloat}/scan.ts +2 -2
- package/src/bloat/show.ts +79 -0
- package/src/bloat/steps.ts +32 -0
- package/src/{agents → bloat}/types.ts +48 -3
- package/src/commit.ts +2 -1
- package/src/git.ts +43 -2
- package/src/push.ts +2 -1
- package/src/ui.ts +3 -0
- package/src/workspaces/fixture.ts +49 -0
- package/src/workspaces/index.ts +3 -1
- package/src/workspaces/ls.ts +56 -11
- package/src/workspaces/merge.ts +29 -13
- package/src/workspaces/new.ts +17 -15
- package/src/workspaces/overlap.test.ts +53 -0
- package/src/workspaces/overlap.ts +86 -0
- package/src/workspaces/preview.test.ts +81 -0
- package/src/workspaces/preview.ts +162 -0
- package/src/workspaces/refresh.ts +26 -24
- package/src/workspaces/rm.ts +6 -1
- package/src/workspaces/services.ts +2 -2
- package/src/workspaces/state.ts +56 -9
- package/src/workspaces/trunk.test.ts +88 -0
- package/sync.ts +5 -2
- package/src/agents/index.ts +0 -198
- package/src/agents/report.ts +0 -211
- package/src/agents/show.ts +0 -73
- package/src/agents/steps.ts +0 -32
- /package/src/{agents → bloat}/kinds.ts +0 -0
package/src/agents/index.ts
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
// able agents: what a host's agent files load, the rules in them, and where each rule belongs (knowledge/product/modules/agents.md).
|
|
2
|
-
//
|
|
3
|
-
// able agents run every step in order, one line each
|
|
4
|
-
// able agents scan [--json|--grid] step 1: every agent file, its kind and size (--grid: one box per file)
|
|
5
|
-
// able agents load [--json] step 2: when each file loads, and the words at start per folder
|
|
6
|
-
// able agents blocks [--json|--grid] step 3: the files cut into blocks, with spans and stable ids (--grid: one square per block)
|
|
7
|
-
// able agents checks [--json|--grid] step 4: what the host already enforces (--grid: per folder, per tool)
|
|
8
|
-
// able agents classify [--json] step 5's result: the agent's findings checked against the blocks, drawn by kind
|
|
9
|
-
// able agents propose [--json] step 6's result: each rule not kept with its proposal, or what is still owed
|
|
10
|
-
// able agents report step 7: checks the findings and writes the run to <journal>/agents/<date>-<hhmm>.json
|
|
11
|
-
// able agents show [<run>] [--step <n>|--json] step 8: a run read back from its file (the latest by default)
|
|
12
|
-
// able agents pick [<yes|no> <n>…]… [--run <run>] step 9: the operator's picks in the latest run, or the one named
|
|
13
|
-
// (no arguments on a terminal: checkboxes)
|
|
14
|
-
//
|
|
15
|
-
// Read-only on the host's agent files: the only files written are the findings (by the skill) and the run file.
|
|
16
|
-
|
|
17
|
-
import { join, relative } from 'node:path'
|
|
18
|
-
import { hostRoot, loadConfig } from '../../config.ts'
|
|
19
|
-
import { confirm, dim, fail, green, tty } from '../ui.ts'
|
|
20
|
-
import * as blocks from './blocks.ts'
|
|
21
|
-
import * as checks from './checks.ts'
|
|
22
|
-
import * as findings from './findings.ts'
|
|
23
|
-
import * as grid from './grid.ts'
|
|
24
|
-
import * as load from './load.ts'
|
|
25
|
-
import { pickInteractive } from './picker.ts'
|
|
26
|
-
import * as report from './report.ts'
|
|
27
|
-
import * as scan from './scan.ts'
|
|
28
|
-
import * as show from './show.ts'
|
|
29
|
-
import { steps, who } from './steps.ts'
|
|
30
|
-
|
|
31
|
-
const [sub = '', ...args] = process.argv.slice(3)
|
|
32
|
-
const valued = ['--step', '--run']
|
|
33
|
-
const names = args.filter((a, i) => !a.startsWith('--') && !valued.includes(args[i - 1] ?? ''))
|
|
34
|
-
const option = (name: string) => (args.includes(name) ? args[args.indexOf(name) + 1] : undefined)
|
|
35
|
-
const stepArg = option('--step')
|
|
36
|
-
const json = args.includes('--json')
|
|
37
|
-
const asGrid = args.includes('--grid')
|
|
38
|
-
const root = hostRoot()
|
|
39
|
-
|
|
40
|
-
/** Each step's result, worked out once and shared by the steps after it. */
|
|
41
|
-
const once = <T>(f: () => T) => {
|
|
42
|
-
let value: { v: T } | undefined
|
|
43
|
-
return () => (value ??= { v: f() }).v
|
|
44
|
-
}
|
|
45
|
-
const files = once(() => scan.listFiles(root))
|
|
46
|
-
const entries = once(() => scan.scan(root, files()))
|
|
47
|
-
|
|
48
|
-
const scope = dim([` root ${root}`, ' scanned the root downwards, gitignored files skipped', ' outside folders above the root and ~/.claude/: counted in the load map (step 2)'].join('\n'))
|
|
49
|
-
|
|
50
|
-
/** A built step: its result, the line `run` prints, and its views. */
|
|
51
|
-
interface Built<T> {
|
|
52
|
-
result: () => T | Promise<T>
|
|
53
|
-
summary: (r: T) => string
|
|
54
|
-
render: (r: T) => string
|
|
55
|
-
grid?: (r: T) => string
|
|
56
|
-
}
|
|
57
|
-
const built = <T>(b: Built<T>) => b as Built<unknown>
|
|
58
|
-
|
|
59
|
-
const cut = once(() => blocks.blocks(root, entries()))
|
|
60
|
-
const classified = once(() => {
|
|
61
|
-
const f = findings.readFindings(join(root, findings.findingsPath))
|
|
62
|
-
return f && findings.check(f, cut().blocks)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
const journal = once(async () => (await loadConfig(root)).journal)
|
|
66
|
-
/** The latest run, or the one named on the command line: `show <run>`, `pick --run <run>`. */
|
|
67
|
-
const latest = once(async () => {
|
|
68
|
-
const path = report.findRun(root, await journal(), sub === 'show' ? names[0] : option('--run'))
|
|
69
|
-
return path ? { path, run: report.readRun(path) } : undefined
|
|
70
|
-
})
|
|
71
|
-
type Latest = Awaited<ReturnType<typeof latest>>
|
|
72
|
-
const requireLatest = async () => (await latest()) ?? fail(option('--run') || (sub === 'show' && names[0]) ? 'no such run' : 'no run yet: able agents report writes one')
|
|
73
|
-
/** Steps 7 to 9 all show the latest run; only their line in `run` differs. */
|
|
74
|
-
const latestView = (summary: (l: NonNullable<Latest>) => string, none: string) =>
|
|
75
|
-
built<Latest>({ result: latest, summary: (l) => (l ? summary(l) : none), render: (l) => (l ? show.render(l.run, l.path, root) : ' No run yet.') })
|
|
76
|
-
|
|
77
|
-
const views: Record<string, Built<unknown>> = {
|
|
78
|
-
scan: built({ result: entries, summary: scan.summary, render: (e) => `${scope}\n\n${scan.render(e)}`, grid: (e) => `${scope}\n\n${grid.files(e)}` }),
|
|
79
|
-
load: built({ result: once(() => load.load(root, entries())), summary: load.summary, render: load.render }),
|
|
80
|
-
blocks: built({ result: cut, summary: blocks.summary, render: blocks.render, grid: grid.blocks }),
|
|
81
|
-
checks: built({ result: once(() => checks.checks(root, entries(), files())), summary: checks.summary, render: checks.render, grid: (c) => grid.enforcement(c, entries()) }),
|
|
82
|
-
classify: built({
|
|
83
|
-
result: classified,
|
|
84
|
-
summary: (c) => (c ? findings.summary(c) : `not run: the skill writes ${findings.findingsPath}`),
|
|
85
|
-
render: (c) =>
|
|
86
|
-
c
|
|
87
|
-
? [grid.byKind(cut(), c), ...(c.errors.length ? ['', ' ERRORS', ...c.errors.map((e) => ` ${e}`)] : [])].join('\n')
|
|
88
|
-
: ` No findings yet: the skill (able-clean-agent-bloat) writes ${findings.findingsPath} at step 5.`,
|
|
89
|
-
}),
|
|
90
|
-
propose: built({
|
|
91
|
-
result: classified,
|
|
92
|
-
summary: (c) => (c ? findings.proposeSummary(c) : 'waits for classify'),
|
|
93
|
-
render: (c) =>
|
|
94
|
-
c
|
|
95
|
-
? c.rules
|
|
96
|
-
.filter((r) => r.kind !== 'keep')
|
|
97
|
-
.map(
|
|
98
|
-
(r) => ` ${r.kind.padEnd(12)} ${r.id}
|
|
99
|
-
${r.proposal ? `→ ${r.proposal.target}: ${r.proposal.change}` : dim('no proposal yet')}`,
|
|
100
|
-
)
|
|
101
|
-
.join('\n')
|
|
102
|
-
: ' No findings yet.',
|
|
103
|
-
}),
|
|
104
|
-
report: latestView((l) => `latest: ${relative(root, l.path)}`, 'not run yet'),
|
|
105
|
-
show: latestView(() => 'able agents show', 'no run yet'),
|
|
106
|
-
pick: latestView((l) => report.tally(l.run).line, 'no run yet'),
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** Step 7: refuses while the findings owe anything, then writes the run and shows it. */
|
|
110
|
-
async function writeReport() {
|
|
111
|
-
const c = classified()
|
|
112
|
-
if (!c) fail(`no findings: the skill writes ${findings.findingsPath} at steps 5 and 6`)
|
|
113
|
-
const owed = report.problems(c)
|
|
114
|
-
if (owed.length) fail(`the findings are not ready:\n${owed.map((p) => ` ${p}`).join('\n')}`)
|
|
115
|
-
const summaries: Record<string, string> = {}
|
|
116
|
-
for (const id of ['scan', 'load', 'blocks', 'checks', 'classify', 'propose']) summaries[id] = views[id].summary(await views[id].result())
|
|
117
|
-
const at = new Date()
|
|
118
|
-
const path = report.runPath(root, await journal(), at)
|
|
119
|
-
const before = report.findRun(root, await journal())
|
|
120
|
-
const run = report.build({
|
|
121
|
-
scan: entries(),
|
|
122
|
-
load: (await views.load.result()) as load.LoadMap,
|
|
123
|
-
blocks: cut(),
|
|
124
|
-
checks: (await views.checks.result()) as checks.Checks,
|
|
125
|
-
checked: c,
|
|
126
|
-
summaries,
|
|
127
|
-
root,
|
|
128
|
-
path,
|
|
129
|
-
at,
|
|
130
|
-
previous: before ? report.readRun(before) : undefined,
|
|
131
|
-
})
|
|
132
|
-
await report.saveRun(path, run)
|
|
133
|
-
console.log(`\n ${green('wrote')} ${relative(root, path)}\n\n${show.render(run, path, root)}\n`)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** Step 9: on a terminal with no arguments, the checkbox picker; otherwise `pick yes 1 3 5`, `pick no 2`, or both at
|
|
137
|
-
* once, `pick yes 1 3 no 2` (the dashboard's page records its checkboxes this way). */
|
|
138
|
-
async function writePicks() {
|
|
139
|
-
const l = await requireLatest()
|
|
140
|
-
let answers: Map<number, 'yes' | 'no'> | undefined
|
|
141
|
-
if (!names.length && tty && process.stdin.isTTY) {
|
|
142
|
-
answers = await pickInteractive(l.run, l.path, root)
|
|
143
|
-
if (!answers) return console.log('\n Nothing recorded.\n')
|
|
144
|
-
} else if (names[0] === 'yes' || names[0] === 'no') {
|
|
145
|
-
answers = new Map()
|
|
146
|
-
let answer: 'yes' | 'no' = names[0]
|
|
147
|
-
for (const x of names.slice(1))
|
|
148
|
-
if (x === 'yes' || x === 'no') answer = x
|
|
149
|
-
else if (/^\d+$/.test(x)) answers.set(Number(x), answer)
|
|
150
|
-
else fail(`not a finding number: ${x}`)
|
|
151
|
-
} else fail('usage: able agents pick [<yes|no> <n>…]… [--run <run>] (no arguments on a terminal opens the checkboxes)')
|
|
152
|
-
const unknown = await report.pick(l.path, l.run, answers)
|
|
153
|
-
if (unknown.length) fail(`no finding numbered ${unknown.join(', ')} in ${relative(root, l.path)}`)
|
|
154
|
-
const { yes, no, open } = report.tally(l.run)
|
|
155
|
-
if (json) return console.log(JSON.stringify({ run: relative(root, l.path), yes, no, open }))
|
|
156
|
-
console.log(`\n ${green('recorded')} ${yes} yes, ${no} no, ${open} not picked, in ${relative(root, l.path)}\n`)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async function run() {
|
|
160
|
-
console.log()
|
|
161
|
-
for (const step of steps.filter((s) => s.v1)) {
|
|
162
|
-
const label = ` ${String(step.n).padStart(2)} ${who[step.kind]} ${step.id.padEnd(10)}`
|
|
163
|
-
const view = views[step.id]
|
|
164
|
-
if (!view) {
|
|
165
|
-
console.log(`${label} ${dim('not built yet')}`)
|
|
166
|
-
continue
|
|
167
|
-
}
|
|
168
|
-
const started = performance.now()
|
|
169
|
-
const result = await view.result()
|
|
170
|
-
const summary = view.summary(result)
|
|
171
|
-
const done = result !== undefined ? `${green('ok')} ${dim(`${Math.round(performance.now() - started)}ms`)}` : ''
|
|
172
|
-
console.log(`${label} ${result !== undefined ? summary.padEnd(44) : dim(summary)} ${done}`.trimEnd())
|
|
173
|
-
}
|
|
174
|
-
console.log(dim('\n M mechanical (the CLI) · A agent · O operator (you)\n'))
|
|
175
|
-
// On a terminal, step 9 follows on: the latest run's unpicked findings, as checkboxes.
|
|
176
|
-
const l = await latest()
|
|
177
|
-
if (l && tty && process.stdin.isTTY && report.tally(l.run).open && confirm('Pick now?')) await writePicks()
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (sub === 'run') await run()
|
|
181
|
-
else if (sub === 'report') await writeReport()
|
|
182
|
-
else if (sub === 'pick') await writePicks()
|
|
183
|
-
else if (sub === 'show' && stepArg) {
|
|
184
|
-
const l = await requireLatest()
|
|
185
|
-
const id = l.run.steps.find((s) => String(s.n) === stepArg || s.id === stepArg)?.id
|
|
186
|
-
if (!id) fail(`no step ${stepArg}: 1 to ${l.run.steps.length}, or a name`)
|
|
187
|
-
console.log(`\n${show.step(l.run, id)}\n`)
|
|
188
|
-
} else if (sub === 'show' && json) console.log(JSON.stringify((await requireLatest()).run))
|
|
189
|
-
else if (views[sub]) {
|
|
190
|
-
const view = views[sub]
|
|
191
|
-
const r = await view.result()
|
|
192
|
-
console.log(json ? JSON.stringify(r) : `\n${asGrid && view.grid ? view.grid(r) : view.render(r)}\n`)
|
|
193
|
-
} else {
|
|
194
|
-
console.error(`usage: able agents run | ${Object.keys(views).join(' | ')} [--json] [--grid]`)
|
|
195
|
-
process.exit(sub ? 1 : 0)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export {}
|
package/src/agents/report.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
// Step 7, report: checks the agent's findings (every block classified, every rule not kept proposed), merges them with
|
|
2
|
-
// steps 1 to 4, works out the impact, and writes the run to `<journal>/agents/<yyyy-mm-dd>-<hhmm>.json`. Every run is
|
|
3
|
-
// kept. Step 9's picks are written into the same file by `able agents pick`. The run is the one source `show` and the
|
|
4
|
-
// dashboard read; it holds each rule's span, so a view can highlight its words.
|
|
5
|
-
//
|
|
6
|
-
// On disk (`able.agents@2`) a rule keeps no copy of its words or its path: both come from its block (the block's text
|
|
7
|
-
// at the rule's span), filled in again by `readRun`. `@1` runs, which stored both, still read.
|
|
8
|
-
|
|
9
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync } from 'node:fs'
|
|
10
|
-
import { dirname, join, relative } from 'node:path'
|
|
11
|
-
import type { Blocks } from './blocks.ts'
|
|
12
|
-
import type { Checks } from './checks.ts'
|
|
13
|
-
import type { Checked, Rule } from './findings.ts'
|
|
14
|
-
import { unproposed } from './findings.ts'
|
|
15
|
-
import { pickOrder, type Kind } from './kinds.ts'
|
|
16
|
-
import { chain, type LoadMap } from './load.ts'
|
|
17
|
-
import { countWords, type Entry } from './scan.ts'
|
|
18
|
-
import { runsDir, steps } from './steps.ts'
|
|
19
|
-
import type { Finding, Run } from './types.ts'
|
|
20
|
-
|
|
21
|
-
export type { Finding, Run }
|
|
22
|
-
|
|
23
|
-
export const format = 'able.agents@2'
|
|
24
|
-
|
|
25
|
-
/** The formats `readRun` reads: every one written so far. */
|
|
26
|
-
export const formats = ['able.agents@1', format] as const satisfies Run['format'][]
|
|
27
|
-
|
|
28
|
-
/** Kinds whose words leave the start-up set once applied: everything but keep, and a conflict until it is picked. */
|
|
29
|
-
const leaves = (k: Kind) => k !== 'keep' && k !== 'conflict'
|
|
30
|
-
|
|
31
|
-
export function runsFolder(root: string, journal: string) {
|
|
32
|
-
return join(root, journal, runsDir)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** The run files, oldest first. */
|
|
36
|
-
export function runs(root: string, journal: string) {
|
|
37
|
-
const dir = runsFolder(root, journal)
|
|
38
|
-
return existsSync(dir)
|
|
39
|
-
? readdirSync(dir)
|
|
40
|
-
.filter((f) => /^\d{4}-\d{2}-\d{2}-\d{4}\.json$/.test(f))
|
|
41
|
-
.sort()
|
|
42
|
-
.map((f) => join(dir, f))
|
|
43
|
-
: []
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** A run from its text, whichever format it was written in, with each rule's words and path filled in from its block. */
|
|
47
|
-
export function parseRun(text: string): Run {
|
|
48
|
-
const run = JSON.parse(text) as Run
|
|
49
|
-
if (!formats.includes(run.format)) throw new Error(`a run in format ${JSON.stringify(run.format)}: this able reads ${formats.join(' and ')}`)
|
|
50
|
-
const blockOf = new Map(run.blocks.blocks.map((b) => [b.id, b]))
|
|
51
|
-
for (const r of run.rules) {
|
|
52
|
-
const b = blockOf.get(r.block)
|
|
53
|
-
if (!b) continue
|
|
54
|
-
r.path ??= b.path
|
|
55
|
-
r.text ??= b.text.slice(r.span[0] - b.span[0], r.span[1] - b.span[0])
|
|
56
|
-
}
|
|
57
|
-
return run
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const readRun = (path: string) => parseRun(readFileSync(path, 'utf8'))
|
|
61
|
-
|
|
62
|
-
/** A run file by name or date prefix (`2026-11-16`, `2026-11-16-2240`), or the latest. */
|
|
63
|
-
export function findRun(root: string, journal: string, name?: string) {
|
|
64
|
-
const all = runs(root, journal)
|
|
65
|
-
return name
|
|
66
|
-
? all
|
|
67
|
-
.filter((p) =>
|
|
68
|
-
p
|
|
69
|
-
.split('/')
|
|
70
|
-
.at(-1)!
|
|
71
|
-
.startsWith(name.replace(/\.json$/, '')),
|
|
72
|
-
)
|
|
73
|
-
.at(-1)
|
|
74
|
-
: all.at(-1)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** What blocks the report: findings errors, blocks not classified, rules not proposed. */
|
|
78
|
-
export function problems(c: Checked) {
|
|
79
|
-
return [...c.errors, ...c.missing.map((id) => `${id}: not classified`), ...unproposed(c).map((r) => `${r.id}: ${r.kind}, no proposal yet`)]
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Step 9's tally: findings to pick, and the answers so far. */
|
|
83
|
-
export function tally(run: Run) {
|
|
84
|
-
const numbered = run.rules.filter((r) => r.n)
|
|
85
|
-
const yes = numbered.filter((r) => r.pick === 'yes').length
|
|
86
|
-
const no = numbered.filter((r) => r.pick === 'no').length
|
|
87
|
-
return { numbered: numbered.length, yes, no, open: numbered.length - yes - no, line: `${yes + no} of ${numbered.length} picked` }
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** Builds the run. `path` is where it will be written; `summaries` are steps 1 to 6's lines, the rest are worked out here. */
|
|
91
|
-
export function build(input: {
|
|
92
|
-
scan: Entry[]
|
|
93
|
-
load: LoadMap
|
|
94
|
-
blocks: Blocks
|
|
95
|
-
checks: Checks
|
|
96
|
-
checked: Checked
|
|
97
|
-
summaries: Record<string, string>
|
|
98
|
-
root: string
|
|
99
|
-
path: string
|
|
100
|
-
at: Date
|
|
101
|
-
/** The run before this one: its picks carry forward by rule id, so what was answered isn't asked again. */
|
|
102
|
-
previous?: Run
|
|
103
|
-
}): Run {
|
|
104
|
-
const { scan, load, blocks, checks, checked } = input
|
|
105
|
-
const earlier = new Map(input.previous?.rules.flatMap((r) => (r.pick ? [[r.id, r.pick] as const] : [])))
|
|
106
|
-
const blockOf = new Map(blocks.blocks.map((b) => [b.id, b]))
|
|
107
|
-
let n = 0
|
|
108
|
-
const rules = checked.rules
|
|
109
|
-
.map((r) => {
|
|
110
|
-
const b = blockOf.get(r.block)!
|
|
111
|
-
const line = b.lines[0] + b.text.slice(0, r.span[0] - b.span[0]).split('\n').length - 1
|
|
112
|
-
return { ...r, line, words: countWords(r.text) }
|
|
113
|
-
})
|
|
114
|
-
.sort((a, b) => pickOrder.indexOf(a.kind) - pickOrder.indexOf(b.kind) || a.path.localeCompare(b.path) || a.span[0] - b.span[0])
|
|
115
|
-
.map((r) => (r.kind === 'keep' ? r : { ...r, n: ++n, ...(earlier.has(r.id) && { pick: earlier.get(r.id) }) }))
|
|
116
|
-
|
|
117
|
-
// A rule counts at start for a folder when its file loads at start there: an instruction file or always-on rule in the
|
|
118
|
-
// folder's chain, or a skill's description.
|
|
119
|
-
const fileLoad = new Map(load.files.map((f) => [f.path, f]))
|
|
120
|
-
const atStart = (r: (typeof rules)[number], folder: string) => {
|
|
121
|
-
const f = fileLoad.get(r.path)
|
|
122
|
-
if (!f) return false
|
|
123
|
-
if (f.load === 'skill') return blockOf.get(r.block)?.heading[0] === 'description'
|
|
124
|
-
return (f.load === 'always' || f.load === 'folder') && chain(folder).includes(f.folder)
|
|
125
|
-
}
|
|
126
|
-
const folders = load.folders.map((f) => ({
|
|
127
|
-
folder: f.folder,
|
|
128
|
-
before: f.host,
|
|
129
|
-
after: f.host - rules.filter((r) => leaves(r.kind) && atStart(r, f.folder)).reduce((s, r) => s + r.words, 0),
|
|
130
|
-
}))
|
|
131
|
-
const byKind: Run['impact']['byKind'] = {}
|
|
132
|
-
for (const r of rules) {
|
|
133
|
-
const k = (byKind[r.kind] ??= { rules: 0, words: 0 })
|
|
134
|
-
k.rules++
|
|
135
|
-
k.words += r.words
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const pathRules = scan.some((e) => e.kind === 'rule')
|
|
139
|
-
const agentsMd = scan
|
|
140
|
-
.filter((e) => e.kind === 'instructions' && e.path.endsWith('CLAUDE.md') && !e.path.endsWith('CLAUDE.local.md'))
|
|
141
|
-
.map((e) => {
|
|
142
|
-
const dir = dirname(e.path)
|
|
143
|
-
const at = (name: string) => (dir === '.' ? name : `${dir}/${name}`)
|
|
144
|
-
const blockers = [
|
|
145
|
-
...(existsSync(join(input.root, at('CLAUDE.local.md'))) ? ['a CLAUDE.local.md beside it stops Claude reading AGENTS.md'] : []),
|
|
146
|
-
...(scan.some((x) => x.path === at('AGENTS.md')) ? ['an AGENTS.md already exists beside it: merge, do not overwrite'] : []),
|
|
147
|
-
...(pathRules && dir === '.' ? ['.claude/rules with paths: are Claude-only and stay where they are'] : []),
|
|
148
|
-
]
|
|
149
|
-
return { path: e.path, blockers }
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
const root = folders.find((f) => f.folder === '.')
|
|
153
|
-
const summaries: Record<string, string> = {
|
|
154
|
-
...input.summaries,
|
|
155
|
-
report: relative(input.root, input.path),
|
|
156
|
-
show: `${root ? root.before - root.after : 0} words leave the root's start`,
|
|
157
|
-
}
|
|
158
|
-
const run: Run = {
|
|
159
|
-
format,
|
|
160
|
-
at: input.at.toISOString(),
|
|
161
|
-
steps: steps.filter((s) => s.v1).map((s) => ({ n: s.n, id: s.id, kind: s.kind, summary: summaries[s.id] ?? '' })),
|
|
162
|
-
scan,
|
|
163
|
-
load,
|
|
164
|
-
blocks,
|
|
165
|
-
checks,
|
|
166
|
-
rules,
|
|
167
|
-
impact: { folders, byKind },
|
|
168
|
-
agentsMd,
|
|
169
|
-
}
|
|
170
|
-
run.steps.find((s) => s.id === 'pick')!.summary = tally(run).line
|
|
171
|
-
return run
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/** The run's file name: local date and time, so two runs a minute apart are both kept. */
|
|
175
|
-
export function runName(at = new Date()) {
|
|
176
|
-
const p = (v: number) => String(v).padStart(2, '0')
|
|
177
|
-
return `${at.getFullYear()}-${p(at.getMonth() + 1)}-${p(at.getDate())}-${p(at.getHours())}${p(at.getMinutes())}.json`
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/** Where a run taken at `at` is written. */
|
|
181
|
-
export const runPath = (root: string, journal: string, at: Date) => join(runsFolder(root, journal), runName(at))
|
|
182
|
-
|
|
183
|
-
/** JSON broken into lines down to the lists (rules, blocks, files), each of their items on one line: small, and still a
|
|
184
|
-
* readable diff. */
|
|
185
|
-
export function lines(value: unknown, depth = 0): string {
|
|
186
|
-
const flat = JSON.stringify(value)
|
|
187
|
-
if (value === null || typeof value !== 'object' || flat.length <= 100 || depth > 2 || (depth === 2 && !Array.isArray(value))) return flat
|
|
188
|
-
const pad = ' '.repeat(depth + 1)
|
|
189
|
-
const items = Array.isArray(value) ? value.map((v) => lines(v, depth + 1)) : Object.entries(value).map(([k, v]) => `${JSON.stringify(k)}: ${lines(v, depth + 1)}`)
|
|
190
|
-
const [open, close] = Array.isArray(value) ? ['[', ']'] : ['{', '}']
|
|
191
|
-
return `${open}\n${items.map((i) => pad + i).join(',\n')}\n${' '.repeat(depth)}${close}`
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/** Writes a run file, always in the current format; the one place its form on disk is set. */
|
|
195
|
-
export async function saveRun(path: string, run: Run) {
|
|
196
|
-
mkdirSync(dirname(path), { recursive: true })
|
|
197
|
-
const rules = run.rules.map(({ text: _text, path: _path, ...r }) => r)
|
|
198
|
-
await Bun.write(path, `${lines({ ...run, format, rules })}\n`)
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/** Step 9: records the operator's yes or no on numbered findings in the run, and saves it. */
|
|
202
|
-
export async function pick(path: string, run: Run, answers: Map<number, 'yes' | 'no'>) {
|
|
203
|
-
const known = new Set(run.rules.flatMap((r) => (r.n ? [r.n] : [])))
|
|
204
|
-
const unknown = [...answers.keys()].filter((x) => !known.has(x))
|
|
205
|
-
if (unknown.length) return unknown
|
|
206
|
-
for (const r of run.rules) if (r.n && answers.has(r.n)) r.pick = answers.get(r.n)
|
|
207
|
-
const step = run.steps.find((s) => s.id === 'pick')
|
|
208
|
-
if (step) step.summary = tally(run).line
|
|
209
|
-
await saveRun(path, run)
|
|
210
|
-
return unknown
|
|
211
|
-
}
|
package/src/agents/show.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// Step 8, show: a run read back from its file and printed as plain text, narrow enough for a terminal and a chat.
|
|
2
|
-
// `--step <n>` prints one step's full view from the same file, so any step can be looked at again later.
|
|
3
|
-
|
|
4
|
-
import { relative } from 'node:path'
|
|
5
|
-
import { dim } from '../ui.ts'
|
|
6
|
-
import * as blocks from './blocks.ts'
|
|
7
|
-
import * as checks from './checks.ts'
|
|
8
|
-
import * as grid from './grid.ts'
|
|
9
|
-
import { kinds, pickOrder } from './kinds.ts'
|
|
10
|
-
import * as load from './load.ts'
|
|
11
|
-
import { runName, tally, type Run } from './report.ts'
|
|
12
|
-
import { who } from './steps.ts'
|
|
13
|
-
import { clip, fit, n, render as renderScan } from './scan.ts'
|
|
14
|
-
|
|
15
|
-
/** One step's full view, from the run file. */
|
|
16
|
-
export function step(run: Run, id: string) {
|
|
17
|
-
// In reading order, as the file has them; the run stores them in pick order.
|
|
18
|
-
const checked = { rules: [...run.rules].sort((a, b) => a.span[0] - b.span[0]), missing: [], errors: [] }
|
|
19
|
-
const views: Record<string, () => string> = {
|
|
20
|
-
scan: () => renderScan(run.scan),
|
|
21
|
-
load: () => load.render(run.load),
|
|
22
|
-
blocks: () => blocks.render(run.blocks),
|
|
23
|
-
checks: () => checks.render(run.checks),
|
|
24
|
-
classify: () => grid.byKind(run.blocks, checked),
|
|
25
|
-
}
|
|
26
|
-
return views[id]?.() ?? ` Step ${id} has no view of its own: its result is in the findings below.\n\n${findings(run)}`
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function findings(run: Run) {
|
|
30
|
-
const out: string[] = []
|
|
31
|
-
const numbered = run.rules.filter((r) => r.n)
|
|
32
|
-
for (const kind of pickOrder) {
|
|
33
|
-
const list = numbered.filter((r) => r.kind === kind)
|
|
34
|
-
if (!list.length) continue
|
|
35
|
-
out.push(` ${kinds[kind].letter} ${kind.toUpperCase()} ${list.length} ${dim(`→ ${kinds[kind].becomes}`)}`)
|
|
36
|
-
for (const r of list) {
|
|
37
|
-
const pick = r.pick === 'yes' ? '[y]' : r.pick === 'no' ? '[n]' : '[ ]'
|
|
38
|
-
const rec = r.recommend ? dim(` rec ${r.recommend}`) : ''
|
|
39
|
-
out.push(` ${pick} ${String(r.n).padStart(2)} ${r.confidence.padEnd(4)} ${fit(`${r.path}:${r.line}`, 34).padEnd(34)} "${clip(r.text.replace(/\s+/g, ' '), 46)}"${rec}`)
|
|
40
|
-
out.push(` ${dim(clip(r.reason, 92))}`)
|
|
41
|
-
if (r.proposal) out.push(` → ${clip(r.proposal.target, 40)}: ${clip(r.proposal.change, 64)}`)
|
|
42
|
-
}
|
|
43
|
-
out.push('')
|
|
44
|
-
}
|
|
45
|
-
return out.join('\n')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function render(run: Run, path: string, root: string) {
|
|
49
|
-
const out: string[] = []
|
|
50
|
-
const { numbered } = tally(run)
|
|
51
|
-
out.push(
|
|
52
|
-
` RUN ${runName(new Date(run.at))
|
|
53
|
-
.replace(/\.json$/, '')
|
|
54
|
-
.replace(/-(\d\d)(\d\d)$/, ' $1:$2')} ${relative(root, path)} ${run.format}`,
|
|
55
|
-
'',
|
|
56
|
-
)
|
|
57
|
-
out.push(' STEPS')
|
|
58
|
-
for (const s of run.steps) out.push(` ${String(s.n).padStart(2)} ${who[s.kind as keyof typeof who]} ${s.id.padEnd(10)} ${s.summary}`)
|
|
59
|
-
|
|
60
|
-
out.push('', ` WORDS AT START, BY FOLDER (host files; tokens are about 1.3 x words)`)
|
|
61
|
-
out.push(` ${'folder'.padEnd(24)} ${'now'.padStart(6)} ${'after'.padStart(6)} ${'saved'.padStart(6)}`)
|
|
62
|
-
for (const f of run.impact.folders)
|
|
63
|
-
out.push(` ${clip(f.folder === '.' ? '(root)' : f.folder, 24).padEnd(24)} ${n(f.before).padStart(6)} ${n(f.after).padStart(6)} ${`-${n(f.before - f.after)}`.padStart(6)}`)
|
|
64
|
-
|
|
65
|
-
const kept = run.impact.byKind.keep
|
|
66
|
-
out.push('', ` FINDINGS ${numbered} to pick${kept ? `, ${kept.rules} rules kept` : ''} [y] yes [n] no [ ] not picked yet`, '')
|
|
67
|
-
out.push(findings(run))
|
|
68
|
-
|
|
69
|
-
out.push(' AGENTS.md (vendor-neutral; converting is version 2)')
|
|
70
|
-
for (const a of run.agentsMd) out.push(` ${a.path.padEnd(24)} ${a.blockers.length ? a.blockers.join('; ') : 'would convert: AGENTS.md, plus a CLAUDE.md of one line, @AGENTS.md'}`)
|
|
71
|
-
if (!run.agentsMd.length) out.push(' no CLAUDE.md files')
|
|
72
|
-
return out.join('\n')
|
|
73
|
-
}
|
package/src/agents/steps.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// The steps of a run, as data: `able agents run` walks them, the skill follows them, a dashboard page will show them.
|
|
2
|
-
|
|
3
|
-
export type StepKind = 'mechanical' | 'agent' | 'operator'
|
|
4
|
-
|
|
5
|
-
export interface Step {
|
|
6
|
-
n: number
|
|
7
|
-
/** The step's one name, also its command: `able agents <id>`. */
|
|
8
|
-
id: string
|
|
9
|
-
kind: StepKind
|
|
10
|
-
/** False for the steps that come after version 1. */
|
|
11
|
-
v1: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** The letter each kind of step shows as in `run` and `show`. */
|
|
15
|
-
export const who: Record<StepKind, string> = { mechanical: 'M', agent: 'A', operator: 'O' }
|
|
16
|
-
|
|
17
|
-
export const steps: Step[] = [
|
|
18
|
-
{ n: 1, id: 'scan', kind: 'mechanical', v1: true },
|
|
19
|
-
{ n: 2, id: 'load', kind: 'mechanical', v1: true },
|
|
20
|
-
{ n: 3, id: 'blocks', kind: 'mechanical', v1: true },
|
|
21
|
-
{ n: 4, id: 'checks', kind: 'mechanical', v1: true },
|
|
22
|
-
{ n: 5, id: 'classify', kind: 'agent', v1: true },
|
|
23
|
-
{ n: 6, id: 'propose', kind: 'agent', v1: true },
|
|
24
|
-
{ n: 7, id: 'report', kind: 'mechanical', v1: true },
|
|
25
|
-
{ n: 8, id: 'show', kind: 'mechanical', v1: true },
|
|
26
|
-
{ n: 9, id: 'pick', kind: 'operator', v1: true },
|
|
27
|
-
{ n: 10, id: 'apply', kind: 'agent', v1: false },
|
|
28
|
-
{ n: 11, id: 'compare', kind: 'mechanical', v1: false },
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
/** The folder runs are written to, under the host's journal. One name, so renaming the skill is one line. */
|
|
32
|
-
export const runsDir = 'agents'
|
|
File without changes
|