@botcord/daemon 0.2.14 → 0.2.16
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/dist/agent-workspace.js +47 -1
- package/dist/index.js +4 -6
- package/package.json +1 -1
- package/src/__tests__/agent-workspace.test.ts +25 -0
- package/src/agent-workspace.ts +47 -0
- package/src/index.ts +4 -6
package/dist/agent-workspace.js
CHANGED
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
* systemContext does not clobber the user/agent-
|
|
17
17
|
* editable workspace AGENTS.md.
|
|
18
18
|
*/
|
|
19
|
-
import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, symlinkSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
19
|
+
import { chmodSync, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, symlinkSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
20
|
+
import { createRequire } from "node:module";
|
|
20
21
|
import { homedir } from "node:os";
|
|
21
22
|
import path from "node:path";
|
|
23
|
+
const require = createRequire(import.meta.url);
|
|
22
24
|
// Accepted agent id pattern. Enforced at every path-builder entry so a
|
|
23
25
|
// malicious / malformed agentId (e.g. "../../etc") cannot escape
|
|
24
26
|
// ~/.botcord/agents/ and end up under `rmSync(..., { recursive: true })`
|
|
@@ -329,6 +331,49 @@ export function ensureAgentHermesWorkspace(agentId) {
|
|
|
329
331
|
mergeHermesProviderEnv(path.join(hermesHome, ".env"));
|
|
330
332
|
return { hermesHome, hermesWorkspace };
|
|
331
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* Bundled Claude Code skills shipped inside `@botcord/cli/skills/`. Seeded
|
|
336
|
+
* into every agent workspace so the spawned `claude` runtime (which loads
|
|
337
|
+
* `.claude/` via `--setting-sources project`) can discover the BotCord CLI
|
|
338
|
+
* skill without any manual setup.
|
|
339
|
+
*/
|
|
340
|
+
const BUNDLED_CC_SKILLS = ["botcord", "botcord-user-guide"];
|
|
341
|
+
function resolveBundledCliSkillsRoot() {
|
|
342
|
+
try {
|
|
343
|
+
const pkgJsonPath = require.resolve("@botcord/cli/package.json");
|
|
344
|
+
const root = path.join(path.dirname(pkgJsonPath), "skills");
|
|
345
|
+
return existsSync(root) ? root : null;
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Copy daemon-owned Claude Code skills into the workspace. Re-copied on every
|
|
353
|
+
* `ensureAgentWorkspace` call (force-overwrite) so daemon upgrades propagate;
|
|
354
|
+
* users wanting custom skills should pick a different directory name under
|
|
355
|
+
* `.claude/skills/` — those are not touched here.
|
|
356
|
+
*/
|
|
357
|
+
function seedClaudeCodeSkills(workspace) {
|
|
358
|
+
const sourceRoot = resolveBundledCliSkillsRoot();
|
|
359
|
+
if (!sourceRoot)
|
|
360
|
+
return;
|
|
361
|
+
const skillsDir = path.join(workspace, ".claude", "skills");
|
|
362
|
+
mkdirTolerant(path.join(workspace, ".claude"));
|
|
363
|
+
mkdirTolerant(skillsDir);
|
|
364
|
+
for (const name of BUNDLED_CC_SKILLS) {
|
|
365
|
+
const src = path.join(sourceRoot, name);
|
|
366
|
+
if (!existsSync(src))
|
|
367
|
+
continue;
|
|
368
|
+
const dst = path.join(skillsDir, name);
|
|
369
|
+
try {
|
|
370
|
+
cpSync(src, dst, { recursive: true, force: true, dereference: true });
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
/* best-effort */
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
332
377
|
/**
|
|
333
378
|
* Idempotently create the agent's home / workspace / state directories and
|
|
334
379
|
* seed the workspace Markdown files. Existing files are never overwritten —
|
|
@@ -356,6 +401,7 @@ export function ensureAgentWorkspace(agentId, seed) {
|
|
|
356
401
|
writeIfMissing(path.join(workspace, "memory.md"), MEMORY_MD);
|
|
357
402
|
writeIfMissing(path.join(workspace, "task.md"), TASK_MD);
|
|
358
403
|
writeIfMissing(path.join(notes, ".gitkeep"), "");
|
|
404
|
+
seedClaudeCodeSkills(workspace);
|
|
359
405
|
}
|
|
360
406
|
const DISPLAY_NAME_LINE = /^- \*\*Display name\*\*: .*$/m;
|
|
361
407
|
// Match the Bio section's body. Anchor on the next `##` heading when one
|
package/dist/index.js
CHANGED
|
@@ -329,8 +329,9 @@ async function runDeviceCodeFlow(opts) {
|
|
|
329
329
|
* plane (legacy P0 behavior — caller may still log a warning).
|
|
330
330
|
*
|
|
331
331
|
* Decision tree (plan §4.4 + §6.4):
|
|
332
|
-
* 1. Have existing creds
|
|
333
|
-
* 2. `--install-token`
|
|
332
|
+
* 1. Have existing creds, no `--relogin`, no `--install-token` → return existing record.
|
|
333
|
+
* 2. `--install-token` (overrides existing creds — they may be stale or
|
|
334
|
+
* belong to a different account) → redeem the one-time dashboard ticket.
|
|
334
335
|
* 3. `--relogin` → device-code login.
|
|
335
336
|
* 4. No creds + TTY → device-code login.
|
|
336
337
|
* 5. No creds + no TTY → exit 1 with the §6.4 hint.
|
|
@@ -341,7 +342,7 @@ async function ensureUserAuthForStart(args) {
|
|
|
341
342
|
const installToken = typeof args.flags["install-token"] === "string" ? args.flags["install-token"] : undefined;
|
|
342
343
|
const relogin = args.flags.relogin === true;
|
|
343
344
|
const existing = safeLoadUserAuth();
|
|
344
|
-
if (!relogin && existing) {
|
|
345
|
+
if (!relogin && !installToken && existing) {
|
|
345
346
|
// A previously-set auth-expired flag is stale by definition once the
|
|
346
347
|
// operator runs `start` again — if creds genuinely don't work, the
|
|
347
348
|
// control channel will re-write the flag on the next 4401/4403.
|
|
@@ -355,9 +356,6 @@ async function ensureUserAuthForStart(args) {
|
|
|
355
356
|
if (labelFlag && existing.label !== labelFlag) {
|
|
356
357
|
console.error(`note: --label "${labelFlag}" ignored (already logged in as "${existing.label ?? "<unset>"}"); pass --relogin to change it`);
|
|
357
358
|
}
|
|
358
|
-
if (installToken) {
|
|
359
|
-
console.error("note: --install-token ignored because daemon is already logged in");
|
|
360
|
-
}
|
|
361
359
|
return existing;
|
|
362
360
|
}
|
|
363
361
|
// Need a fresh login. Resolve hubUrl: explicit --hub > existing record > DEFAULT_HUB.
|
package/package.json
CHANGED
|
@@ -80,6 +80,31 @@ describe("ensureAgentWorkspace", () => {
|
|
|
80
80
|
expect(existsSync(path.join(agentWorkspaceDir("ag_notes"), "notes", ".gitkeep"))).toBe(true);
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
+
it("seeds bundled Claude Code skills under .claude/skills/", () => {
|
|
84
|
+
ensureAgentWorkspace("ag_skills", {});
|
|
85
|
+
const skillsDir = path.join(agentWorkspaceDir("ag_skills"), ".claude", "skills");
|
|
86
|
+
expect(existsSync(path.join(skillsDir, "botcord", "SKILL.md"))).toBe(true);
|
|
87
|
+
expect(existsSync(path.join(skillsDir, "botcord-user-guide", "SKILL.md"))).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("re-seeds skills on a second call so daemon upgrades propagate", () => {
|
|
91
|
+
ensureAgentWorkspace("ag_skill_upgrade", {});
|
|
92
|
+
const skillFile = path.join(
|
|
93
|
+
agentWorkspaceDir("ag_skill_upgrade"),
|
|
94
|
+
".claude",
|
|
95
|
+
"skills",
|
|
96
|
+
"botcord",
|
|
97
|
+
"SKILL.md",
|
|
98
|
+
);
|
|
99
|
+
writeFileSync(skillFile, "stale content from a prior daemon version\n");
|
|
100
|
+
|
|
101
|
+
ensureAgentWorkspace("ag_skill_upgrade", {});
|
|
102
|
+
|
|
103
|
+
const reseeded = readFileSync(skillFile, "utf8");
|
|
104
|
+
expect(reseeded).not.toBe("stale content from a prior daemon version\n");
|
|
105
|
+
expect(reseeded).toContain("name: botcord");
|
|
106
|
+
});
|
|
107
|
+
|
|
83
108
|
it("does not overwrite a user-modified memory.md on a second call", () => {
|
|
84
109
|
ensureAgentWorkspace("ag_keep", {});
|
|
85
110
|
const memoryPath = path.join(agentWorkspaceDir("ag_keep"), "memory.md");
|
package/src/agent-workspace.ts
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import {
|
|
20
20
|
chmodSync,
|
|
21
21
|
copyFileSync,
|
|
22
|
+
cpSync,
|
|
22
23
|
existsSync,
|
|
23
24
|
lstatSync,
|
|
24
25
|
mkdirSync,
|
|
@@ -28,9 +29,12 @@ import {
|
|
|
28
29
|
unlinkSync,
|
|
29
30
|
writeFileSync,
|
|
30
31
|
} from "node:fs";
|
|
32
|
+
import { createRequire } from "node:module";
|
|
31
33
|
import { homedir } from "node:os";
|
|
32
34
|
import path from "node:path";
|
|
33
35
|
|
|
36
|
+
const require = createRequire(import.meta.url);
|
|
37
|
+
|
|
34
38
|
// Accepted agent id pattern. Enforced at every path-builder entry so a
|
|
35
39
|
// malicious / malformed agentId (e.g. "../../etc") cannot escape
|
|
36
40
|
// ~/.botcord/agents/ and end up under `rmSync(..., { recursive: true })`
|
|
@@ -364,6 +368,48 @@ export function ensureAgentHermesWorkspace(agentId: string): {
|
|
|
364
368
|
return { hermesHome, hermesWorkspace };
|
|
365
369
|
}
|
|
366
370
|
|
|
371
|
+
/**
|
|
372
|
+
* Bundled Claude Code skills shipped inside `@botcord/cli/skills/`. Seeded
|
|
373
|
+
* into every agent workspace so the spawned `claude` runtime (which loads
|
|
374
|
+
* `.claude/` via `--setting-sources project`) can discover the BotCord CLI
|
|
375
|
+
* skill without any manual setup.
|
|
376
|
+
*/
|
|
377
|
+
const BUNDLED_CC_SKILLS = ["botcord", "botcord-user-guide"] as const;
|
|
378
|
+
|
|
379
|
+
function resolveBundledCliSkillsRoot(): string | null {
|
|
380
|
+
try {
|
|
381
|
+
const pkgJsonPath = require.resolve("@botcord/cli/package.json");
|
|
382
|
+
const root = path.join(path.dirname(pkgJsonPath), "skills");
|
|
383
|
+
return existsSync(root) ? root : null;
|
|
384
|
+
} catch {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Copy daemon-owned Claude Code skills into the workspace. Re-copied on every
|
|
391
|
+
* `ensureAgentWorkspace` call (force-overwrite) so daemon upgrades propagate;
|
|
392
|
+
* users wanting custom skills should pick a different directory name under
|
|
393
|
+
* `.claude/skills/` — those are not touched here.
|
|
394
|
+
*/
|
|
395
|
+
function seedClaudeCodeSkills(workspace: string): void {
|
|
396
|
+
const sourceRoot = resolveBundledCliSkillsRoot();
|
|
397
|
+
if (!sourceRoot) return;
|
|
398
|
+
const skillsDir = path.join(workspace, ".claude", "skills");
|
|
399
|
+
mkdirTolerant(path.join(workspace, ".claude"));
|
|
400
|
+
mkdirTolerant(skillsDir);
|
|
401
|
+
for (const name of BUNDLED_CC_SKILLS) {
|
|
402
|
+
const src = path.join(sourceRoot, name);
|
|
403
|
+
if (!existsSync(src)) continue;
|
|
404
|
+
const dst = path.join(skillsDir, name);
|
|
405
|
+
try {
|
|
406
|
+
cpSync(src, dst, { recursive: true, force: true, dereference: true });
|
|
407
|
+
} catch {
|
|
408
|
+
/* best-effort */
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
367
413
|
/**
|
|
368
414
|
* Idempotently create the agent's home / workspace / state directories and
|
|
369
415
|
* seed the workspace Markdown files. Existing files are never overwritten —
|
|
@@ -392,6 +438,7 @@ export function ensureAgentWorkspace(agentId: string, seed: WorkspaceSeed): void
|
|
|
392
438
|
writeIfMissing(path.join(workspace, "memory.md"), MEMORY_MD);
|
|
393
439
|
writeIfMissing(path.join(workspace, "task.md"), TASK_MD);
|
|
394
440
|
writeIfMissing(path.join(notes, ".gitkeep"), "");
|
|
441
|
+
seedClaudeCodeSkills(workspace);
|
|
395
442
|
}
|
|
396
443
|
|
|
397
444
|
/** Patch fields accepted by {@link applyAgentIdentity}. `bio = null` clears it. */
|
package/src/index.ts
CHANGED
|
@@ -417,8 +417,9 @@ async function runDeviceCodeFlow(opts: {
|
|
|
417
417
|
* plane (legacy P0 behavior — caller may still log a warning).
|
|
418
418
|
*
|
|
419
419
|
* Decision tree (plan §4.4 + §6.4):
|
|
420
|
-
* 1. Have existing creds
|
|
421
|
-
* 2. `--install-token`
|
|
420
|
+
* 1. Have existing creds, no `--relogin`, no `--install-token` → return existing record.
|
|
421
|
+
* 2. `--install-token` (overrides existing creds — they may be stale or
|
|
422
|
+
* belong to a different account) → redeem the one-time dashboard ticket.
|
|
422
423
|
* 3. `--relogin` → device-code login.
|
|
423
424
|
* 4. No creds + TTY → device-code login.
|
|
424
425
|
* 5. No creds + no TTY → exit 1 with the §6.4 hint.
|
|
@@ -432,7 +433,7 @@ async function ensureUserAuthForStart(args: ParsedArgs): Promise<UserAuthRecord
|
|
|
432
433
|
|
|
433
434
|
const existing = safeLoadUserAuth();
|
|
434
435
|
|
|
435
|
-
if (!relogin && existing) {
|
|
436
|
+
if (!relogin && !installToken && existing) {
|
|
436
437
|
// A previously-set auth-expired flag is stale by definition once the
|
|
437
438
|
// operator runs `start` again — if creds genuinely don't work, the
|
|
438
439
|
// control channel will re-write the flag on the next 4401/4403.
|
|
@@ -448,9 +449,6 @@ async function ensureUserAuthForStart(args: ParsedArgs): Promise<UserAuthRecord
|
|
|
448
449
|
`note: --label "${labelFlag}" ignored (already logged in as "${existing.label ?? "<unset>"}"); pass --relogin to change it`,
|
|
449
450
|
);
|
|
450
451
|
}
|
|
451
|
-
if (installToken) {
|
|
452
|
-
console.error("note: --install-token ignored because daemon is already logged in");
|
|
453
|
-
}
|
|
454
452
|
return existing;
|
|
455
453
|
}
|
|
456
454
|
|