@able-autonomy/able 0.0.8 → 0.0.10
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 +12 -0
- package/config.ts +10 -2
- package/package.json +1 -1
- package/src/commit.ts +4 -3
- package/src/workspaces/ls.ts +46 -7
- package/src/workspaces/new.ts +2 -2
- package/src/workspaces/services.ts +6 -3
package/able.ts
CHANGED
|
@@ -106,6 +106,18 @@ if (command && modules[command]) {
|
|
|
106
106
|
await import(modules[command])
|
|
107
107
|
process.exit(0)
|
|
108
108
|
}
|
|
109
|
+
// An unknown command falls through to a just recipe, then a package.json script, with one dim line saying so.
|
|
110
|
+
async function fallback(name: string) {
|
|
111
|
+
const summary = Bun.which('just') ? Bun.spawnSync(['just', '--summary'], { stderr: 'ignore' }).stdout.toString().split(/\s+/) : []
|
|
112
|
+
if (summary.some((r) => r === name || r.startsWith(`${name}::`))) return ['just', name, ...args]
|
|
113
|
+
const pkg = Bun.file('package.json')
|
|
114
|
+
if ((await pkg.exists()) && (await pkg.json()).scripts?.[name]) return ['bun', 'run', name, ...args]
|
|
115
|
+
}
|
|
116
|
+
const delegate = command && command !== 'gh' ? await fallback(command) : undefined
|
|
117
|
+
if (delegate) {
|
|
118
|
+
console.error(`\x1b[2mable: no '${command}' command, running ${delegate.join(' ')}\x1b[0m`)
|
|
119
|
+
process.exit(Bun.spawnSync(delegate, { stdio: ['inherit', 'inherit', 'inherit'] }).exitCode ?? 1)
|
|
120
|
+
}
|
|
109
121
|
if (command !== 'gh') {
|
|
110
122
|
console.error(
|
|
111
123
|
"usage: able gh <gh arguments> run gh as Able's GitHub App\n able sync [--dry-run] file follow-ups and write ended weeks' records\n able config [--json] print the host's able.config.ts\n able commit \"<message>\" [<path>…] a pathspec commit after the touched folders' checks\n able push pushes this branch with its tags\n able ws <new|ls|current|refresh|merge|rm|start|stop|status|take> workspaces",
|
package/config.ts
CHANGED
|
@@ -28,8 +28,10 @@ export interface WorkspacesConfig {
|
|
|
28
28
|
onRemove?: Command[]
|
|
29
29
|
services?: Record<string, Service>
|
|
30
30
|
/** Shared resources with one holder at a time on a machine (the tunnel, the devices): `able ws take` runs `take` and
|
|
31
|
-
* records the holder. An `auto` one is taken by `able ws start` and goes back to its earlier holder at `able ws stop`.
|
|
32
|
-
|
|
31
|
+
* records the holder. An `auto` one is taken by `able ws start` and goes back to its earlier holder at `able ws stop`.
|
|
32
|
+
* `holder`, when set, is asked instead of that record by `able ws ls`: run in the main checkout, it prints the holding
|
|
33
|
+
* checkouts' slugs or paths, one per line, so a resource the host moves with its own tools still shows. */
|
|
34
|
+
resources?: Record<string, { take: Command; auto?: boolean; holder?: Command }>
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
export interface AbleConfig {
|
|
@@ -37,6 +39,9 @@ export interface AbleConfig {
|
|
|
37
39
|
* touches; kept fast. `merge`: run from the root after those, at `able ws merge` only (the cross-package checks).
|
|
38
40
|
* Any failure stops it. Release checks (builds, tests) come with the Release module (98). */
|
|
39
41
|
checks?: { commit?: Record<string, Command[]>; merge?: Command[] }
|
|
42
|
+
/** `trailers`: lines such as `Co-Authored-By: …`, added to every commit Able makes with `able commit` and
|
|
43
|
+
* `able ws new --brief` (and so `able sync`'s); a message that already ends with one is not given it twice. */
|
|
44
|
+
commit?: { trailers?: string[] }
|
|
40
45
|
workspaces?: WorkspacesConfig
|
|
41
46
|
/** The branch workspaces are cut from and merged into. */
|
|
42
47
|
trunk: string
|
|
@@ -46,6 +51,9 @@ export interface AbleConfig {
|
|
|
46
51
|
knowledge?: string
|
|
47
52
|
}
|
|
48
53
|
|
|
54
|
+
/** The `git commit` flags for the host's trailers. */
|
|
55
|
+
export const trailerArgs = (config: AbleConfig) => (config.commit?.trailers ?? []).flatMap((t) => ['--trailer', t])
|
|
56
|
+
|
|
49
57
|
/** Types and editor help for `able.config.ts`; returns the config unchanged. */
|
|
50
58
|
export const defineConfig = (config: AbleConfig): AbleConfig => config
|
|
51
59
|
|
package/package.json
CHANGED
package/src/commit.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { existsSync } from 'node:fs'
|
|
11
11
|
import { join, relative, resolve } from 'node:path'
|
|
12
|
-
import { loadConfig } from '../config.ts'
|
|
12
|
+
import { loadConfig, trailerArgs } from '../config.ts'
|
|
13
13
|
import { runChecks } from './checks.ts'
|
|
14
14
|
import { failOnMerge, git, gitLoud } from './git.ts'
|
|
15
15
|
import { bold, confirm, dim, fail, green } from './ui.ts'
|
|
@@ -45,11 +45,12 @@ for (const f of before) console.log(dim(` ${f}`))
|
|
|
45
45
|
if (argv.includes('--dry')) process.exit(0)
|
|
46
46
|
if (!argv.includes('--yes') && !confirm(`Run the checks and commit as "${msg}"?`)) fail('aborted; nothing committed')
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const config = await loadConfig(root)
|
|
49
|
+
if (!runChecks(config, before, at)) fail('a check failed; nothing committed')
|
|
49
50
|
|
|
50
51
|
// The checks may have formatted files, so the list is read again.
|
|
51
52
|
const paths = changed()
|
|
52
53
|
// A path that is gone (a deletion, a rename's old name) has nothing to add, but still goes into the commit.
|
|
53
54
|
const present = paths.filter((p) => existsSync(join(root, p)))
|
|
54
|
-
if ((present.length && !gitLoud(root, 'add', '--', ...present)) || !gitLoud(root, 'commit', '--quiet', '-m', msg, '--', ...paths)) fail('git commit failed')
|
|
55
|
+
if ((present.length && !gitLoud(root, 'add', '--', ...present)) || !gitLoud(root, 'commit', '--quiet', '-m', msg, ...trailerArgs(config), '--', ...paths)) fail('git commit failed')
|
|
55
56
|
console.log(`\n ${green('✓')} ${git(root, 'log', '--oneline', '-1')}\n`)
|
package/src/workspaces/ls.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
// able ws ls: the main checkout and every workspace, read live: offset, services, tree, shared resources held.
|
|
2
|
+
// A service counts as running when Able started it or its `ready` check answers; a resource's holders come from its
|
|
3
|
+
// `holder` command when the host gives one, otherwise from Able's record.
|
|
2
4
|
// With --json, only the workspaces (slug, branch, path, portOffset, createdAt), for a host's own tools (84).
|
|
3
5
|
|
|
4
6
|
import { existsSync } from 'node:fs'
|
|
7
|
+
import { resolve } from 'node:path'
|
|
8
|
+
import { loadConfig } from '../../config.ts'
|
|
5
9
|
import { dirtyCount, mainRoot, unpushedCount } from '../git.ts'
|
|
6
|
-
import {
|
|
10
|
+
import { shellFor, type Place } from '../run.ts'
|
|
11
|
+
import { bold, dim, red, yellow } from '../ui.ts'
|
|
12
|
+
import { answers } from './services.ts'
|
|
7
13
|
import { checkouts, holderOf, readState, running, workspaces } from './state.ts'
|
|
8
14
|
|
|
9
15
|
const main = mainRoot()
|
|
@@ -13,19 +19,52 @@ if (process.argv.includes('--json')) {
|
|
|
13
19
|
process.exit(0)
|
|
14
20
|
}
|
|
15
21
|
const rows = await checkouts(main, state)
|
|
22
|
+
const { services = {}, resources = {} } = (await loadConfig(main)).workspaces ?? {}
|
|
23
|
+
const home = rows[0]
|
|
24
|
+
|
|
25
|
+
const asked = (c: NonNullable<(typeof resources)[string]['holder']>, at: Place) => {
|
|
26
|
+
const { run, cwd } = typeof c === 'string' ? { run: c } : c
|
|
27
|
+
const sh = shellFor(at, run, cwd)
|
|
28
|
+
const r = Bun.spawnSync(sh.argv, { cwd: sh.cwd, env: sh.env, stdout: 'pipe', stderr: 'ignore' })
|
|
29
|
+
return r.exitCode === 0
|
|
30
|
+
? r.stdout
|
|
31
|
+
.toString()
|
|
32
|
+
.split('\n')
|
|
33
|
+
.map((l) => l.trim())
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
: []
|
|
36
|
+
}
|
|
37
|
+
const holders = Object.fromEntries(
|
|
38
|
+
Object.entries(resources).map(([name, r]) => {
|
|
39
|
+
if (!r.holder || !home) return [name, rows.filter((w) => holderOf(state, name) === w.slug).map((w) => w.slug)]
|
|
40
|
+
const lines = asked(r.holder, home)
|
|
41
|
+
return [name, rows.filter((w) => lines.some((l) => l === w.slug || resolve(home.path, l) === resolve(w.path))).map((w) => w.slug)]
|
|
42
|
+
}),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
const upCount = async (w: Place) => {
|
|
46
|
+
const started = await running(w.path)
|
|
47
|
+
const live = await Promise.all(Object.entries(services).map(async ([name, s]) => Boolean(started[name]) || (await answers(s, w))))
|
|
48
|
+
return live.filter(Boolean).length
|
|
49
|
+
}
|
|
50
|
+
const ups = await Promise.all(rows.map(upCount))
|
|
16
51
|
|
|
17
52
|
console.log(`\n${bold(' CHECKOUT OFFSET SERVICES TREE')}`)
|
|
18
|
-
|
|
19
|
-
const up =
|
|
53
|
+
rows.forEach((w, i) => {
|
|
54
|
+
const up = ups[i] ?? 0
|
|
20
55
|
let tree = yellow('directory missing')
|
|
21
56
|
if (existsSync(w.path)) {
|
|
22
57
|
const dirty = dirtyCount(w.path)
|
|
23
58
|
const ahead = unpushedCount(w.path)
|
|
24
59
|
tree = [dirty ? yellow(`${dirty} dirty`) : dim('clean'), ahead ? yellow(`${ahead} unpushed`) : dim('0 unpushed')].join(dim(' · '))
|
|
25
60
|
}
|
|
26
|
-
const holds = Object.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
61
|
+
const holds = Object.entries(holders)
|
|
62
|
+
.filter(([, slugs]) => slugs.includes(w.slug))
|
|
63
|
+
.map(([name, slugs]) => (slugs.length > 1 ? red(name) : name))
|
|
64
|
+
const column = up ? `${up} running`.padEnd(10) : dim('stopped'.padEnd(10))
|
|
65
|
+
console.log(` ${w.slug.padEnd(16)} ${String(w.portOffset).padEnd(7)} ${column} ${tree}${holds.length ? bold(` holds ${holds.join(' + ')}`) : ''}`)
|
|
66
|
+
})
|
|
67
|
+
for (const [name, slugs] of Object.entries(holders))
|
|
68
|
+
if (slugs.length > 1) console.log(red(`\n ${name} is held by ${slugs.join(' and ')} at once: able ws take ${name} in the one that should hold it`))
|
|
30
69
|
if (rows.length === 1) console.log(dim('\n no workspaces: able ws new <slug>'))
|
|
31
70
|
console.log()
|
package/src/workspaces/new.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { copyFileSync, existsSync, mkdirSync } from 'node:fs'
|
|
10
10
|
import { dirname, join, relative, resolve } from 'node:path'
|
|
11
|
-
import { loadConfig } from '../../config.ts'
|
|
11
|
+
import { loadConfig, trailerArgs } from '../../config.ts'
|
|
12
12
|
import { runChecks } from '../checks.ts'
|
|
13
13
|
import { count, failOnMerge, fetchTrunk, git, gitLoud, mainRoot } from '../git.ts'
|
|
14
14
|
import { runCommand } from '../run.ts'
|
|
@@ -49,7 +49,7 @@ if (args.includes('--brief')) {
|
|
|
49
49
|
if (git(main, 'status', '--porcelain', '--', file)) {
|
|
50
50
|
const at = { slug: 'main', path: main, portOffset: 0, main }
|
|
51
51
|
if (!runChecks(config, [file], at)) fail('a check failed; nothing committed')
|
|
52
|
-
if (!gitLoud(main, 'add', '--', file) || !gitLoud(main, 'commit', '--quiet', '-m', `journal: ${slug} brief`, '--', file)) fail('commit of the brief failed')
|
|
52
|
+
if (!gitLoud(main, 'add', '--', file) || !gitLoud(main, 'commit', '--quiet', '-m', `journal: ${slug} brief`, ...trailerArgs(config), '--', file)) fail('commit of the brief failed')
|
|
53
53
|
}
|
|
54
54
|
if (count(main, `origin/${trunk}..${trunk}`) && !gitLoud(main, 'push', '--quiet', 'origin', trunk)) fail(`push of ${trunk} failed`)
|
|
55
55
|
}
|
|
@@ -43,11 +43,14 @@ const portOpen = (port: number) =>
|
|
|
43
43
|
socket.on('error', () => done(false))
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
+
/** Whether a service's `ready` check answers right now; a service without one is unknown. */
|
|
47
|
+
export const answers = async (s: Service, at: Place) =>
|
|
48
|
+
s.ready ? ('port' in s.ready ? portOpen(s.ready.port + at.portOffset) : runCommand({ run: s.ready.cmd, cwd: s.cwd }, at, { quiet: true })) : false
|
|
49
|
+
|
|
46
50
|
async function ready(s: Service, at: Place, timeoutMs = 120_000): Promise<boolean> {
|
|
47
|
-
|
|
48
|
-
if (!check) return true
|
|
51
|
+
if (!s.ready) return true
|
|
49
52
|
for (const until = Date.now() + timeoutMs; Date.now() < until; await Bun.sleep(250)) {
|
|
50
|
-
if (
|
|
53
|
+
if (await answers(s, at)) return true
|
|
51
54
|
}
|
|
52
55
|
return false
|
|
53
56
|
}
|