@commonlyai/cli 0.1.336 → 0.1.338
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/lib/adapters/claude.js +6 -1
- package/src/lib/adapters/pi.js +38 -17
- package/src/lib/environment.js +52 -3
- package/src/lib/resolve-on-path.js +5 -2
package/package.json
CHANGED
|
@@ -1998,9 +1998,14 @@ export default {
|
|
|
1998
1998
|
}
|
|
1999
1999
|
// F153: a Seatbelt seat with no key signs in only through the keychain.
|
|
2000
2000
|
// When that fails, say how to give it a key instead, as bwrap does.
|
|
2001
|
+
// F171: `commonly daemon install` carries no ANTHROPIC_API_KEY (claude
|
|
2002
|
+
// declares no providerKeyEnv), so the key route is a seat run from a
|
|
2003
|
+
// shell that has it; the hint must not send a daemon operator to a
|
|
2004
|
+
// service file that never receives the key.
|
|
2001
2005
|
if (publicNativeSandbox && !providerProxy && /not logged in/i.test(String(err?.message))) {
|
|
2002
2006
|
err.message = `${err.message}. Sign in with \`claude\` in your own terminal on this Mac, `
|
|
2003
|
-
+
|
|
2007
|
+
+ `or run the agent with ANTHROPIC_API_KEY set (\`${CLI} agent run\` from a shell that has it; `
|
|
2008
|
+
+ 'the background daemon does not carry it)';
|
|
2004
2009
|
}
|
|
2005
2010
|
throw err;
|
|
2006
2011
|
} finally {
|
package/src/lib/adapters/pi.js
CHANGED
|
@@ -48,7 +48,9 @@ import { resolveOnPath } from '../resolve-on-path.js';
|
|
|
48
48
|
import { spawn as childSpawn, spawnSync } from 'child_process';
|
|
49
49
|
import { createHash, randomUUID } from 'crypto';
|
|
50
50
|
import { existsSync, readFileSync, realpathSync, rmSync } from 'fs';
|
|
51
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
mkdir, readdir, readFile, rm, writeFile,
|
|
53
|
+
} from 'fs/promises';
|
|
52
54
|
import { homedir } from 'os';
|
|
53
55
|
import {
|
|
54
56
|
dirname, isAbsolute, join, relative, sep,
|
|
@@ -507,6 +509,9 @@ export const piPackageRoot = (binary) => {
|
|
|
507
509
|
const versionOf = (value) => String(value || '').trim()
|
|
508
510
|
.match(/(?<![\w.+~-])(\d+\.\d+\.\d+(?:-[0-9A-Za-z]+(?:\.[0-9A-Za-z]+)*)?)(?![\w.+~-])/)?.[1] || null;
|
|
509
511
|
|
|
512
|
+
// The system prompt files pi reads from its agent folder unconditionally.
|
|
513
|
+
const PI_AGENT_DIR_PROMPT_FILES = Object.freeze(['SYSTEM.md', 'APPEND_SYSTEM.md']);
|
|
514
|
+
|
|
510
515
|
export const buildArgs = ({
|
|
511
516
|
prompt, provider, model, thinking, sessionId, isResume, sessionDir, bridge, publicSeat = false, ownerWoken = false,
|
|
512
517
|
}) => [
|
|
@@ -517,12 +522,16 @@ export const buildArgs = ({
|
|
|
517
522
|
'--no-prompt-templates',
|
|
518
523
|
'--no-themes',
|
|
519
524
|
// A public seat: no built-in tool (no shell, no file access), the withheld
|
|
520
|
-
// Commonly tools removed from the registry,
|
|
521
|
-
//
|
|
525
|
+
// Commonly tools removed from the registry, no project-local pi files from
|
|
526
|
+
// the workspace trusted for this run, and no AGENTS.md / CLAUDE.md (F146).
|
|
527
|
+
// pi discovers those from the working directory upward, independently of
|
|
528
|
+
// --no-approve (0.84.1's resource loader gates them on noContextFiles alone),
|
|
529
|
+
// so a public turn turns discovery off explicitly.
|
|
522
530
|
...(publicSeat ? [
|
|
523
531
|
'--no-builtin-tools',
|
|
524
532
|
'--exclude-tools', [...PI_BUILTIN_TOOLS, ...publicSeatWithheldTools({ ownerWoken })].join(','),
|
|
525
533
|
'--no-approve',
|
|
534
|
+
'--no-context-files',
|
|
526
535
|
] : []),
|
|
527
536
|
'--provider', provider,
|
|
528
537
|
'--model', model,
|
|
@@ -823,7 +832,13 @@ export default {
|
|
|
823
832
|
const sessionDir = join(home, 'sessions');
|
|
824
833
|
await mkdir(agentDir, { recursive: true, mode: 0o700 });
|
|
825
834
|
await mkdir(sessionDir, { recursive: true, mode: 0o700 });
|
|
826
|
-
if (isPublic)
|
|
835
|
+
if (isPublic) {
|
|
836
|
+
await mkdir(join(home, 'tmp'), { recursive: true, mode: 0o700 });
|
|
837
|
+
// F146: pi 0.84.1 loads these two from PI_CODING_AGENT_DIR with no flag
|
|
838
|
+
// to turn that off. The CLI writes only models.json there, so a public
|
|
839
|
+
// turn starts without either.
|
|
840
|
+
await Promise.all(PI_AGENT_DIR_PROMPT_FILES.map((file) => rm(join(agentDir, file), { force: true })));
|
|
841
|
+
}
|
|
827
842
|
|
|
828
843
|
// Resume only what pi wrote; anything else (a codex thread id from before
|
|
829
844
|
// the switch, a wiped home) starts fresh under a new id.
|
|
@@ -936,8 +951,11 @@ export default {
|
|
|
936
951
|
// Public seat: the CLI made this workspace, so it is pinned (F197).
|
|
937
952
|
pinWorkspace: true,
|
|
938
953
|
readOnlyDirectories: [packageRoot, EXTENSION_CODE_ROOT, ...mcpReadDirectories],
|
|
939
|
-
//
|
|
940
|
-
//
|
|
954
|
+
// Defense in depth, not the boundary: the jailed pi holds the seat
|
|
955
|
+
// token in memory (the bridge reads it), and pi has no shell or other
|
|
956
|
+
// built-in tool to start an inspector with. Its only children are the
|
|
957
|
+
// MCP servers the bridge starts. Even so, nothing it starts may
|
|
958
|
+
// inspect another process.
|
|
941
959
|
processInfo: 'self',
|
|
942
960
|
});
|
|
943
961
|
}
|
|
@@ -951,22 +969,25 @@ export default {
|
|
|
951
969
|
timeoutMs: ctx.timeoutMs || DEFAULT_TIMEOUT_MS,
|
|
952
970
|
credentials: proxy ? [...credentials, proxy.token] : credentials,
|
|
953
971
|
spawnImpl: ctx._spawnImpl, // test seam only — do not use in production
|
|
954
|
-
//
|
|
955
|
-
//
|
|
956
|
-
//
|
|
957
|
-
//
|
|
958
|
-
//
|
|
959
|
-
//
|
|
960
|
-
//
|
|
961
|
-
//
|
|
962
|
-
//
|
|
963
|
-
|
|
972
|
+
// A public turn keeps its credential file only until pi has loaded its
|
|
973
|
+
// extensions: the bridge reads it at load, and nothing on a public turn
|
|
974
|
+
// reads it after that (our own server gets the value on its fd 3 pipe,
|
|
975
|
+
// and pi has no shell). F175c: on a turn holding a grant broker the
|
|
976
|
+
// first layer is inside pi: the bridge deletes the directory before its
|
|
977
|
+
// factory returns, which pi awaits before it creates the session
|
|
978
|
+
// (removeSpawnCredential), and stops pi if it cannot. This is the second
|
|
979
|
+
// layer, at pi's first JSON line (firstEventWatcher), and since F146 it
|
|
980
|
+
// runs on every public turn. It is async to pi, so it cannot be the one
|
|
981
|
+
// that closes the file before a prompt; on a broker turn it normally
|
|
982
|
+
// finds the file gone, and `force` tolerates that. A delete that does
|
|
983
|
+
// fail here still ends the turn.
|
|
984
|
+
onFirstEvent: isPublic && credential
|
|
964
985
|
? () => {
|
|
965
986
|
try {
|
|
966
987
|
(ctx._rmSync || rmSync)(credential.dir, { recursive: true, force: true });
|
|
967
988
|
} catch (err) {
|
|
968
989
|
throw new Error(
|
|
969
|
-
`pi adapter: a public pi seat could not delete its
|
|
990
|
+
`pi adapter: a public pi seat could not delete its runtime credential (${credential.path}) once pi `
|
|
970
991
|
+ `had loaded its extensions: ${err?.message || err}; the turn was stopped so the credential does not `
|
|
971
992
|
+ 'stay readable during it',
|
|
972
993
|
);
|
package/src/lib/environment.js
CHANGED
|
@@ -544,6 +544,43 @@ const freezeFiles = async (dir) => {
|
|
|
544
544
|
}
|
|
545
545
|
};
|
|
546
546
|
|
|
547
|
+
// F171: skills are written only into a real .claude/skills directory inside
|
|
548
|
+
// the workspace. Each component is read with lstat and never followed. A
|
|
549
|
+
// missing one is created with a plain mkdir inside the real directory just
|
|
550
|
+
// checked, then read again; a link, or anything that is not a real directory,
|
|
551
|
+
// returns null and mountSkills writes nothing.
|
|
552
|
+
const SKILLS_DIR_PARTS = ['.claude', 'skills'];
|
|
553
|
+
|
|
554
|
+
const lstatOrNull = async (p) => {
|
|
555
|
+
try {
|
|
556
|
+
return await lstat(p);
|
|
557
|
+
} catch (err) {
|
|
558
|
+
if (err.code === 'ENOENT') return null;
|
|
559
|
+
throw err;
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
const realSkillsDir = async (workspacePath) => {
|
|
564
|
+
let dir = workspacePath;
|
|
565
|
+
for (const part of SKILLS_DIR_PARTS) {
|
|
566
|
+
dir = join(dir, part);
|
|
567
|
+
// eslint-disable-next-line no-await-in-loop
|
|
568
|
+
let st = await lstatOrNull(dir);
|
|
569
|
+
if (!st) {
|
|
570
|
+
try {
|
|
571
|
+
// eslint-disable-next-line no-await-in-loop
|
|
572
|
+
await mkdir(dir);
|
|
573
|
+
} catch (err) {
|
|
574
|
+
if (err.code !== 'EEXIST') throw err;
|
|
575
|
+
}
|
|
576
|
+
// eslint-disable-next-line no-await-in-loop
|
|
577
|
+
st = await lstatOrNull(dir);
|
|
578
|
+
}
|
|
579
|
+
if (!st || st.isSymbolicLink() || !st.isDirectory()) return null;
|
|
580
|
+
}
|
|
581
|
+
return dir;
|
|
582
|
+
};
|
|
583
|
+
|
|
547
584
|
/**
|
|
548
585
|
* Mount each `skills.claude[]` source into `<workspacePath>/.claude/skills/`
|
|
549
586
|
* as a READ-ONLY SNAPSHOT COPY.
|
|
@@ -570,10 +607,14 @@ const freezeFiles = async (dir) => {
|
|
|
570
607
|
* skill paths). Optional — when omitted, relative paths fall back to
|
|
571
608
|
* `workspacePath`.
|
|
572
609
|
*
|
|
610
|
+
* A workspace whose .claude or .claude/skills is a link, or not a directory,
|
|
611
|
+
* gets no mount at all: every source is reported as 'unsafe-skill-dir' and
|
|
612
|
+
* nothing is written (F171).
|
|
613
|
+
*
|
|
573
614
|
* Returns `{ mounted, conflicted }`:
|
|
574
615
|
* - `mounted`: string[] — absolute source paths snapshotted
|
|
575
616
|
* - `conflicted`: Array<{path, reason}> where reason ∈
|
|
576
|
-
* 'not-a-mount' | 'missing-source'
|
|
617
|
+
* 'not-a-mount' | 'missing-source' | 'unsafe-skill-dir'
|
|
577
618
|
*/
|
|
578
619
|
export const mountSkills = async (spec, workspacePath, envFileDir = null) => {
|
|
579
620
|
const sources = Array.isArray(spec?.skills?.claude) ? spec.skills.claude : [];
|
|
@@ -581,8 +622,16 @@ export const mountSkills = async (spec, workspacePath, envFileDir = null) => {
|
|
|
581
622
|
const conflicted = [];
|
|
582
623
|
if (sources.length === 0) return { mounted, conflicted };
|
|
583
624
|
|
|
584
|
-
const skillsDir =
|
|
585
|
-
|
|
625
|
+
const skillsDir = await realSkillsDir(workspacePath);
|
|
626
|
+
if (!skillsDir) {
|
|
627
|
+
return {
|
|
628
|
+
mounted,
|
|
629
|
+
conflicted: sources.map((rawSource) => ({
|
|
630
|
+
path: resolveSkillSource(rawSource, envFileDir || workspacePath),
|
|
631
|
+
reason: 'unsafe-skill-dir',
|
|
632
|
+
})),
|
|
633
|
+
};
|
|
634
|
+
}
|
|
586
635
|
|
|
587
636
|
for (const rawSource of sources) {
|
|
588
637
|
const absSource = resolveSkillSource(rawSource, envFileDir || workspacePath);
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { accessSync, constants as fsConstants } from 'node:fs';
|
|
1
|
+
import { accessSync, constants as fsConstants, statSync } from 'node:fs';
|
|
2
2
|
import { delimiter, isAbsolute, join } from 'node:path';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The first executable `name` on `pathValue`, absolute, or null. No shell
|
|
6
6
|
* involved, and only absolute PATH entries count: a relative entry would
|
|
7
7
|
* resolve against whatever the daemon's working directory happens to be.
|
|
8
|
+
* Only a file counts: X_OK passes a directory, and execvp passes over one
|
|
9
|
+
* (EACCES) to the next entry, so a same-named folder earlier on PATH must not
|
|
10
|
+
* be returned as the binary (F146).
|
|
8
11
|
*/
|
|
9
12
|
export const resolveOnPath = (name, pathValue) => {
|
|
10
13
|
for (const dir of String(pathValue || '').split(delimiter)) {
|
|
@@ -12,7 +15,7 @@ export const resolveOnPath = (name, pathValue) => {
|
|
|
12
15
|
const candidate = join(dir, name);
|
|
13
16
|
try {
|
|
14
17
|
accessSync(candidate, fsConstants.X_OK);
|
|
15
|
-
return candidate;
|
|
18
|
+
if (statSync(candidate).isFile()) return candidate;
|
|
16
19
|
} catch { /* next */ }
|
|
17
20
|
}
|
|
18
21
|
return null;
|