@commonlyai/cli 0.1.134 → 0.1.136
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/commands/agent.js +60 -4
- package/src/lib/adapters/claude.js +22 -4
- package/src/lib/adapters/codex.js +14 -2
- package/src/lib/api.js +2 -2
- package/src/lib/server-skills.js +32 -0
- package/src/lib/skill-prompt.js +2 -1
- package/src/lib/skills-import.js +1 -0
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { readFileSync, writeFileSync, mkdirSync, existsSync, rmSync, readdirSync } from 'fs';
|
|
15
|
-
import { join, dirname, resolve as pathResolve } from 'path';
|
|
15
|
+
import { join, dirname, basename, resolve as pathResolve } from 'path';
|
|
16
16
|
import { homedir, tmpdir } from 'os';
|
|
17
17
|
import { fileURLToPath } from 'url';
|
|
18
18
|
import { createHash } from 'crypto';
|
|
@@ -39,7 +39,8 @@ import {
|
|
|
39
39
|
import { readLongTerm, syncBack } from '../lib/memory-bridge.js';
|
|
40
40
|
import { pollRetryPolicy } from '../lib/poll-retry.js';
|
|
41
41
|
import { detectMemorySources, composeImport, importMemory } from '../lib/memory-import.js';
|
|
42
|
-
import { detectSkills, importSkills } from '../lib/skills-import.js';
|
|
42
|
+
import { detectSkills, importSkills, parseSkillMeta } from '../lib/skills-import.js';
|
|
43
|
+
import { compileServerSkills } from '../lib/server-skills.js';
|
|
43
44
|
import {
|
|
44
45
|
environmentForServer,
|
|
45
46
|
normalizeSandboxTrust,
|
|
@@ -498,6 +499,14 @@ const BUNDLED_COMMONLY_SKILL_DIR = pathResolve(
|
|
|
498
499
|
dirname(fileURLToPath(import.meta.url)), '..', '..', 'skills', 'commonly',
|
|
499
500
|
);
|
|
500
501
|
|
|
502
|
+
const reportedSkillName = (source) => {
|
|
503
|
+
try {
|
|
504
|
+
return parseSkillMeta(readFileSync(join(source, 'SKILL.md'), 'utf8'), basename(source)).name;
|
|
505
|
+
} catch {
|
|
506
|
+
return basename(source);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
|
|
501
510
|
// Minimum-viable environment for fresh attach: wire @commonlyai/mcp so the
|
|
502
511
|
// agent gets commonly_* kernel tools out of the box, AND mount the commonly
|
|
503
512
|
// behavior skill so the agent knows the house rules (orient before posting,
|
|
@@ -1581,6 +1590,25 @@ export const performRun = ({
|
|
|
1581
1590
|
throw error;
|
|
1582
1591
|
}
|
|
1583
1592
|
const promptWithFocus = `${focusFrame}\n\n${prompt}`;
|
|
1593
|
+
let serverSkills;
|
|
1594
|
+
let skillReadUnavailable = false;
|
|
1595
|
+
try {
|
|
1596
|
+
const response = await client.get(`/api/agents/runtime/pods/${eventPodId}/skills`, {}, {
|
|
1597
|
+
signal: AbortSignal.timeout(5000),
|
|
1598
|
+
});
|
|
1599
|
+
serverSkills = compileServerSkills(response?.items || []);
|
|
1600
|
+
} catch (error) {
|
|
1601
|
+
// Skill delivery is optional to the turn. A read failure must not stop
|
|
1602
|
+
// every seat from spawning; report the missing observation explicitly.
|
|
1603
|
+
if (error?.status !== 404) {
|
|
1604
|
+
skillReadUnavailable = true;
|
|
1605
|
+
log(`server skills unavailable (HTTP ${error?.status || 'no response'}); spawning without them`);
|
|
1606
|
+
}
|
|
1607
|
+
serverSkills = compileServerSkills();
|
|
1608
|
+
}
|
|
1609
|
+
const promptWithSkills = serverSkills.text
|
|
1610
|
+
? `${focusFrame}\n\n${serverSkills.text}\n\n${prompt}`
|
|
1611
|
+
: promptWithFocus;
|
|
1584
1612
|
|
|
1585
1613
|
log(`[${event.type}] spawning ${adapter.name}`);
|
|
1586
1614
|
// TASK-102 part B. The CHILD gets a scoped credential; the wrapper keeps
|
|
@@ -1643,6 +1671,10 @@ export const performRun = ({
|
|
|
1643
1671
|
};
|
|
1644
1672
|
}
|
|
1645
1673
|
let result;
|
|
1674
|
+
let skillMount = skillReadUnavailable || serverSkills.mounted.length || serverSkills.conflicted.length
|
|
1675
|
+
? { mounted: serverSkills.mounted, conflicted: serverSkills.conflicted, ...(skillReadUnavailable ? { status: 'unavailable' } : {}) }
|
|
1676
|
+
: null;
|
|
1677
|
+
let spawnCompleted = false;
|
|
1646
1678
|
let commitAttribution = null;
|
|
1647
1679
|
try {
|
|
1648
1680
|
// The local CLI is a wrapper for a Commonly seat, so its Git commits
|
|
@@ -1660,13 +1692,20 @@ export const performRun = ({
|
|
|
1660
1692
|
effort: seatEnvironment?.effort,
|
|
1661
1693
|
});
|
|
1662
1694
|
}
|
|
1663
|
-
result = await adapter.spawn(frameDecisionForkRule(
|
|
1695
|
+
result = await adapter.spawn(frameDecisionForkRule(promptWithSkills), {
|
|
1664
1696
|
sessionId,
|
|
1665
1697
|
cwd: agentCwd,
|
|
1666
1698
|
env: commitAttribution?.env || process.env,
|
|
1667
1699
|
commitAttributionEnv: commitAttribution?.sandboxEnv || null,
|
|
1668
1700
|
memoryLongTerm,
|
|
1669
1701
|
environment: seatEnvironment,
|
|
1702
|
+
onSkillsLinked: ({ mounted, conflicted }) => {
|
|
1703
|
+
skillMount = {
|
|
1704
|
+
mounted: [...new Set([...serverSkills.mounted, ...mounted.map(reportedSkillName)])],
|
|
1705
|
+
conflicted: [...new Set([...serverSkills.conflicted, ...conflicted.map(({ path }) => reportedSkillName(path))])],
|
|
1706
|
+
...(skillReadUnavailable ? { status: 'unavailable' } : {}),
|
|
1707
|
+
};
|
|
1708
|
+
},
|
|
1670
1709
|
// Runtime context the Claude/Codex adapters expose only to their
|
|
1671
1710
|
// per-spawn MCP environment. Claude keeps ${COMMONLY_*} placeholders
|
|
1672
1711
|
// literal on disk and lets its native MCP parser expand them, so the
|
|
@@ -1678,10 +1717,18 @@ export const performRun = ({
|
|
|
1678
1717
|
agentName,
|
|
1679
1718
|
metadata: { event },
|
|
1680
1719
|
});
|
|
1720
|
+
spawnCompleted = true;
|
|
1681
1721
|
} finally {
|
|
1682
1722
|
try {
|
|
1683
1723
|
commitAttribution?.cleanup();
|
|
1684
1724
|
} finally {
|
|
1725
|
+
if (spawnCompleted && skillMount) {
|
|
1726
|
+
try {
|
|
1727
|
+
await client.post(`/api/agents/runtime/pods/${eventPodId}/skill-load`, skillMount);
|
|
1728
|
+
} catch (error) {
|
|
1729
|
+
log(`skill load status could not be recorded: ${error.message}`);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1685
1732
|
// Best-effort by construction: `close` logs and returns on a failed
|
|
1686
1733
|
// revoke, so a turn that already produced an answer is not failed by
|
|
1687
1734
|
// cleanup. The boot sweep collects anything left behind.
|
|
@@ -2410,7 +2457,16 @@ export const performRun = ({
|
|
|
2410
2457
|
entry.result?.outcome === 'posted'
|
|
2411
2458
|
|| (entry.result?.outcome === 'no_action' && !entry.result?.reason)
|
|
2412
2459
|
));
|
|
2413
|
-
if (batchSpawned)
|
|
2460
|
+
if (batchSpawned) {
|
|
2461
|
+
consecutiveSpawnFailures = 0;
|
|
2462
|
+
// A turn is exactly when events pile up: whoever typed while the
|
|
2463
|
+
// adapter was running is already waiting. Sleeping the interval on
|
|
2464
|
+
// top of the turn charges them for it twice (TASK-343). Only a
|
|
2465
|
+
// batch that actually spawned skips the wait; an idle poll and a
|
|
2466
|
+
// batch that spawned nothing keep the interval, so this cannot
|
|
2467
|
+
// become a spin.
|
|
2468
|
+
nextPollDelayMs = 0;
|
|
2469
|
+
}
|
|
2414
2470
|
for (const entry of batch.entries) {
|
|
2415
2471
|
const event = entry.event;
|
|
2416
2472
|
// No result: an item a failure during refusal isolation never
|
|
@@ -276,8 +276,13 @@ const buildPublicClaudePolicyArgs = (mcpToolPatterns) => {
|
|
|
276
276
|
// total is capped well under it.
|
|
277
277
|
const PUBLIC_SKILL_PROMPT_MAX_BYTES = 96 * 1024;
|
|
278
278
|
const publicSkillPromptArgs = async (skillSources) => {
|
|
279
|
-
const
|
|
280
|
-
|
|
279
|
+
const included = [];
|
|
280
|
+
const text = await skillsAsText(skillSources, {
|
|
281
|
+
maxBytes: PUBLIC_SKILL_PROMPT_MAX_BYTES,
|
|
282
|
+
label: 'claude',
|
|
283
|
+
onIncluded: (source) => included.push(source),
|
|
284
|
+
});
|
|
285
|
+
return { args: text ? ['--append-system-prompt', text] : [], included };
|
|
281
286
|
};
|
|
282
287
|
|
|
283
288
|
const runClaude = ({ cmd, args, cwd, env, timeoutMs, credentials = [], spawnImpl = childSpawn }) => new Promise((resolve, reject) => {
|
|
@@ -804,16 +809,17 @@ export default {
|
|
|
804
809
|
const baseArgs = ['-p', fullPrompt, '--output-format', 'text', sessionFlag, sessionId, ...modelArgs];
|
|
805
810
|
|
|
806
811
|
let mountedSkills = [];
|
|
812
|
+
let skillMount = { mounted: [], conflicted: [] };
|
|
807
813
|
if (ctx.environment && ctx.cwd) {
|
|
808
814
|
const skills = await mountSkills(ctx.environment, ctx.cwd);
|
|
809
815
|
mountedSkills = skills.mounted;
|
|
816
|
+
skillMount = skills;
|
|
810
817
|
if (skills.conflicted.length > 0) {
|
|
811
818
|
for (const c of skills.conflicted) {
|
|
812
819
|
// eslint-disable-next-line no-console
|
|
813
820
|
console.warn(`[claude] skill not mounted (${c.reason}): ${c.path}`);
|
|
814
821
|
}
|
|
815
822
|
}
|
|
816
|
-
if (ctx.onSkillsLinked) ctx.onSkillsLinked(skills);
|
|
817
823
|
}
|
|
818
824
|
|
|
819
825
|
let mcpConfig = null;
|
|
@@ -830,7 +836,19 @@ export default {
|
|
|
830
836
|
if (publicNativeSandbox) {
|
|
831
837
|
publicClaudeState = await preparePublicClaudeState(ctx);
|
|
832
838
|
}
|
|
833
|
-
if (publicTrust)
|
|
839
|
+
if (publicTrust) {
|
|
840
|
+
const prompt = await publicSkillPromptArgs(mountedSkills);
|
|
841
|
+
publicSkillArgs = prompt.args;
|
|
842
|
+
skillMount = {
|
|
843
|
+
mounted: prompt.included,
|
|
844
|
+
conflicted: [
|
|
845
|
+
...skillMount.conflicted,
|
|
846
|
+
...mountedSkills.filter((source) => !prompt.included.includes(source))
|
|
847
|
+
.map((path) => ({ path, reason: 'not-inlined' })),
|
|
848
|
+
],
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
if (ctx.environment && ctx.cwd) ctx.onSkillsLinked?.(skillMount);
|
|
834
852
|
if (Array.isArray(ctx.environment?.mcp) && ctx.environment.mcp.length > 0) {
|
|
835
853
|
mcpConfig = await createMcpConfig(ctx.environment.mcp, {
|
|
836
854
|
runtimeToken: ctx.runtimeToken,
|
|
@@ -343,18 +343,30 @@ const PUBLIC_CODEX_INSTRUCTIONS_MAX_BYTES = 32 * 1024;
|
|
|
343
343
|
const writePublicCodexInstructions = async (publicHome, ctx) => {
|
|
344
344
|
const declared = Array.isArray(ctx.environment?.skills?.claude) ? ctx.environment.skills.claude : [];
|
|
345
345
|
const baseDir = ctx.cwd || process.cwd();
|
|
346
|
+
const sources = declared.map((source) => resolveSkillSource(source, baseDir));
|
|
347
|
+
const included = [];
|
|
346
348
|
const text = await skillsAsText(
|
|
347
|
-
|
|
348
|
-
{
|
|
349
|
+
sources,
|
|
350
|
+
{
|
|
351
|
+
maxBytes: PUBLIC_CODEX_INSTRUCTIONS_MAX_BYTES,
|
|
352
|
+
label: 'codex',
|
|
353
|
+
trailer: '\n',
|
|
354
|
+
onIncluded: (source) => included.push(source),
|
|
355
|
+
},
|
|
349
356
|
);
|
|
350
357
|
const target = join(publicHome, 'AGENTS.md');
|
|
351
358
|
if (!text) {
|
|
352
359
|
await rm(target, { force: true });
|
|
360
|
+
ctx.onSkillsLinked?.({ mounted: [], conflicted: sources.map((path) => ({ path, reason: 'not-inlined' })) });
|
|
353
361
|
return;
|
|
354
362
|
}
|
|
355
363
|
const staged = `${target}.${process.pid}.tmp`;
|
|
356
364
|
await writeFile(staged, text, { encoding: 'utf8', mode: 0o600 });
|
|
357
365
|
await rename(staged, target);
|
|
366
|
+
ctx.onSkillsLinked?.({
|
|
367
|
+
mounted: included,
|
|
368
|
+
conflicted: sources.filter((source) => !included.includes(source)).map((path) => ({ path, reason: 'not-inlined' })),
|
|
369
|
+
});
|
|
358
370
|
};
|
|
359
371
|
|
|
360
372
|
const publicPermissionProfileFlags = (
|
package/src/lib/api.js
CHANGED
|
@@ -65,10 +65,10 @@ export const createClient = ({ instance = null, token = undefined } = {}) => {
|
|
|
65
65
|
baseUrl,
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
const get = (path, params = {}) => {
|
|
68
|
+
const get = (path, params = {}, options = {}) => {
|
|
69
69
|
const url = new URL(`${baseUrl}${path}`);
|
|
70
70
|
Object.entries(params).forEach(([k, v]) => v != null && url.searchParams.set(k, v));
|
|
71
|
-
return fetch(url.toString(), { headers: headers(authToken) }).then((res) => handleResponse(res, session));
|
|
71
|
+
return fetch(url.toString(), { headers: headers(authToken), ...options }).then((res) => handleResponse(res, session));
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
const post = (path, body = {}) => fetch(`${baseUrl}${path}`, {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Agent-scoped catalog skills arrive from Commonly at each turn start. The
|
|
2
|
+
// wrapper gives their instructions to either adapter as prompt text, so a
|
|
3
|
+
// browser add/remove changes the next spawn without touching local files.
|
|
4
|
+
const MAX_BYTES = 64 * 1024;
|
|
5
|
+
const PREAMBLE = 'Installed skills for this agent and pod. Follow the applicable instructions below.';
|
|
6
|
+
const FRONTMATTER = /^---\r?\n[\s\S]*?\r?\n---[ \t]*\r?\n?/;
|
|
7
|
+
|
|
8
|
+
export const compileServerSkills = (items = []) => {
|
|
9
|
+
const sections = [];
|
|
10
|
+
const mounted = [];
|
|
11
|
+
const conflicted = [];
|
|
12
|
+
let bytes = Buffer.byteLength(PREAMBLE);
|
|
13
|
+
for (const item of items) {
|
|
14
|
+
const name = String(item?.name || '').replace(/[\r\n]/g, ' ').trim();
|
|
15
|
+
const content = String(item?.content || '').replace(FRONTMATTER, '').trim();
|
|
16
|
+
if (!name || !content) continue;
|
|
17
|
+
const section = `## Skill: ${name}\n\n${content}`;
|
|
18
|
+
const nextBytes = Buffer.byteLength(section) + 2;
|
|
19
|
+
if (bytes + nextBytes > MAX_BYTES) {
|
|
20
|
+
conflicted.push(name);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
sections.push(section);
|
|
24
|
+
mounted.push(name);
|
|
25
|
+
bytes += nextBytes;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
text: sections.length ? `${PREAMBLE}\n\n${sections.join('\n\n')}` : null,
|
|
29
|
+
mounted,
|
|
30
|
+
conflicted,
|
|
31
|
+
};
|
|
32
|
+
};
|
package/src/lib/skill-prompt.js
CHANGED
|
@@ -35,7 +35,7 @@ const SECTION_SEPARATOR = '\n\n';
|
|
|
35
35
|
* would cross the cap, is skipped with a warning naming the runtime (`label`)
|
|
36
36
|
* rather than failing the spawn.
|
|
37
37
|
*/
|
|
38
|
-
export const readSkillSections = async (skillSources, { maxBytes, label, trailer = '' }) => {
|
|
38
|
+
export const readSkillSections = async (skillSources, { maxBytes, label, trailer = '', onIncluded }) => {
|
|
39
39
|
const sections = [];
|
|
40
40
|
let total = Buffer.byteLength(SKILLS_AS_TEXT_PREAMBLE, 'utf8') + Buffer.byteLength(trailer, 'utf8');
|
|
41
41
|
for (const source of skillSources || []) {
|
|
@@ -60,6 +60,7 @@ export const readSkillSections = async (skillSources, { maxBytes, label, trailer
|
|
|
60
60
|
}
|
|
61
61
|
total += bytes;
|
|
62
62
|
sections.push(section);
|
|
63
|
+
onIncluded?.(source);
|
|
63
64
|
}
|
|
64
65
|
return sections;
|
|
65
66
|
};
|
package/src/lib/skills-import.js
CHANGED