@vatio-ai/cli 0.72.0 → 0.75.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/lib/claude-session.mjs +18 -2
- package/lib/commands/chat.mjs +5 -1
- package/lib/commands/improve.mjs +3 -3
- package/lib/commands/support-commands.mjs +31 -4
- package/lib/config.mjs +5 -2
- package/lib/skills-hint.mjs +112 -28
- package/lib/workspace.mjs +30 -2
- package/package.json +1 -1
package/lib/claude-session.mjs
CHANGED
|
@@ -48,6 +48,15 @@ const SECRET_PATTERNS = [
|
|
|
48
48
|
]
|
|
49
49
|
];
|
|
50
50
|
|
|
51
|
+
// The people a session is about rather than the one who sends it: customers
|
|
52
|
+
// that came up in a query or a log. The team never needs who they were. A
|
|
53
|
+
// phone counts only in international form; a bare run of digits is as likely
|
|
54
|
+
// an id.
|
|
55
|
+
const PERSONAL_PATTERNS = [
|
|
56
|
+
[/(?<![\w.%+/-])(?!git@|no-?reply@)[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}\b/g, "[EMAIL]"],
|
|
57
|
+
[/(?<![\w+])\+\d(?:[ .-]?\d){7,14}\b/g, "[PHONE]"]
|
|
58
|
+
];
|
|
59
|
+
|
|
51
60
|
export function claudeHome() {
|
|
52
61
|
return process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
|
|
53
62
|
}
|
|
@@ -120,10 +129,11 @@ export function describe(session) {
|
|
|
120
129
|
}
|
|
121
130
|
|
|
122
131
|
// The session as it is sent: only what was said and done, without images,
|
|
123
|
-
// with anything that looks like a secret
|
|
132
|
+
// with anything that looks like a secret, an email or a phone replaced and the
|
|
133
|
+
// home directory as ~.
|
|
124
134
|
export function clean(session) {
|
|
125
135
|
const lines = [];
|
|
126
|
-
const counts = { messages: 0, images: 0, redactions: 0 };
|
|
136
|
+
const counts = { messages: 0, images: 0, redactions: 0, personal: 0 };
|
|
127
137
|
let startedAt = null;
|
|
128
138
|
let endedAt = null;
|
|
129
139
|
let gitBranch = null;
|
|
@@ -197,6 +207,12 @@ function redact(text, counts) {
|
|
|
197
207
|
return replacement.replace(/\$(\d)/g, (_, index) => match[Number(index)] ?? "");
|
|
198
208
|
});
|
|
199
209
|
}
|
|
210
|
+
for (const [pattern, replacement] of PERSONAL_PATTERNS) {
|
|
211
|
+
result = result.replace(pattern, () => {
|
|
212
|
+
counts.personal += 1;
|
|
213
|
+
return replacement;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
200
216
|
return HOME.length > 1 ? result.replaceAll(HOME, "~") : result;
|
|
201
217
|
}
|
|
202
218
|
|
package/lib/commands/chat.mjs
CHANGED
|
@@ -80,7 +80,11 @@ workspace has never met.`;
|
|
|
80
80
|
function client(config, options) {
|
|
81
81
|
const apiUrl = config.resolveApiUrl({ explicit: options.apiUrl });
|
|
82
82
|
const token = options.token ?? config.resolveToken();
|
|
83
|
-
if (!apiUrl)
|
|
83
|
+
if (!apiUrl) {
|
|
84
|
+
// Says which: no vatio.yml here (and where one is), or one without `workspace:`.
|
|
85
|
+
config.resolveWorkspaceRequired();
|
|
86
|
+
fail("A workspace API url is required (--api-url, or base_url + a vatio.yml with `workspace:`)");
|
|
87
|
+
}
|
|
84
88
|
if (!token) fail("VATIO_TOKEN is required (env or `vatio login`)");
|
|
85
89
|
return new ApiClient({ baseUrl: apiUrl, token });
|
|
86
90
|
}
|
package/lib/commands/improve.mjs
CHANGED
|
@@ -57,7 +57,7 @@ export async function flags(config, args) {
|
|
|
57
57
|
const markdown = await fetchMarkdown(config, "/flags.md", "the flags");
|
|
58
58
|
if (!save) {
|
|
59
59
|
process.stdout.write(markdown);
|
|
60
|
-
printSkillsHint();
|
|
60
|
+
await printSkillsHint();
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -65,7 +65,7 @@ export async function flags(config, args) {
|
|
|
65
65
|
mkdirSync(dirname(target), { recursive: true });
|
|
66
66
|
writeFileSync(target, markdown);
|
|
67
67
|
console.log(`Wrote ${target}. Hand it to your coding agent; re-run \`vatio flags --save\` to refresh.`);
|
|
68
|
-
printSkillsHint();
|
|
68
|
+
await printSkillsHint();
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
// Each tool's calls, error rate, timeouts and p50/p95 latency over a period,
|
|
@@ -114,7 +114,7 @@ export async function evalCommand(config, args) {
|
|
|
114
114
|
|
|
115
115
|
const total = runs.reduce((sum, run) => sum + run.cases, 0);
|
|
116
116
|
console.error(`vatio: replaying ${total} case${total === 1 ? "" : "s"} on ${environment}…`);
|
|
117
|
-
printSkillsHint();
|
|
117
|
+
await printSkillsHint();
|
|
118
118
|
if (noWait) {
|
|
119
119
|
for (const run of runs) console.log(`Run ${run.id} (${run.agent}): vatio eval --show ${run.id}`);
|
|
120
120
|
return;
|
|
@@ -97,7 +97,8 @@ export async function shareSession(config, args) {
|
|
|
97
97
|
console.log(` ${size(Buffer.byteLength(transcript.jsonl))}, ${size(gzipped.length)} compressed`);
|
|
98
98
|
console.log(
|
|
99
99
|
` Left out: ${transcript.images > 0 ? `${transcript.images} image(s) and ` : ""}Claude Code's own bookkeeping.` +
|
|
100
|
-
(transcript.redactions > 0 ? ` ${transcript.redactions} thing(s) that looked like a key, token or password are [REDACTED].` : "")
|
|
100
|
+
(transcript.redactions > 0 ? ` ${transcript.redactions} thing(s) that looked like a key, token or password are [REDACTED].` : "") +
|
|
101
|
+
(transcript.personal > 0 ? ` ${transcript.personal} email address(es) and phone number(s) are [EMAIL] and [PHONE].` : "")
|
|
101
102
|
);
|
|
102
103
|
|
|
103
104
|
if (savePath) {
|
|
@@ -108,7 +109,10 @@ export async function shareSession(config, args) {
|
|
|
108
109
|
return;
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
console.log(
|
|
112
|
+
console.log(
|
|
113
|
+
"\nOnly the Vatio team reads it, to see where you and your coding agent got stuck. Every read is logged,\n" +
|
|
114
|
+
"and it is deleted 30 days after it arrives."
|
|
115
|
+
);
|
|
112
116
|
if (!yes) {
|
|
113
117
|
if (!process.stdin.isTTY) {
|
|
114
118
|
fail(
|
|
@@ -153,7 +157,8 @@ export async function shareSession(config, args) {
|
|
|
153
157
|
if (response.status === 401) fail("Your sign-in has expired. Run `vatio login`, then this again.");
|
|
154
158
|
if (!response.ok) fail(`Could not send it: ${body.error_description ?? `HTTP ${response.status}`}`);
|
|
155
159
|
|
|
156
|
-
console.log(`Sent to the Vatio team (#${body.id}). Thank you.`);
|
|
160
|
+
console.log(`Sent to the Vatio team (#${body.id}).${body.expires_at ? ` It is deleted on ${when(body.expires_at)}.` : ""} Thank you.`);
|
|
161
|
+
rememberSent(session.id, body.id);
|
|
157
162
|
rememberOffer(session.id);
|
|
158
163
|
}
|
|
159
164
|
|
|
@@ -201,6 +206,26 @@ function rememberOffer(sessionId) {
|
|
|
201
206
|
}
|
|
202
207
|
}
|
|
203
208
|
|
|
209
|
+
// Which sessions went, so `--list` can say so: when a permission check stops
|
|
210
|
+
// the coding agent and the developer sends it from a terminal, this is how the
|
|
211
|
+
// agent learns it arrived.
|
|
212
|
+
const SENT_KEPT = 20;
|
|
213
|
+
|
|
214
|
+
function rememberSent(sessionId, transcriptId) {
|
|
215
|
+
try {
|
|
216
|
+
const state = readOfferState();
|
|
217
|
+
const { [sessionId]: _previous, ...others } = sentSessions(state);
|
|
218
|
+
const sent = Object.entries({ ...others, [sessionId]: { id: transcriptId, at: new Date().toISOString() } });
|
|
219
|
+
writeOfferState({ ...state, sent: Object.fromEntries(sent.slice(-SENT_KEPT)) });
|
|
220
|
+
} catch {
|
|
221
|
+
// Not remembering only means `--list` does not mark it.
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function sentSessions(state = readOfferState()) {
|
|
226
|
+
return state.sent && typeof state.sent === "object" && !Array.isArray(state.sent) ? state.sent : {};
|
|
227
|
+
}
|
|
228
|
+
|
|
204
229
|
function offerStatePath() {
|
|
205
230
|
return join(configHome(), "share-session.json");
|
|
206
231
|
}
|
|
@@ -243,11 +268,13 @@ function listSessions() {
|
|
|
243
268
|
if (sessions.length === 0) fail("No Claude Code sessions for this directory.");
|
|
244
269
|
|
|
245
270
|
const current = process.env.CLAUDE_CODE_SESSION_ID;
|
|
271
|
+
const sent = sentSessions();
|
|
246
272
|
for (const session of sessions) {
|
|
247
273
|
const mark = session.id === current ? "*" : " ";
|
|
248
274
|
const title = session.title ? truncate(session.title, 60) : "";
|
|
249
275
|
const modified = when(new Date(session.modifiedAt).toISOString());
|
|
250
|
-
|
|
276
|
+
const shared = sent[session.id] ? ` (sent #${sent[session.id].id}, ${when(sent[session.id].at)})` : "";
|
|
277
|
+
console.log(`${mark} ${short(session.id)} ${modified} ${String(session.messages).padStart(5)} msgs ${title}${shared}`);
|
|
251
278
|
}
|
|
252
279
|
console.log("\nSend one with `vatio share-session --id ID`.");
|
|
253
280
|
}
|
package/lib/config.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "n
|
|
|
15
15
|
import { homedir } from "node:os";
|
|
16
16
|
import { dirname, join, resolve } from "node:path";
|
|
17
17
|
|
|
18
|
-
import { MANIFEST_FILE, SLUG_FORMAT, findWorkspaceRoot, manifestPath, workspaceSlug } from "./workspace.mjs";
|
|
18
|
+
import { MANIFEST_FILE, SLUG_FORMAT, findWorkspaceRoot, manifestPath, workspaceSlug, workspacesBelow } from "./workspace.mjs";
|
|
19
19
|
|
|
20
20
|
export const KEYS = ["base_url", "token"];
|
|
21
21
|
export const DEFAULT_BASE_URL = "https://vatio.ai";
|
|
@@ -122,9 +122,12 @@ export class Config {
|
|
|
122
122
|
|
|
123
123
|
workspaceRootRequired() {
|
|
124
124
|
if (this.workspaceRoot) return this.workspaceRoot;
|
|
125
|
+
const below = workspacesBelow(this.startDir);
|
|
125
126
|
throw new ConfigError(
|
|
126
127
|
`Not inside a Vatio workspace (no ${MANIFEST_FILE} found walking up from ${this.startDir}).\n` +
|
|
127
|
-
|
|
128
|
+
(below.length > 0
|
|
129
|
+
? `There is one in ${below.map((dir) => `./${dir}`).join(", ")}: run it from there (\`cd ${below[0]}\`).`
|
|
130
|
+
: "Run `vatio init SLUG` here to create one.")
|
|
128
131
|
);
|
|
129
132
|
}
|
|
130
133
|
|
package/lib/skills-hint.mjs
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
// "The Vatio skills are not installed here"
|
|
2
|
-
// improve loop. Without them Claude Code has
|
|
3
|
-
//
|
|
1
|
+
// "The Vatio skills are not installed here" -- or are older than the published
|
|
2
|
+
// ones -- after the commands of the improve loop. Without them Claude Code has
|
|
3
|
+
// no /vatio:vatio-improve, and with old ones it works the reports the way the
|
|
4
|
+
// skill said months ago.
|
|
4
5
|
//
|
|
5
6
|
// Installed means either copy: the Claude Code plugin (installed_plugins.json
|
|
6
|
-
// names vatio@<marketplace
|
|
7
|
-
// project's .claude/skills or .agents/skills
|
|
8
|
-
// it, or in ~/.claude/skills
|
|
7
|
+
// names vatio@<marketplace>, with its version), or the files
|
|
8
|
+
// `npx @vatio-ai/skills` puts in a project's .claude/skills or .agents/skills
|
|
9
|
+
// -- in this directory or one above it, or in ~/.claude/skills -- with the
|
|
10
|
+
// .vatio-skills-version it leaves beside each. A copy without that file
|
|
11
|
+
// predates it, so it is older than any version that writes one.
|
|
9
12
|
//
|
|
10
13
|
// Unlike the update notice it prints when stderr is not a terminal too: the
|
|
11
14
|
// reader is as often the coding agent running the command as a person. At
|
|
12
|
-
// most once a day per directory, and never in CI.
|
|
15
|
+
// most once a day per directory, and never in CI. The registry is asked for
|
|
16
|
+
// the latest skills at most once a day.
|
|
13
17
|
|
|
14
18
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
15
19
|
import { homedir } from "node:os";
|
|
@@ -19,65 +23,145 @@ import { configHome } from "./config.mjs";
|
|
|
19
23
|
import { paint } from "./support.mjs";
|
|
20
24
|
|
|
21
25
|
const SKILL = "vatio-improve";
|
|
26
|
+
const VERSION_FILE = ".vatio-skills-version";
|
|
27
|
+
const LATEST_URL = "https://registry.npmjs.org/@vatio-ai/skills/latest";
|
|
22
28
|
const SHOW_EVERY_MS = 24 * 60 * 60 * 1000;
|
|
29
|
+
const CHECK_EVERY_MS = 24 * 60 * 60 * 1000;
|
|
30
|
+
const FETCH_TIMEOUT_MS = 1_500;
|
|
23
31
|
|
|
24
|
-
export function printSkillsHint(startDir = process.cwd()) {
|
|
32
|
+
export async function printSkillsHint(startDir = process.cwd()) {
|
|
25
33
|
if (process.env.CI || process.env.VATIO_NO_SKILLS_HINT) return;
|
|
26
|
-
if (skillsInstalled(startDir)) return;
|
|
27
34
|
|
|
28
35
|
const path = join(configHome(), "skills-hint.json");
|
|
29
36
|
const key = resolve(startDir);
|
|
30
|
-
const state =
|
|
37
|
+
const state = readJson(path);
|
|
31
38
|
const last = Date.parse(state[key] ?? "");
|
|
32
39
|
if (!Number.isNaN(last) && Date.now() - last < SHOW_EVERY_MS) return;
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
);
|
|
38
|
-
|
|
41
|
+
const lines = hintLines(findSkills(startDir), await latestSkillsVersion());
|
|
42
|
+
if (lines.length === 0) return;
|
|
43
|
+
|
|
44
|
+
process.stderr.write(`\n${lines.map((line, i) => (i === 0 ? paint("yellow", line) : line)).join("\n")}\n`);
|
|
45
|
+
writeJson(path, { ...state, [key]: new Date().toISOString() });
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
export function
|
|
48
|
+
export function hintLines(found, latest) {
|
|
49
|
+
if (found.length === 0) {
|
|
50
|
+
return [
|
|
51
|
+
"The Vatio skills are not installed here, so Claude Code has no /vatio:vatio-improve.",
|
|
52
|
+
"To install them, run in this project: npx @vatio-ai/skills"
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
if (!latest) return [];
|
|
56
|
+
|
|
57
|
+
const lines = [];
|
|
58
|
+
const plugin = found.find((install) => install.kind === "plugin");
|
|
59
|
+
if (plugin?.version && isOlder(plugin.version, latest)) {
|
|
60
|
+
lines.push(
|
|
61
|
+
`The Vatio plugin for Claude Code is ${plugin.version}; ${latest} is out.`,
|
|
62
|
+
"To update it, run: claude plugin update vatio@vatio (or turn on auto-update in /plugin → Marketplaces → vatio)"
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
const copy = found.find((install) => install.kind === "copy");
|
|
66
|
+
if (copy && (!copy.version || isOlder(copy.version, latest))) {
|
|
67
|
+
lines.push(
|
|
68
|
+
`The Vatio skills copied into this project are ${copy.version ?? "older than 1.7.0"}; ${latest} is out.`,
|
|
69
|
+
"To update them, run in this project: npx @vatio-ai/skills"
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return lines;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Every copy Claude Code or another coding agent may load, nearest first.
|
|
76
|
+
export function findSkills(startDir) {
|
|
42
77
|
const claudeHome = String(process.env.CLAUDE_CONFIG_DIR ?? "").trim() || join(homedir(), ".claude");
|
|
43
|
-
|
|
44
|
-
|
|
78
|
+
const found = [];
|
|
79
|
+
const plugin = pluginVersion(join(claudeHome, "plugins", "installed_plugins.json"));
|
|
80
|
+
if (plugin !== undefined) found.push({ kind: "plugin", version: plugin });
|
|
45
81
|
|
|
46
82
|
let dir = resolve(startDir);
|
|
47
83
|
for (;;) {
|
|
48
|
-
|
|
84
|
+
for (const base of [join(dir, ".claude"), join(dir, ".agents")]) {
|
|
85
|
+
if (hasSkill(base)) found.push({ kind: "copy", version: copyVersion(base) });
|
|
86
|
+
}
|
|
49
87
|
const parent = dirname(dir);
|
|
50
|
-
if (parent === dir)
|
|
88
|
+
if (parent === dir) break;
|
|
51
89
|
dir = parent;
|
|
52
90
|
}
|
|
91
|
+
if (hasSkill(claudeHome)) found.push({ kind: "copy", version: copyVersion(claudeHome) });
|
|
92
|
+
return found;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function skillsInstalled(startDir) {
|
|
96
|
+
return findSkills(startDir).length > 0;
|
|
53
97
|
}
|
|
54
98
|
|
|
55
99
|
function hasSkill(base) {
|
|
56
100
|
return existsSync(join(base, "skills", SKILL, "SKILL.md"));
|
|
57
101
|
}
|
|
58
102
|
|
|
59
|
-
function
|
|
103
|
+
function copyVersion(base) {
|
|
104
|
+
try {
|
|
105
|
+
return readFileSync(join(base, "skills", SKILL, VERSION_FILE), "utf8").trim() || null;
|
|
106
|
+
} catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// undefined when no vatio plugin is installed, null when one is but its
|
|
112
|
+
// version is not where it was: the file's format is Claude Code's, not ours.
|
|
113
|
+
function pluginVersion(path) {
|
|
60
114
|
try {
|
|
61
115
|
const plugins = JSON.parse(readFileSync(path, "utf8"))?.plugins ?? {};
|
|
62
|
-
|
|
116
|
+
const name = Object.keys(plugins).find((candidate) => candidate.startsWith("vatio@"));
|
|
117
|
+
if (!name) return undefined;
|
|
118
|
+
const installs = Array.isArray(plugins[name]) ? plugins[name] : [ plugins[name] ];
|
|
119
|
+
const versions = installs.map((install) => install?.version).filter((v) => typeof v === "string");
|
|
120
|
+
return versions.sort((a, b) => (isOlder(a, b) ? 1 : -1))[0] ?? null;
|
|
121
|
+
} catch {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function latestSkillsVersion() {
|
|
127
|
+
const path = join(configHome(), "skills-check.json");
|
|
128
|
+
const cached = readJson(path);
|
|
129
|
+
if (typeof cached.latest === "string" && Date.now() - Date.parse(cached.checked_at ?? "") < CHECK_EVERY_MS) {
|
|
130
|
+
return cached.latest;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const response = await fetch(LATEST_URL, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
134
|
+
const latest = response.ok ? (await response.json())?.version : null;
|
|
135
|
+
if (typeof latest !== "string") return cached.latest ?? null;
|
|
136
|
+
writeJson(path, { checked_at: new Date().toISOString(), latest });
|
|
137
|
+
return latest;
|
|
63
138
|
} catch {
|
|
64
|
-
return
|
|
139
|
+
return cached.latest ?? null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function isOlder(version, than) {
|
|
144
|
+
const parse = (v) => String(v).split(".").map((part) => Number.parseInt(part, 10) || 0);
|
|
145
|
+
const [a, b] = [parse(version), parse(than)];
|
|
146
|
+
for (let i = 0; i < 3; i++) {
|
|
147
|
+
if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) < (b[i] ?? 0);
|
|
65
148
|
}
|
|
149
|
+
return false;
|
|
66
150
|
}
|
|
67
151
|
|
|
68
|
-
function
|
|
152
|
+
function readJson(path) {
|
|
69
153
|
try {
|
|
70
|
-
const
|
|
71
|
-
return
|
|
154
|
+
const value = JSON.parse(readFileSync(path, "utf8"));
|
|
155
|
+
return value && typeof value === "object" ? value : {};
|
|
72
156
|
} catch {
|
|
73
157
|
return {};
|
|
74
158
|
}
|
|
75
159
|
}
|
|
76
160
|
|
|
77
|
-
function
|
|
161
|
+
function writeJson(path, value) {
|
|
78
162
|
try {
|
|
79
163
|
mkdirSync(dirname(path), { recursive: true });
|
|
80
|
-
writeFileSync(path, JSON.stringify(
|
|
164
|
+
writeFileSync(path, JSON.stringify(value, null, 2) + "\n");
|
|
81
165
|
} catch {
|
|
82
166
|
// A hint that cannot remember it was shown shows again tomorrow.
|
|
83
167
|
}
|
package/lib/workspace.mjs
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
// thing a client cannot ask the platform for is the address of that call: the
|
|
8
8
|
// slug is in its URL. So this reads `workspace:` and stops.
|
|
9
9
|
|
|
10
|
-
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
11
|
-
import { dirname, join, parse as parsePath, resolve } from "node:path";
|
|
10
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
11
|
+
import { dirname, join, parse as parsePath, relative, resolve } from "node:path";
|
|
12
12
|
import { parse as parseYaml } from "yaml";
|
|
13
13
|
|
|
14
14
|
export const MANIFEST_FILE = "vatio.yml";
|
|
@@ -42,6 +42,34 @@ export function findWorkspaceRoot(startDir) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// The workspaces just below a directory that is not in one, for the error that
|
|
46
|
+
// says so: a coding agent started at the top of a repository is usually one
|
|
47
|
+
// `cd` away from its vatio.yml.
|
|
48
|
+
const SKIPPED_DIRS = new Set(["node_modules", "vendor", "dist", "build"]);
|
|
49
|
+
|
|
50
|
+
export function workspacesBelow(startDir, { depth = 2, limit = 3 } = {}) {
|
|
51
|
+
const root = resolve(startDir);
|
|
52
|
+
const found = [];
|
|
53
|
+
const visit = (dir, level) => {
|
|
54
|
+
if (level > depth || found.length >= limit) return;
|
|
55
|
+
let names;
|
|
56
|
+
try {
|
|
57
|
+
names = readdirSync(dir, { withFileTypes: true });
|
|
58
|
+
} catch {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
for (const entry of names) {
|
|
62
|
+
if (!entry.isDirectory() || entry.name.startsWith(".") || SKIPPED_DIRS.has(entry.name)) continue;
|
|
63
|
+
const child = join(dir, entry.name);
|
|
64
|
+
if (manifestPath(child)) found.push(relative(root, child));
|
|
65
|
+
else visit(child, level + 1);
|
|
66
|
+
if (found.length >= limit) return;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
visit(root, 1);
|
|
70
|
+
return found;
|
|
71
|
+
}
|
|
72
|
+
|
|
45
73
|
// Which workspace this directory deploys to. Addressing, not content: it names
|
|
46
74
|
// the remote, so it never rides along in the deployed manifest. Null when the
|
|
47
75
|
// file does not declare one.
|