@able-autonomy/able 0.0.5 → 0.0.8
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/package.json +1 -1
- package/src/workspaces/merge.ts +7 -1
- package/src/workspaces/new.ts +25 -3
package/package.json
CHANGED
package/src/workspaces/merge.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// able ws merge ["message"] [--yes]: merges this workspace into the trunk, from inside it.
|
|
2
2
|
//
|
|
3
|
-
// Merges origin's trunk into `feat/<slug>`, runs the commit checks of every folder the branch changed and then the
|
|
3
|
+
// Refuses while the workspace's brief has no `## Ledger` (its close). Merges origin's trunk into `feat/<slug>`, runs the commit checks of every folder the branch changed and then the
|
|
4
4
|
// merge checks (decisions 73, 100), pushes `feat/<slug>` and merges it into origin's trunk as one merge commit,
|
|
5
5
|
// `Merge feat/<slug>`, which is how `able sync` finds it. A message commits what is still dirty first. The main checkout takes no part; afterwards it is
|
|
6
6
|
// fast-forwarded when it is on the trunk and nothing of its own is in the way.
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
// A conflict stops it with the files named: resolve them here, commit, and run it again. A push refused because the
|
|
9
9
|
// trunk moved meanwhile is the same: run it again, and it merges the newer trunk in.
|
|
10
10
|
|
|
11
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
12
|
+
import { join, relative } from 'node:path'
|
|
11
13
|
import { runChecks, runMergeChecks } from '../checks.ts'
|
|
12
14
|
import { count, dirtyCount, fetchTrunk, git, gitLoud, gitQuiet, lines, mergeOrFail } from '../git.ts'
|
|
13
15
|
import { bold, confirm, dim, fail, green, yellow } from '../ui.ts'
|
|
@@ -21,6 +23,10 @@ const { trunk } = config
|
|
|
21
23
|
const dirty = dirtyCount(ws.path)
|
|
22
24
|
if (dirty && !msg) fail(`${dirty} uncommitted file(s); commit them (able commit), or pass a message to commit them all at once`)
|
|
23
25
|
|
|
26
|
+
// The close goes in with the branch: a brief without its ledger is never merged (`able sync` reads that ledger).
|
|
27
|
+
const brief = join(ws.path, config.journal, 'workspaces', `${ws.slug}.md`)
|
|
28
|
+
if (existsSync(brief) && !readFileSync(brief, 'utf8').includes('\n## Ledger\n')) fail(`${relative(ws.path, brief)} has no ## Ledger; close the workspace first (the able-close-ws skill), then merge`)
|
|
29
|
+
|
|
24
30
|
fetchTrunk(ws.path, trunk)
|
|
25
31
|
const ahead = count(ws.path, `origin/${trunk}..HEAD`)
|
|
26
32
|
const behind = count(ws.path, `HEAD..origin/${trunk}`)
|
package/src/workspaces/new.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
// able ws new <slug> [--no-fetch]: a worktree on `feat/<slug>` cut from origin's trunk, in `workspaces.dir`, then
|
|
1
|
+
// able ws new <slug> [--brief] [--no-fetch]: a worktree on `feat/<slug>` cut from origin's trunk, in `workspaces.dir`, then
|
|
2
2
|
// what a worktree can't inherit: the host's `copy` files and its `onCreate` commands, with this workspace's facts in
|
|
3
3
|
// `ABLE_WS_*`. Services are not started: `able ws start` does that. Every check runs before anything is created.
|
|
4
|
+
//
|
|
5
|
+
// `--brief` first publishes the workspace's brief, `<journal>/workspaces/<slug>.md`, from the main checkout on the trunk:
|
|
6
|
+
// it commits that file alone after its checks, when it has changes, and pushes the trunk, so the cut carries it. It
|
|
7
|
+
// refuses while the trunk has other unpushed commits, which would leave with it.
|
|
4
8
|
|
|
5
9
|
import { copyFileSync, existsSync, mkdirSync } from 'node:fs'
|
|
6
10
|
import { dirname, join, relative, resolve } from 'node:path'
|
|
7
11
|
import { loadConfig } from '../../config.ts'
|
|
8
|
-
import {
|
|
12
|
+
import { runChecks } from '../checks.ts'
|
|
13
|
+
import { count, failOnMerge, fetchTrunk, git, gitLoud, mainRoot } from '../git.ts'
|
|
9
14
|
import { runCommand } from '../run.ts'
|
|
10
15
|
import { bold, dim, fail, green, yellow } from '../ui.ts'
|
|
11
16
|
import { branchOf, readState, workspaces, writeState } from './state.ts'
|
|
12
17
|
|
|
13
18
|
const args = process.argv.slice(4)
|
|
14
19
|
const slug = args.find((a) => !a.startsWith('-'))
|
|
15
|
-
if (!slug) fail('usage: able ws new <slug> [--no-fetch]')
|
|
20
|
+
if (!slug) fail('usage: able ws new <slug> [--brief] [--no-fetch]')
|
|
16
21
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) fail(`invalid name '${slug}': lowercase letters, digits and dashes only`)
|
|
17
22
|
|
|
18
23
|
const main = mainRoot()
|
|
@@ -32,6 +37,23 @@ const { ports } = ws
|
|
|
32
37
|
const portOffset = ports ? (Array.from({ length: ports.max }, (_, i) => (i + 1) * ports.step).find((o) => !taken.has(o)) ?? fail('no free port offset; remove a workspace first')) : 0
|
|
33
38
|
|
|
34
39
|
if (!args.includes('--no-fetch')) fetchTrunk(main, config.trunk)
|
|
40
|
+
|
|
41
|
+
if (args.includes('--brief')) {
|
|
42
|
+
const { trunk, journal } = config
|
|
43
|
+
const file = `${journal}/workspaces/${slug}.md`
|
|
44
|
+
if (!existsSync(join(main, file))) fail(`no brief at ${file}; write it first`)
|
|
45
|
+
if (git(main, 'rev-parse', '--abbrev-ref', 'HEAD') !== trunk) fail(`the main checkout is not on ${trunk}`)
|
|
46
|
+
failOnMerge(main)
|
|
47
|
+
const unpushed = git(main, 'log', '--oneline', `origin/${trunk}..${trunk}`)
|
|
48
|
+
if (unpushed) fail(`${trunk} has unpushed commits that would leave with the brief:\n${unpushed}`)
|
|
49
|
+
if (git(main, 'status', '--porcelain', '--', file)) {
|
|
50
|
+
const at = { slug: 'main', path: main, portOffset: 0, main }
|
|
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')
|
|
53
|
+
}
|
|
54
|
+
if (count(main, `origin/${trunk}..${trunk}`) && !gitLoud(main, 'push', '--quiet', 'origin', trunk)) fail(`push of ${trunk} failed`)
|
|
55
|
+
}
|
|
56
|
+
|
|
35
57
|
// Cut from origin's trunk: the main checkout's own branch may lag, and is the operator's to move.
|
|
36
58
|
const start = git(main, 'rev-parse', '--verify', '--quiet', `origin/${config.trunk}`) ? `origin/${config.trunk}` : config.trunk
|
|
37
59
|
|