@venizia/vulcan 0.4.8 → 0.4.9-1
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/base/extensions/vulcan-guards.ts +48 -41
- package/base/hooks/antigravity-guards.ts +4 -3
- package/base/hooks/codex-guards.ts +17 -6
- package/base/hooks/guard-git.ts +8 -8
- package/base/hooks/guard-manifest.ts +5 -5
- package/base/hooks/guard-outside.ts +8 -8
- package/base/hooks/guard-package.ts +6 -6
- package/base/hooks/guard-remote-hosts.ts +14 -9
- package/base/hooks/guard-scripting.ts +6 -6
- package/base/hooks/guard-writes.ts +20 -11
- package/base/hooks/post-tool.ts +4 -3
- package/base/hooks/prompt-submit.ts +4 -3
- package/base/hooks/session-start.ts +5 -3
- package/base/hooks/stop.ts +4 -3
- package/base/hooks/subagent-start.ts +2 -2
- package/base/make/vulcan.mk +1 -4
- package/base/skills/build-a-feature/SKILL.md +1 -1
- package/base/skills/docs-update/SKILL.md +11 -5
- package/base/skills/docs-update/evals/evals.json +1 -1
- package/base/skills/docs-writing/SKILL.md +1 -1
- package/base/skills/plan-a-change/references/spec-card.md +1 -1
- package/base/skills/ship/SKILL.md +1 -1
- package/base/skills/visualize-work/SKILL.md +29 -6
- package/base/skills/visualize-work/references/spec.md +16 -5
- package/package.json +5 -6
- package/src/agents/atlas-block.ts +43 -43
- package/src/agents/codex-hooks.ts +55 -52
- package/src/agents/common/types.ts +1 -1
- package/src/agents/detect.ts +19 -16
- package/src/agents/exclude.ts +97 -98
- package/src/agents/hooks-json.ts +41 -43
- package/src/agents/local.ts +46 -43
- package/src/agents/prompt.ts +45 -42
- package/src/agents/render.ts +203 -201
- package/src/agents/resolve.ts +133 -134
- package/src/agents/table.ts +12 -8
- package/src/cli.ts +3 -1
- package/src/commands/add.command.ts +2 -2
- package/src/commands/agents.command.ts +11 -17
- package/src/commands/clean.command.ts +6 -6
- package/src/commands/doctor.command.ts +6 -4
- package/src/commands/help.command.ts +11 -9
- package/src/commands/init.command.ts +14 -8
- package/src/commands/preset.command.ts +2 -2
- package/src/commands/profile.command.ts +43 -50
- package/src/commands/sync.command.ts +109 -111
- package/src/commands/upgrade.command.ts +85 -78
- package/src/commands/visualize.command.ts +20 -5
- package/src/commands/x.command.ts +55 -50
- package/src/common/format.ts +23 -21
- package/src/common/index.ts +2 -0
- package/src/common/json.ts +8 -5
- package/src/common/layout-folder.ts +96 -111
- package/src/common/paths.ts +14 -12
- package/src/common/record.ts +7 -0
- package/src/common/text.ts +7 -0
- package/src/config/common/constants.ts +13 -1
- package/src/config/common/types.ts +8 -1
- package/src/config/loader.ts +53 -48
- package/src/config/packages.ts +17 -11
- package/src/config/schema.ts +54 -7
- package/src/create/add-app.ts +604 -493
- package/src/create/add-lib.ts +249 -242
- package/src/create/bunfig.ts +26 -23
- package/src/create/checks.ts +36 -34
- package/src/create/common/constants.ts +1 -0
- package/src/create/common/failure.ts +10 -0
- package/src/create/common/index.ts +2 -0
- package/src/create/common/preset-path.ts +11 -0
- package/src/create/common/types.ts +7 -2
- package/src/create/diff.ts +21 -23
- package/src/create/dockerignore.ts +26 -24
- package/src/create/files.ts +7 -5
- package/src/create/init-monorepo.ts +78 -80
- package/src/create/lib-preset.ts +62 -61
- package/src/create/manifest-json.ts +10 -4
- package/src/create/names.ts +217 -210
- package/src/create/next.ts +27 -24
- package/src/create/plan.ts +15 -12
- package/src/create/preset-diff.ts +415 -240
- package/src/create/preset-menu.ts +40 -34
- package/src/create/preset.ts +207 -194
- package/src/create/process.ts +80 -71
- package/src/create/scratch.ts +49 -48
- package/src/create/workspace.ts +423 -398
- package/src/doctor/checks.ts +1069 -998
- package/src/doctor/makefile.ts +17 -13
- package/src/doctor/runner.ts +88 -116
- package/src/doctor/skills.ts +97 -95
- package/src/doctor/tags.ts +44 -41
- package/src/hooks/codex-patch.ts +27 -24
- package/src/hooks/command-view.ts +44 -39
- package/src/hooks/common/constants.ts +0 -3
- package/src/hooks/common/types.ts +15 -1
- package/src/hooks/decision.ts +38 -42
- package/src/hooks/guard-git.ts +52 -50
- package/src/hooks/guard-manifest.ts +58 -55
- package/src/hooks/guard-outside.ts +109 -88
- package/src/hooks/guard-package.ts +86 -77
- package/src/hooks/guard-scripting.ts +20 -15
- package/src/hooks/guard-writes.ts +169 -111
- package/src/hooks/owner-reply.ts +128 -128
- package/src/hooks/post-tool.ts +94 -93
- package/src/hooks/project-guards.ts +93 -55
- package/src/hooks/project-tmp.ts +27 -24
- package/src/hooks/remote-hosts.ts +157 -149
- package/src/hooks/session-digest.ts +99 -95
- package/src/hooks/shell.ts +519 -500
- package/src/hooks/subagent-card.ts +11 -7
- package/src/hooks/trusted-scripts.ts +158 -80
- package/src/init/common/types.ts +1 -1
- package/src/init/scaffold.ts +137 -134
- package/src/local/clean.ts +39 -37
- package/src/local/format.ts +21 -17
- package/src/local/scan.ts +146 -140
- package/src/manifest/render.ts +127 -112
- package/src/owner/card.ts +51 -46
- package/src/owner/profile.ts +100 -96
- package/src/owner/reply-switch.ts +9 -6
- package/src/owner/shape.ts +72 -70
- package/src/owner/survey.ts +175 -164
- package/src/owner/view.ts +62 -59
- package/src/owner/violations.ts +119 -123
- package/src/router.ts +4 -1
- package/src/rules/base.ts +15 -11
- package/src/rules/common/types.ts +1 -1
- package/src/rules/parser.ts +39 -32
- package/src/rules/slots.ts +8 -6
- package/src/signals/claims.ts +30 -28
- package/src/signals/classify.ts +36 -33
- package/src/signals/loop.ts +39 -37
- package/src/signals/state.ts +80 -85
- package/src/skills/frontmatter.ts +28 -28
- package/src/sync/agent-files.ts +217 -199
- package/src/sync/agent-removal.ts +62 -68
- package/src/sync/atlas-block.ts +45 -43
- package/src/sync/base-rules.ts +32 -30
- package/src/sync/claude-launch.ts +74 -37
- package/src/sync/common/constants.ts +4 -0
- package/src/sync/common/index.ts +1 -0
- package/src/sync/common/symlink.ts +9 -0
- package/src/sync/common/types.ts +2 -2
- package/src/sync/exclude.ts +77 -69
- package/src/sync/local-choice.ts +50 -47
- package/src/sync/planner.ts +64 -68
- package/src/sync/prune.ts +52 -48
- package/src/sync/settings.ts +167 -168
- package/src/ui/capability.ts +12 -7
- package/src/ui/keyboard.ts +35 -33
- package/src/ui/prompt.ts +81 -77
- package/src/visualize/assets.ts +379 -195
- package/src/visualize/charts.ts +188 -176
- package/src/visualize/compare-css.ts +31 -0
- package/src/visualize/compare-render.ts +196 -0
- package/src/visualize/compare-schema.ts +81 -0
- package/src/visualize/compare-validate.ts +126 -0
- package/src/visualize/constants.ts +29 -3
- package/src/visualize/diagrams.ts +189 -174
- package/src/visualize/gate.ts +136 -0
- package/src/visualize/grid-span.ts +34 -0
- package/src/visualize/icons.ts +9 -4
- package/src/visualize/index.ts +2 -0
- package/src/visualize/kinds-css.ts +54 -0
- package/src/visualize/kinds-render.ts +698 -0
- package/src/visualize/kinds-schema.ts +148 -0
- package/src/visualize/kinds-validate.ts +186 -0
- package/src/visualize/labels-vi.ts +109 -0
- package/src/visualize/labels.ts +53 -0
- package/src/visualize/layout.ts +112 -92
- package/src/visualize/page.ts +140 -114
- package/src/visualize/render.ts +158 -114
- package/src/visualize/schema.ts +21 -1
- package/src/visualize/sections.ts +401 -309
- package/src/visualize/sources.ts +270 -0
- package/src/visualize/theme.ts +474 -0
- package/src/visualize/validate.ts +15 -5
- package/src/wiki/anchors.ts +39 -37
- package/src/wiki/command.ts +4 -4
- package/src/wiki/source-links.ts +49 -49
package/src/local/clean.ts
CHANGED
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
import { spawnSync } from 'node:child_process';
|
|
2
2
|
import { existsSync, lstatSync, rmSync, unlinkSync } from 'node:fs';
|
|
3
3
|
import { LocalConstants } from './constants.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { LocalScan } from './scan.ts';
|
|
5
5
|
import type { ILocalEntry } from './scan.ts';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
interface ICleanPlan {
|
|
8
8
|
/** What the chosen scopes would remove. */
|
|
9
9
|
remove: ILocalEntry[];
|
|
10
10
|
/** In a chosen scope but not removable (an unmerged worktree, a worktree git could not read). */
|
|
11
11
|
keep: ILocalEntry[];
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/** What the chosen scopes hold: what `clean` would remove and what it keeps, with the reason. */
|
|
15
|
-
export const planClean = (opts: { root: string; scopes: string[]; now?: number }): ICleanPlan => {
|
|
16
|
-
const inScope = scanLocal({ root: opts.root, now: opts.now }).filter((entry) =>
|
|
17
|
-
opts.scopes.includes(entry.scope),
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
remove: inScope.filter((entry) => entry.removable),
|
|
22
|
-
keep: inScope.filter((entry) => !entry.removable),
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
14
|
const git = (opts: { cwd: string; args: string[] }): boolean =>
|
|
27
15
|
spawnSync('git', opts.args, {
|
|
28
16
|
cwd: opts.cwd,
|
|
@@ -33,7 +21,7 @@ const git = (opts: { cwd: string; args: string[] }): boolean =>
|
|
|
33
21
|
const removeEntry = (opts: { root: string; entry: ILocalEntry }): string | undefined => {
|
|
34
22
|
const { entry } = opts;
|
|
35
23
|
|
|
36
|
-
if (!
|
|
24
|
+
if (!LocalScan.isInside({ root: opts.root, path: entry.path })) {
|
|
37
25
|
return 'refused: the path is not inside .agents/local/';
|
|
38
26
|
}
|
|
39
27
|
|
|
@@ -61,28 +49,42 @@ const removeEntry = (opts: { root: string; entry: ILocalEntry }): string | undef
|
|
|
61
49
|
}
|
|
62
50
|
};
|
|
63
51
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
root: string;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (error === undefined) {
|
|
76
|
-
removed.push(entry);
|
|
77
|
-
} else {
|
|
78
|
-
failed.push({ entry, error });
|
|
79
|
-
}
|
|
52
|
+
export class LocalClean {
|
|
53
|
+
/** What the chosen scopes hold: what `clean` would remove and what it keeps, with the reason. */
|
|
54
|
+
static plan(opts: { root: string; scopes: string[]; now?: number }): ICleanPlan {
|
|
55
|
+
const inScope = LocalScan.scan({ root: opts.root, now: opts.now }).filter((entry) =>
|
|
56
|
+
opts.scopes.includes(entry.scope),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
remove: inScope.filter((entry) => entry.removable),
|
|
61
|
+
keep: inScope.filter((entry) => !entry.removable),
|
|
62
|
+
};
|
|
80
63
|
}
|
|
81
64
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
65
|
+
/** Removes the plan's entries, then prunes git's worktree list. Returns what went and what failed. */
|
|
66
|
+
static run(opts: { root: string; plan: ICleanPlan }): {
|
|
67
|
+
removed: ILocalEntry[];
|
|
68
|
+
failed: { entry: ILocalEntry; error: string }[];
|
|
69
|
+
} {
|
|
70
|
+
const removed: ILocalEntry[] = [];
|
|
71
|
+
const failed: { entry: ILocalEntry; error: string }[] = [];
|
|
72
|
+
|
|
73
|
+
for (const entry of opts.plan.remove) {
|
|
74
|
+
const error = removeEntry({ root: opts.root, entry });
|
|
75
|
+
|
|
76
|
+
if (error === undefined) {
|
|
77
|
+
removed.push(entry);
|
|
78
|
+
} else {
|
|
79
|
+
failed.push({ entry, error });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
86
82
|
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
// Pruned after any worktree entry goes, registered or not: git then forgets one whose folder is gone.
|
|
84
|
+
if (removed.some((entry) => entry.scope === 'worktrees')) {
|
|
85
|
+
git({ cwd: opts.root, args: ['worktree', 'prune'] });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return { removed, failed };
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/local/format.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
const UNITS = ['B', 'KB', 'MB', 'GB'];
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export class LocalFormat {
|
|
4
|
+
/** `1536` as `1.5 KB`: one decimal from KB up, whole bytes below. */
|
|
5
|
+
static formatBytes(opts: { bytes: number }): string {
|
|
6
|
+
let value = opts.bytes;
|
|
7
|
+
let unit = 0;
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
while (value >= 1024 && unit < UNITS.length - 1) {
|
|
10
|
+
value /= 1024;
|
|
11
|
+
unit += 1;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return unit === 0 ? `${value} B` : `${value.toFixed(1)} ${UNITS[unit]}`;
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
}
|
|
17
|
+
/** An age in the largest whole unit: `5m`, `3h`, `2d`. */
|
|
18
|
+
static formatAge(opts: { ageMs: number }): string {
|
|
19
|
+
const minutes = Math.floor(opts.ageMs / 60_000);
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
if (minutes < 60) {
|
|
22
|
+
return `${Math.max(minutes, 0)}m`;
|
|
23
|
+
}
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
return minutes < 60 * 24
|
|
26
|
+
? `${Math.floor(minutes / 60)}h`
|
|
27
|
+
: `${Math.floor(minutes / (60 * 24))}d`;
|
|
22
28
|
}
|
|
23
|
-
|
|
24
|
-
return minutes < 60 * 24 ? `${Math.floor(minutes / 60)}h` : `${Math.floor(minutes / (60 * 24))}d`;
|
|
25
|
-
};
|
|
29
|
+
}
|
package/src/local/scan.ts
CHANGED
|
@@ -28,7 +28,7 @@ interface IRegistered {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/** The newest modification time under `path`, itself included: a folder's own time moves only when its direct children do. */
|
|
31
|
-
|
|
31
|
+
const newestModifiedAt = (opts: { path: string }): number => {
|
|
32
32
|
let stat;
|
|
33
33
|
|
|
34
34
|
try {
|
|
@@ -48,7 +48,7 @@ export const newestModifiedAt = (opts: { path: string }): number => {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
/** The bytes under `path`, symlinks counted as themselves and never followed. */
|
|
51
|
-
|
|
51
|
+
const sizeOf = (opts: { path: string }): number => {
|
|
52
52
|
let stat;
|
|
53
53
|
|
|
54
54
|
try {
|
|
@@ -67,29 +67,6 @@ export const sizeOf = (opts: { path: string }): number => {
|
|
|
67
67
|
);
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
/**
|
|
71
|
-
* The real path of the project's `.agents/local/`, or `undefined` when there is none or it cannot be
|
|
72
|
-
* trusted: `.agents` or `.agents/local` is a symlink, or the folder resolves outside the project. Every
|
|
73
|
-
* scan and every removal starts here, so a link can never move them out of the project.
|
|
74
|
-
*/
|
|
75
|
-
export const localRootOf = (opts: { root: string }): string | undefined => {
|
|
76
|
-
const agents = join(opts.root, '.agents');
|
|
77
|
-
const local = join(opts.root, ProjectLayout.LOCAL_DIRECTORY);
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
if (lstatSync(agents).isSymbolicLink() || lstatSync(local).isSymbolicLink()) {
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const real = realpathSync(local);
|
|
85
|
-
const realRoot = realpathSync(opts.root);
|
|
86
|
-
|
|
87
|
-
return real.startsWith(`${realRoot}${sep}`) && lstatSync(real).isDirectory() ? real : undefined;
|
|
88
|
-
} catch {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
70
|
const git = (opts: { cwd: string; args: string[] }): string | undefined => {
|
|
94
71
|
const result = spawnSync('git', opts.args, {
|
|
95
72
|
cwd: opts.cwd,
|
|
@@ -100,43 +77,6 @@ const git = (opts: { cwd: string; args: string[] }): string | undefined => {
|
|
|
100
77
|
return result.status === 0 ? result.stdout : undefined;
|
|
101
78
|
};
|
|
102
79
|
|
|
103
|
-
/**
|
|
104
|
-
* The output of `git worktree list --porcelain -z`: records end with an extra NUL and fields are NUL
|
|
105
|
-
* separated, so a path with a line break or odd characters is read whole.
|
|
106
|
-
*/
|
|
107
|
-
export const parseWorktreeList = (opts: { output: string }): Map<string, IRegistered> => {
|
|
108
|
-
const map = new Map<string, IRegistered>();
|
|
109
|
-
|
|
110
|
-
for (const record of opts.output.split('\0\0')) {
|
|
111
|
-
const fields = record.split('\0').filter((field) => field !== '');
|
|
112
|
-
const path = fields.find((field) => field.startsWith('worktree '))?.slice('worktree '.length);
|
|
113
|
-
const branch = fields
|
|
114
|
-
.find((field) => field.startsWith('branch refs/heads/'))
|
|
115
|
-
?.slice('branch refs/heads/'.length);
|
|
116
|
-
const head = fields.find((field) => /^HEAD [0-9a-f]{7,64}$/.test(field))?.slice('HEAD '.length);
|
|
117
|
-
|
|
118
|
-
if (path !== undefined) {
|
|
119
|
-
map.set(existsSync(path) ? realpathSync(path) : path, { branch, head });
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return map;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
/** The registered worktrees of the repository at `root`; `undefined` when git cannot list them. */
|
|
127
|
-
const registeredWorktrees = (opts: { root: string }): Map<string, IRegistered> | undefined => {
|
|
128
|
-
const listed = git({ cwd: opts.root, args: ['worktree', 'list', '--porcelain', '-z'] });
|
|
129
|
-
|
|
130
|
-
return listed === undefined ? undefined : parseWorktreeList({ output: listed });
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
interface IVerdict {
|
|
134
|
-
state: string;
|
|
135
|
-
removable: boolean;
|
|
136
|
-
registered: boolean;
|
|
137
|
-
note: string;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
80
|
const classifyBranch = (opts: {
|
|
141
81
|
root: string;
|
|
142
82
|
real: string;
|
|
@@ -262,107 +202,173 @@ const isRealDirectory = (opts: { path: string }): boolean => {
|
|
|
262
202
|
}
|
|
263
203
|
};
|
|
264
204
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
205
|
+
export class LocalScan {
|
|
206
|
+
/** The registered worktrees of the repository at `root`; `undefined` when git cannot list them. */
|
|
207
|
+
private static registeredWorktrees(opts: { root: string }): Map<string, IRegistered> | undefined {
|
|
208
|
+
const listed = git({ cwd: opts.root, args: ['worktree', 'list', '--porcelain', '-z'] });
|
|
269
209
|
|
|
270
|
-
|
|
271
|
-
return [];
|
|
210
|
+
return listed === undefined ? undefined : LocalScan.parseWorktreeList({ output: listed });
|
|
272
211
|
}
|
|
273
212
|
|
|
274
|
-
|
|
275
|
-
|
|
213
|
+
/**
|
|
214
|
+
* The real path of the project's `.agents/local/`, or `undefined` when there is none or it cannot be
|
|
215
|
+
* trusted: `.agents` or `.agents/local` is a symlink, or the folder resolves outside the project. Every
|
|
216
|
+
* scan and every removal starts here, so a link can never move them out of the project.
|
|
217
|
+
*/
|
|
218
|
+
static localRootOf(opts: { root: string }): string | undefined {
|
|
219
|
+
const agents = join(opts.root, '.agents');
|
|
220
|
+
const local = join(opts.root, ProjectLayout.LOCAL_DIRECTORY);
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
if (lstatSync(agents).isSymbolicLink() || lstatSync(local).isSymbolicLink()) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const real = realpathSync(local);
|
|
228
|
+
const realRoot = realpathSync(opts.root);
|
|
276
229
|
|
|
277
|
-
|
|
278
|
-
|
|
230
|
+
return real.startsWith(`${realRoot}${sep}`) && lstatSync(real).isDirectory()
|
|
231
|
+
? real
|
|
232
|
+
: undefined;
|
|
233
|
+
} catch {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
279
237
|
|
|
280
|
-
|
|
281
|
-
|
|
238
|
+
/**
|
|
239
|
+
* The output of `git worktree list --porcelain -z`: records end with an extra NUL and fields are NUL
|
|
240
|
+
* separated, so a path with a line break or odd characters is read whole.
|
|
241
|
+
*/
|
|
242
|
+
static parseWorktreeList(opts: { output: string }): Map<string, IRegistered> {
|
|
243
|
+
const map = new Map<string, IRegistered>();
|
|
244
|
+
|
|
245
|
+
for (const record of opts.output.split('\0\0')) {
|
|
246
|
+
const fields = record.split('\0').filter((field) => field !== '');
|
|
247
|
+
const path = fields.find((field) => field.startsWith('worktree '))?.slice('worktree '.length);
|
|
248
|
+
const branch = fields
|
|
249
|
+
.find((field) => field.startsWith('branch refs/heads/'))
|
|
250
|
+
?.slice('branch refs/heads/'.length);
|
|
251
|
+
const head = fields
|
|
252
|
+
.find((field) => /^HEAD [0-9a-f]{7,64}$/.test(field))
|
|
253
|
+
?.slice('HEAD '.length);
|
|
254
|
+
|
|
255
|
+
if (path !== undefined) {
|
|
256
|
+
map.set(existsSync(path) ? realpathSync(path) : path, { branch, head });
|
|
257
|
+
}
|
|
282
258
|
}
|
|
283
259
|
|
|
284
|
-
|
|
285
|
-
|
|
260
|
+
return map;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Every entry of `.agents/local/`, with size, age and what may be removed. Nothing is followed outside it. */
|
|
264
|
+
static scan(opts: { root: string; now?: number }): ILocalEntry[] {
|
|
265
|
+
const local = LocalScan.localRootOf({ root: opts.root });
|
|
266
|
+
const now = opts.now ?? Date.now();
|
|
267
|
+
|
|
268
|
+
if (local === undefined) {
|
|
269
|
+
return [];
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const registered = LocalScan.registeredWorktrees({ root: opts.root });
|
|
273
|
+
const entries: ILocalEntry[] = [];
|
|
274
|
+
|
|
275
|
+
for (const layout of ProjectLayout.LOCAL_LAYOUT) {
|
|
276
|
+
const directory = join(local, layout.name);
|
|
277
|
+
|
|
278
|
+
if (!isRealDirectory({ path: directory })) {
|
|
286
279
|
continue;
|
|
287
280
|
}
|
|
288
281
|
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
282
|
+
for (const name of readdirSync(directory)) {
|
|
283
|
+
if (name === '.gitkeep') {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const path = join(directory, name);
|
|
288
|
+
const stat = lstatSync(path);
|
|
289
|
+
const ageMs = now - newestModifiedAt({ path });
|
|
290
|
+
const staleAfter =
|
|
291
|
+
'staleAfterDays' in layout ? layout.staleAfterDays * LocalConstants.DAY_MS : undefined;
|
|
292
|
+
let state: string = LocalStates.OK;
|
|
293
|
+
let removable = true;
|
|
294
|
+
let isRegistered = false;
|
|
295
|
+
let note = '';
|
|
296
|
+
|
|
297
|
+
if (layout.name === CleanScopes.WORKTREES) {
|
|
298
|
+
const verdict = classifyWorktree({
|
|
299
|
+
root: opts.root,
|
|
300
|
+
real: stat.isSymbolicLink() ? resolve(path) : realpathSync(path),
|
|
301
|
+
registered,
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
({ state, removable, registered: isRegistered, note } = verdict);
|
|
305
|
+
} else if (staleAfter !== undefined && ageMs > staleAfter) {
|
|
306
|
+
state = LocalStates.STALE;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
entries.push({
|
|
310
|
+
scope: layout.name,
|
|
311
|
+
name,
|
|
312
|
+
path,
|
|
313
|
+
bytes: sizeOf({ path }),
|
|
314
|
+
ageMs,
|
|
315
|
+
state,
|
|
316
|
+
removable,
|
|
317
|
+
isSymlink: stat.isSymbolicLink(),
|
|
318
|
+
registered: isRegistered,
|
|
319
|
+
note,
|
|
304
320
|
});
|
|
305
|
-
|
|
306
|
-
({ state, removable, registered: isRegistered, note } = verdict);
|
|
307
|
-
} else if (staleAfter !== undefined && ageMs > staleAfter) {
|
|
308
|
-
state = LocalStates.STALE;
|
|
309
321
|
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const profile = join(local, 'profile.json');
|
|
325
|
+
|
|
326
|
+
if (existsSync(profile)) {
|
|
327
|
+
const stat = lstatSync(profile);
|
|
310
328
|
|
|
311
329
|
entries.push({
|
|
312
|
-
scope:
|
|
313
|
-
name,
|
|
314
|
-
path,
|
|
315
|
-
bytes:
|
|
316
|
-
ageMs,
|
|
317
|
-
state,
|
|
318
|
-
removable,
|
|
330
|
+
scope: CleanScopes.PROFILE,
|
|
331
|
+
name: 'profile.json',
|
|
332
|
+
path: profile,
|
|
333
|
+
bytes: stat.size,
|
|
334
|
+
ageMs: now - stat.mtimeMs,
|
|
335
|
+
state: LocalStates.OK,
|
|
336
|
+
removable: true,
|
|
319
337
|
isSymlink: stat.isSymbolicLink(),
|
|
320
|
-
registered:
|
|
321
|
-
note,
|
|
338
|
+
registered: false,
|
|
339
|
+
note: '',
|
|
322
340
|
});
|
|
323
341
|
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const profile = join(local, 'profile.json');
|
|
327
342
|
|
|
328
|
-
|
|
329
|
-
const stat = lstatSync(profile);
|
|
330
|
-
|
|
331
|
-
entries.push({
|
|
332
|
-
scope: CleanScopes.PROFILE,
|
|
333
|
-
name: 'profile.json',
|
|
334
|
-
path: profile,
|
|
335
|
-
bytes: stat.size,
|
|
336
|
-
ageMs: now - stat.mtimeMs,
|
|
337
|
-
state: LocalStates.OK,
|
|
338
|
-
removable: true,
|
|
339
|
-
isSymlink: stat.isSymbolicLink(),
|
|
340
|
-
registered: false,
|
|
341
|
-
note: '',
|
|
342
|
-
});
|
|
343
|
+
return entries;
|
|
343
344
|
}
|
|
344
345
|
|
|
345
|
-
|
|
346
|
-
|
|
346
|
+
/**
|
|
347
|
+
* Whether `path` sits under the project's trusted `.agents/local/` once its parent is resolved; a final
|
|
348
|
+
* symlink is not followed. A symlinked `.agents` or `.agents/local` makes it false for everything.
|
|
349
|
+
*/
|
|
350
|
+
static isInside(opts: { root: string; path: string }): boolean {
|
|
351
|
+
const local = LocalScan.localRootOf({ root: opts.root });
|
|
347
352
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
*/
|
|
352
|
-
export const isInsideLocal = (opts: { root: string; path: string }): boolean => {
|
|
353
|
-
const local = localRootOf({ root: opts.root });
|
|
353
|
+
if (local === undefined) {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
354
356
|
|
|
355
|
-
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
357
|
+
const parent = resolve(opts.path, '..');
|
|
358
358
|
|
|
359
|
-
|
|
359
|
+
if (!existsSync(parent)) {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
360
362
|
|
|
361
|
-
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
363
|
+
const target = join(realpathSync(parent), resolve(opts.path).split(sep).at(-1) ?? '');
|
|
364
364
|
|
|
365
|
-
|
|
365
|
+
return target.startsWith(`${local}${sep}`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
366
368
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
+
interface IVerdict {
|
|
370
|
+
state: string;
|
|
371
|
+
removable: boolean;
|
|
372
|
+
registered: boolean;
|
|
373
|
+
note: string;
|
|
374
|
+
}
|