@picassohq/cli 0.0.0-stage → 1.0.2
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/agents/browser_agent.yaml +53 -0
- package/agents/code_reviewer.yaml +49 -0
- package/agents/codebase_investigator.yaml +70 -0
- package/agents/design_auditor.yaml +50 -0
- package/agents/devex_auditor.yaml +50 -0
- package/agents/doc_writer.yaml +54 -0
- package/agents/engineering_architect.yaml +51 -0
- package/agents/generalist.yaml +55 -0
- package/agents/migration_planner.yaml +51 -0
- package/agents/product_reviewer.yaml +48 -0
- package/agents/qa_operator.yaml +52 -0
- package/agents/release_engineer.yaml +50 -0
- package/agents/security_auditor.yaml +62 -0
- package/agents/test_writer.yaml +52 -0
- package/assets/first-light-lockup.png +0 -0
- package/assets/first-light-tagline.png +0 -0
- package/assets/house/README.md +26 -0
- package/assets/house/auraone-banner.png +0 -0
- package/assets/house/auraone-logo.png +0 -0
- package/assets/house/kiro-prism-banner.png +0 -0
- package/assets/house/kiro-prism-logo.png +0 -0
- package/assets/house/picasso-banner.png +0 -0
- package/assets/house/picasso-logo.png +0 -0
- package/assets/wordmark-app.png +0 -0
- package/assets/wordmark-tight.png +0 -0
- package/assets/wordmark.png +0 -0
- package/design/styles.css +1042 -0
- package/dist/build-info.json +37 -0
- package/dist/index.js +3062 -0
- package/goals/cli-hardening.yaml +40 -0
- package/goals/repo-maintenance.yaml +40 -0
- package/package.json +49 -4
- package/runtime/dsh/picasso-ecosystem.community.amendments.yml +24 -0
- package/runtime/dsh/picasso-ecosystem.community.json +185 -0
- package/runtime/dsh/picasso-ecosystem.community.patch.yml +40 -0
- package/runtime/dsh/picasso-ecosystem.cordis.patch.yml +143 -0
- package/runtime/dsh/picasso-isolation.patch.yml +25 -0
- package/runtime/dsh/picasso-providers.patch.yml +373 -0
- package/runtime/dsh/picasso-runtime.cordis.yml +738 -0
- package/runtime/dsh/picasso-sdk.patch.yml +204 -0
- package/runtime/engine-manifest.json +215 -0
- package/runtime/package.json +6 -0
- package/runtime/packages/picasso-cache-probe/cordis.patch.yml +5 -0
- package/runtime/packages/picasso-cache-probe/index.js +477 -0
- package/runtime/packages/picasso-cache-probe/package.json +38 -0
- package/runtime/packages/picasso-commands/cordis.patch.yml +4 -0
- package/runtime/packages/picasso-commands/fresh-review.js +573 -0
- package/runtime/packages/picasso-commands/index.js +497 -0
- package/runtime/packages/picasso-commands/package.json +28 -0
- package/runtime/packages/picasso-instructions/conflicts.js +115 -0
- package/runtime/packages/picasso-instructions/formats.js +145 -0
- package/runtime/packages/picasso-instructions/frontmatter.js +175 -0
- package/runtime/packages/picasso-instructions/glob.js +114 -0
- package/runtime/packages/picasso-instructions/globals.js +90 -0
- package/runtime/packages/picasso-instructions/imports.js +123 -0
- package/runtime/packages/picasso-instructions/index.js +326 -0
- package/runtime/packages/picasso-instructions/modes.js +64 -0
- package/runtime/packages/picasso-instructions/package.json +30 -0
- package/runtime/packages/picasso-instructions/parse.js +134 -0
- package/runtime/packages/picasso-instructions/report.js +161 -0
- package/runtime/packages/picasso-instructions/resolve.js +939 -0
- package/runtime/packages/picasso-instructions/scan.js +181 -0
- package/runtime/packages/picasso-instructions/settings.js +150 -0
- package/runtime/packages/picasso-instructions/skills.js +345 -0
- package/runtime/packages/picasso-lean-context/cordis.patch.yml +13 -0
- package/runtime/packages/picasso-lean-context/index.js +6280 -0
- package/runtime/packages/picasso-lean-context/package.json +26 -0
- package/runtime/packages/picasso-lean-context/read-image-recovery.js +306 -0
- package/runtime/packages/picasso-lean-context/timeline.js +418 -0
- package/runtime/packages/picasso-librarian/classify.js +146 -0
- package/runtime/packages/picasso-librarian/cordis.patch.yml +10 -0
- package/runtime/packages/picasso-librarian/index.js +878 -0
- package/runtime/packages/picasso-librarian/notes.js +159 -0
- package/runtime/packages/picasso-librarian/package.json +34 -0
- package/runtime/packages/picasso-librarian/state.js +478 -0
- package/runtime/packages/picasso-memory/index.js +1184 -0
- package/runtime/packages/picasso-memory/package.json +21 -0
- package/runtime/packages/picasso-model-router/connections.js +912 -0
- package/runtime/packages/picasso-model-router/cordis.patch.yml +17 -0
- package/runtime/packages/picasso-model-router/index.js +1083 -0
- package/runtime/packages/picasso-model-router/package.json +30 -0
- package/runtime/packages/picasso-options/cordis.patch.yml +4 -0
- package/runtime/packages/picasso-options/index.js +263 -0
- package/runtime/packages/picasso-options/package.json +28 -0
- package/runtime/packages/picasso-progress-reports/cordis.patch.yml +10 -0
- package/runtime/packages/picasso-progress-reports/index.js +267 -0
- package/runtime/packages/picasso-progress-reports/package.json +30 -0
- package/runtime/packages/picasso-progress-reports/report.js +235 -0
- package/runtime/packages/picasso-sdk-server/aside.js +142 -0
- package/runtime/packages/picasso-sdk-server/connections.js +38 -0
- package/runtime/packages/picasso-sdk-server/context-timeline.js +27 -0
- package/runtime/packages/picasso-sdk-server/egress-gate.js +520 -0
- package/runtime/packages/picasso-sdk-server/failure-policy.js +246 -0
- package/runtime/packages/picasso-sdk-server/file-input.js +169 -0
- package/runtime/packages/picasso-sdk-server/goal.js +131 -0
- package/runtime/packages/picasso-sdk-server/ignore-file.js +458 -0
- package/runtime/packages/picasso-sdk-server/ignore-plugin.js +12 -0
- package/runtime/packages/picasso-sdk-server/ignore-sandbox.js +122 -0
- package/runtime/packages/picasso-sdk-server/ignore-snapshot.js +131 -0
- package/runtime/packages/picasso-sdk-server/image-input.js +44 -0
- package/runtime/packages/picasso-sdk-server/index.js +891 -0
- package/runtime/packages/picasso-sdk-server/instructions.js +34 -0
- package/runtime/packages/picasso-sdk-server/jobs.js +113 -0
- package/runtime/packages/picasso-sdk-server/mcp-gate.js +51 -0
- package/runtime/packages/picasso-sdk-server/model-selection.js +162 -0
- package/runtime/packages/picasso-sdk-server/package.json +50 -0
- package/runtime/packages/picasso-sdk-server/picasso-records.js +50 -0
- package/runtime/packages/picasso-sdk-server/provider-reload.js +84 -0
- package/runtime/packages/picasso-sdk-server/queue.js +322 -0
- package/runtime/packages/picasso-sdk-server/requester.js +43 -0
- package/runtime/packages/picasso-sdk-server/rewind.js +108 -0
- package/runtime/packages/picasso-sdk-server/schedule.js +187 -0
- package/runtime/packages/picasso-sdk-server/session-grants.js +35 -0
- package/runtime/packages/picasso-sdk-server/session-state.js +118 -0
- package/runtime/packages/picasso-sdk-server/shell-paths.js +869 -0
- package/runtime/packages/picasso-sdk-server/stream-deltas.js +211 -0
- package/runtime/packages/picasso-sdk-server/team-tasks.js +451 -0
- package/runtime/packages/picasso-sdk-server/tool-output.js +128 -0
- package/runtime/packages/picasso-sdk-server/tools-list.js +51 -0
- package/runtime/packages/picasso-sdk-server/wave2-hooks.js +612 -0
- package/runtime/packages/picasso-sdk-server/workspace-archive.js +170 -0
- package/runtime/packages/picasso-sdk-server/workspace-restore.js +180 -0
- package/runtime/packages/picasso-web-search/backends.js +412 -0
- package/runtime/packages/picasso-web-search/config.js +121 -0
- package/runtime/packages/picasso-web-search/cordis.patch.yml +7 -0
- package/runtime/packages/picasso-web-search/failure.js +116 -0
- package/runtime/packages/picasso-web-search/format.js +42 -0
- package/runtime/packages/picasso-web-search/index.js +71 -0
- package/runtime/packages/picasso-web-search/package.json +38 -0
- package/runtime/packages/picasso-web-search/router.js +156 -0
- package/runtime/packages/picasso-x-reader/circle.js +324 -0
- package/runtime/packages/picasso-x-reader/command.js +169 -0
- package/runtime/packages/picasso-x-reader/cordis.patch.yml +8 -0
- package/runtime/packages/picasso-x-reader/index.js +170 -0
- package/runtime/packages/picasso-x-reader/package.json +39 -0
- package/runtime/packages/picasso-x-reader/read.js +370 -0
- package/runtime/packages/picasso-x-reader/rewrite.js +38 -0
- package/runtime/packages/picasso-x-reader/settings.js +131 -0
- package/runtime/packages/picasso-x-reader/urls.js +154 -0
- package/runtime/packages/picasso-x-reader/xmd.js +512 -0
- package/runtime/plugins/picasso-auth-bridge/index.js +380 -0
- package/runtime/plugins/picasso-auth-bridge/package.json +28 -0
- package/runtime/plugins/picasso-auto-approve/index.js +1003 -0
- package/runtime/plugins/picasso-auto-approve/package.json +28 -0
- package/runtime/plugins/picasso-browser/index.js +424 -0
- package/runtime/plugins/picasso-browser/package.json +28 -0
- package/runtime/plugins/picasso-checkpoints/evidence.js +210 -0
- package/runtime/plugins/picasso-checkpoints/index.js +885 -0
- package/runtime/plugins/picasso-checkpoints/package.json +29 -0
- package/runtime/plugins/picasso-commands/fresh-review.js +573 -0
- package/runtime/plugins/picasso-commands/index.js +497 -0
- package/runtime/plugins/picasso-commands/package.json +28 -0
- package/runtime/plugins/picasso-instructions/conflicts.js +115 -0
- package/runtime/plugins/picasso-instructions/formats.js +145 -0
- package/runtime/plugins/picasso-instructions/frontmatter.js +175 -0
- package/runtime/plugins/picasso-instructions/glob.js +114 -0
- package/runtime/plugins/picasso-instructions/globals.js +90 -0
- package/runtime/plugins/picasso-instructions/imports.js +123 -0
- package/runtime/plugins/picasso-instructions/index.js +326 -0
- package/runtime/plugins/picasso-instructions/modes.js +64 -0
- package/runtime/plugins/picasso-instructions/package.json +30 -0
- package/runtime/plugins/picasso-instructions/parse.js +134 -0
- package/runtime/plugins/picasso-instructions/report.js +161 -0
- package/runtime/plugins/picasso-instructions/resolve.js +939 -0
- package/runtime/plugins/picasso-instructions/scan.js +181 -0
- package/runtime/plugins/picasso-instructions/settings.js +150 -0
- package/runtime/plugins/picasso-instructions/skills.js +345 -0
- package/runtime/plugins/picasso-lean-context/index.js +6280 -0
- package/runtime/plugins/picasso-lean-context/package.json +26 -0
- package/runtime/plugins/picasso-lean-context/read-image-recovery.js +306 -0
- package/runtime/plugins/picasso-lean-context/timeline.js +418 -0
- package/runtime/plugins/picasso-librarian/classify.js +146 -0
- package/runtime/plugins/picasso-librarian/index.js +878 -0
- package/runtime/plugins/picasso-librarian/notes.js +159 -0
- package/runtime/plugins/picasso-librarian/package.json +34 -0
- package/runtime/plugins/picasso-librarian/state.js +478 -0
- package/runtime/plugins/picasso-lifecycle-hooks/index.js +186 -0
- package/runtime/plugins/picasso-lifecycle-hooks/package.json +25 -0
- package/runtime/plugins/picasso-mail/inbox.js +207 -0
- package/runtime/plugins/picasso-mail/index.js +293 -0
- package/runtime/plugins/picasso-mail/package.json +22 -0
- package/runtime/plugins/picasso-memory/index.js +1184 -0
- package/runtime/plugins/picasso-memory/package.json +21 -0
- package/runtime/plugins/picasso-model-router/connections.js +912 -0
- package/runtime/plugins/picasso-model-router/index.js +1083 -0
- package/runtime/plugins/picasso-model-router/package.json +30 -0
- package/runtime/plugins/picasso-options/index.js +263 -0
- package/runtime/plugins/picasso-options/package.json +28 -0
- package/runtime/plugins/picasso-progress-reports/index.js +267 -0
- package/runtime/plugins/picasso-progress-reports/package.json +30 -0
- package/runtime/plugins/picasso-progress-reports/report.js +235 -0
- package/runtime/plugins/picasso-provider-models/index.js +436 -0
- package/runtime/plugins/picasso-provider-models/package.json +28 -0
- package/runtime/plugins/picasso-repo-index/index.js +1850 -0
- package/runtime/plugins/picasso-repo-index/package.json +28 -0
- package/runtime/plugins/picasso-schedule-pause/index.js +344 -0
- package/runtime/plugins/picasso-schedule-pause/package.json +28 -0
- package/runtime/plugins/picasso-session-lifecycle/index.js +796 -0
- package/runtime/plugins/picasso-session-lifecycle/package.json +28 -0
- package/runtime/plugins/picasso-trackers/index.js +895 -0
- package/runtime/plugins/picasso-trackers/package.json +28 -0
- package/runtime/plugins/picasso-web-search/backends.js +412 -0
- package/runtime/plugins/picasso-web-search/config.js +121 -0
- package/runtime/plugins/picasso-web-search/failure.js +116 -0
- package/runtime/plugins/picasso-web-search/format.js +42 -0
- package/runtime/plugins/picasso-web-search/index.js +71 -0
- package/runtime/plugins/picasso-web-search/package.json +38 -0
- package/runtime/plugins/picasso-web-search/router.js +156 -0
- package/runtime/plugins/picasso-x-reader/circle.js +324 -0
- package/runtime/plugins/picasso-x-reader/command.js +169 -0
- package/runtime/plugins/picasso-x-reader/index.js +170 -0
- package/runtime/plugins/picasso-x-reader/package.json +39 -0
- package/runtime/plugins/picasso-x-reader/read.js +370 -0
- package/runtime/plugins/picasso-x-reader/rewrite.js +38 -0
- package/runtime/plugins/picasso-x-reader/settings.js +131 -0
- package/runtime/plugins/picasso-x-reader/urls.js +154 -0
- package/runtime/plugins/picasso-x-reader/xmd.js +512 -0
- package/runtime/relay/attachment-text.mjs +737 -0
- package/runtime/relay/companion/companion.css +126 -0
- package/runtime/relay/companion/companion.js +648 -0
- package/runtime/relay/companion/icon.svg +5 -0
- package/runtime/relay/companion/index.html +25 -0
- package/runtime/relay/companion/manifest.json +13 -0
- package/runtime/relay/companion/sw.js +41 -0
- package/runtime/relay/main.mjs +38580 -0
- package/runtime/relay/model-listing.mjs +614 -0
- package/runtime/relay/versions-routes.mjs +1400 -0
- package/runtime/verify-plugins.mjs +205 -0
- package/runtime-lock/package-lock.json +10779 -0
- package/runtime-lock/package.json +7 -0
- package/scripts/install-runtime.mjs +400 -0
- package/README.md +0 -3
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
// `.picassoignore`: gitignore-syntax paths the agent must not see.
|
|
2
|
+
//
|
|
3
|
+
// dsh's own tools deliberately ignore ignore files (`glob` and `grep` run
|
|
4
|
+
// ripgrep with `--no-ignore --hidden`, `read` reads any path the sandbox
|
|
5
|
+
// allows), and dsh has no ignore configuration to feed. So the Picasso SDK
|
|
6
|
+
// server enforces `.picassoignore` on dsh's tool pipeline:
|
|
7
|
+
//
|
|
8
|
+
// tools/pre-execute a path argument (read/write/edit/read_image
|
|
9
|
+
// `file_path`, str_replace_editor `path`, glob/grep
|
|
10
|
+
// search `path`, path-like arguments of other tools) or
|
|
11
|
+
// a shell command (bash/pwsh/terminal) that would touch
|
|
12
|
+
// an ignored path, or read a directory tree holding
|
|
13
|
+
// one, is denied with a model-visible reason
|
|
14
|
+
// (shell-paths.js parses the command line).
|
|
15
|
+
// tools/post-execute ignored paths are dropped from `glob` and `grep`
|
|
16
|
+
// results (the value is replaced, so the tool re-renders).
|
|
17
|
+
//
|
|
18
|
+
// The nearest `.picassoignore` at or above the session working directory
|
|
19
|
+
// applies; its patterns are relative to the directory holding it. Syntax is
|
|
20
|
+
// gitignore's: `#` comments, `!` negation, trailing `/` for directories, a
|
|
21
|
+
// leading or inner `/` anchors to the file's directory, `*`, `?`, `[...]`,
|
|
22
|
+
// `**`. As in git, a path inside an ignored directory stays ignored.
|
|
23
|
+
// The same matcher backs the CLI's `@` picker (@picasso/core ignore-file.ts).
|
|
24
|
+
import { execFileSync } from 'node:child_process';
|
|
25
|
+
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
26
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
27
|
+
import { fileURLToPath } from 'node:url';
|
|
28
|
+
import { installIgnoreSandbox } from './ignore-sandbox.js';
|
|
29
|
+
import { shellReferences } from './shell-paths.js';
|
|
30
|
+
|
|
31
|
+
export const PICASSO_IGNORE_FILE = '.picassoignore';
|
|
32
|
+
|
|
33
|
+
const escapeRegex = (char) => char.replace(/[.*+?^${}()|[\]\\/]/gu, '\\$&');
|
|
34
|
+
|
|
35
|
+
function globSource(glob) {
|
|
36
|
+
let source = '';
|
|
37
|
+
for (let index = 0; index < glob.length; index += 1) {
|
|
38
|
+
const char = glob[index];
|
|
39
|
+
if (char === '*') {
|
|
40
|
+
if (glob[index + 1] === '*') {
|
|
41
|
+
const atSegmentStart = index === 0 || glob[index - 1] === '/';
|
|
42
|
+
if (atSegmentStart && glob[index + 2] === '/') {
|
|
43
|
+
source += '(?:.*/)?';
|
|
44
|
+
index += 2;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (atSegmentStart && index + 2 === glob.length) {
|
|
48
|
+
source += '.*';
|
|
49
|
+
index += 1;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
source += '[^/]*';
|
|
53
|
+
index += 1;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
source += '[^/]*';
|
|
57
|
+
} else if (char === '?') {
|
|
58
|
+
source += '[^/]';
|
|
59
|
+
} else if (char === '[') {
|
|
60
|
+
const close = glob.indexOf(']', index + 2);
|
|
61
|
+
if (close < 0) {
|
|
62
|
+
source += '\\[';
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
let body = glob.slice(index + 1, close).replace(/\\/gu, '\\\\');
|
|
66
|
+
if (body.startsWith('!')) body = `^${body.slice(1)}`;
|
|
67
|
+
source += `[${body}]`;
|
|
68
|
+
index = close;
|
|
69
|
+
} else if (char === '\\' && index + 1 < glob.length) {
|
|
70
|
+
index += 1;
|
|
71
|
+
source += escapeRegex(glob[index]);
|
|
72
|
+
} else {
|
|
73
|
+
source += escapeRegex(char);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return source;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Parse gitignore-syntax text into ordered rules. */
|
|
80
|
+
export function parseIgnore(text) {
|
|
81
|
+
const rules = [];
|
|
82
|
+
for (const rawLine of String(text).split(/\r?\n/u)) {
|
|
83
|
+
let line = rawLine.replace(/(?<!\\)\s+$/u, '');
|
|
84
|
+
if (line.length === 0 || line.startsWith('#')) continue;
|
|
85
|
+
let negate = false;
|
|
86
|
+
if (line.startsWith('!')) {
|
|
87
|
+
negate = true;
|
|
88
|
+
line = line.slice(1);
|
|
89
|
+
} else if (line.startsWith('\\!') || line.startsWith('\\#')) {
|
|
90
|
+
line = line.slice(1);
|
|
91
|
+
}
|
|
92
|
+
let dirOnly = false;
|
|
93
|
+
if (line.endsWith('/')) {
|
|
94
|
+
dirOnly = true;
|
|
95
|
+
line = line.replace(/\/+$/u, '');
|
|
96
|
+
}
|
|
97
|
+
if (line.length === 0) continue;
|
|
98
|
+
const anchored = line.includes('/');
|
|
99
|
+
if (line.startsWith('/')) line = line.slice(1);
|
|
100
|
+
rules.push({ pattern: rawLine.trim(), negate, dirOnly, anchored, regex: new RegExp(`^${globSource(line)}$`, 'u') });
|
|
101
|
+
}
|
|
102
|
+
return rules;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** A matcher over parsed rules; `ignores(relativePath, isDirectory?)` with `/`-separated paths. */
|
|
106
|
+
export function createIgnoreMatcher(text) {
|
|
107
|
+
const rules = parseIgnore(text);
|
|
108
|
+
const test = (path, isDirectory) => {
|
|
109
|
+
let ignored = false;
|
|
110
|
+
const name = path.slice(path.lastIndexOf('/') + 1);
|
|
111
|
+
for (const rule of rules) {
|
|
112
|
+
if (rule.dirOnly && !isDirectory) continue;
|
|
113
|
+
if (rule.negate !== ignored) continue;
|
|
114
|
+
if (rule.regex.test(rule.anchored ? path : name)) ignored = !rule.negate;
|
|
115
|
+
}
|
|
116
|
+
return ignored;
|
|
117
|
+
};
|
|
118
|
+
return {
|
|
119
|
+
rules,
|
|
120
|
+
ignores(relativePath, isDirectory = false) {
|
|
121
|
+
const parts = String(relativePath).split(/[\\/]+/u).filter((part) => part.length > 0 && part !== '.');
|
|
122
|
+
if (parts.length === 0 || parts[0] === '..') return false;
|
|
123
|
+
for (let depth = 1; depth <= parts.length; depth += 1) {
|
|
124
|
+
if (test(parts.slice(0, depth).join('/'), depth < parts.length || isDirectory)) return true;
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The real path of `path`, or of its nearest existing ancestor joined with the missing rest. */
|
|
132
|
+
function canonicalPath(path) {
|
|
133
|
+
try {
|
|
134
|
+
return realpathSync(path);
|
|
135
|
+
} catch {
|
|
136
|
+
const parent = dirname(path);
|
|
137
|
+
return parent === path ? path : join(canonicalPath(parent), basename(path));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The nearest `.picassoignore` at or above `cwd`, or undefined. */
|
|
142
|
+
export function findIgnoreFile(cwd) {
|
|
143
|
+
let dir = resolve(cwd);
|
|
144
|
+
for (;;) {
|
|
145
|
+
const candidate = join(dir, PICASSO_IGNORE_FILE);
|
|
146
|
+
if (existsSync(candidate)) return candidate;
|
|
147
|
+
const parent = dirname(dir);
|
|
148
|
+
if (parent === dir) return undefined;
|
|
149
|
+
dir = parent;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const SCAN_LIMIT = 100000;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Ignore lookups for working directories, cached per ignore file and mtime so
|
|
157
|
+
* an edited `.picassoignore` applies on the next tool call.
|
|
158
|
+
*/
|
|
159
|
+
export function createIgnoreIndex({ scanLimit = SCAN_LIMIT } = {}) {
|
|
160
|
+
const cache = new Map();
|
|
161
|
+
const scans = new Map();
|
|
162
|
+
const load = (file) => {
|
|
163
|
+
let mtime;
|
|
164
|
+
try {
|
|
165
|
+
mtime = statSync(file).mtimeMs;
|
|
166
|
+
} catch {
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
const cached = cache.get(file);
|
|
170
|
+
if (cached?.mtime === mtime) return cached.matcher;
|
|
171
|
+
let text = '';
|
|
172
|
+
try {
|
|
173
|
+
text = readFileSync(file, 'utf8');
|
|
174
|
+
} catch {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
const matcher = createIgnoreMatcher(text);
|
|
178
|
+
cache.set(file, { mtime, matcher });
|
|
179
|
+
return matcher;
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
/** Whether `path` (absolute, or relative to `cwd`) is excluded for a session working in `cwd`. */
|
|
183
|
+
ignored(cwd, path, isDirectory) {
|
|
184
|
+
const file = findIgnoreFile(cwd);
|
|
185
|
+
if (file === undefined) return false;
|
|
186
|
+
const matcher = load(file);
|
|
187
|
+
if (matcher === undefined || matcher.rules.length === 0) return false;
|
|
188
|
+
let absolute = isAbsolute(path) ? path : resolve(cwd, path);
|
|
189
|
+
let rel = relative(dirname(file), absolute);
|
|
190
|
+
if (rel.startsWith('..') || isAbsolute(rel)) {
|
|
191
|
+
// `/var/…` vs `/private/var/…`: compare canonical spellings.
|
|
192
|
+
absolute = canonicalPath(absolute);
|
|
193
|
+
rel = relative(canonicalPath(dirname(file)), absolute);
|
|
194
|
+
}
|
|
195
|
+
if (rel === '' || rel.startsWith('..') || isAbsolute(rel)) return false;
|
|
196
|
+
let directory = isDirectory;
|
|
197
|
+
if (directory === undefined) {
|
|
198
|
+
try {
|
|
199
|
+
directory = statSync(absolute).isDirectory();
|
|
200
|
+
} catch {
|
|
201
|
+
directory = false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return matcher.ignores(rel.split(sep).join('/'), directory);
|
|
205
|
+
},
|
|
206
|
+
/**
|
|
207
|
+
* Every ignored path under the `.picassoignore` that applies to `cwd`
|
|
208
|
+
* (an ignored directory is listed once, not descended), bounded to
|
|
209
|
+
* `scanLimit` visited entries; cached briefly per ignore file.
|
|
210
|
+
*/
|
|
211
|
+
scan(cwd, within) {
|
|
212
|
+
const file = findIgnoreFile(cwd);
|
|
213
|
+
if (file === undefined) return { root: undefined, entries: [], truncated: false };
|
|
214
|
+
const matcher = load(file);
|
|
215
|
+
const root = dirname(file);
|
|
216
|
+
if (matcher === undefined || matcher.rules.length === 0) return { root, entries: [], truncated: false };
|
|
217
|
+
// `within`: only the subtree at that directory (used when the whole-workspace scan was truncated).
|
|
218
|
+
const start = within === undefined ? '' : relative(root, resolve(within)).split(sep).join('/');
|
|
219
|
+
if (start.startsWith('..') || isAbsolute(start)) return { root, entries: [], truncated: false };
|
|
220
|
+
const key = `${file}\0${start}`;
|
|
221
|
+
const cached = scans.get(key);
|
|
222
|
+
if (cached !== undefined && cached.matcher === matcher && Date.now() - cached.at < SCAN_TTL_MS) return cached.result;
|
|
223
|
+
const result = scanIgnored(root, matcher, start, scanLimit);
|
|
224
|
+
scans.set(key, { at: Date.now(), matcher, result });
|
|
225
|
+
while (scans.size > MAX_CACHED_SCANS) scans.delete(scans.keys().next().value);
|
|
226
|
+
return result;
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const SCAN_TTL_MS = 2000;
|
|
232
|
+
const MAX_CACHED_SCANS = 64;
|
|
233
|
+
|
|
234
|
+
function scanIgnored(root, matcher, start, limit) {
|
|
235
|
+
const entries = [];
|
|
236
|
+
let visited = 0;
|
|
237
|
+
let truncated = false;
|
|
238
|
+
const stack = [start];
|
|
239
|
+
while (stack.length > 0) {
|
|
240
|
+
const rel = stack.pop();
|
|
241
|
+
let children;
|
|
242
|
+
try {
|
|
243
|
+
children = readdirSync(rel === '' ? root : join(root, rel), { withFileTypes: true });
|
|
244
|
+
} catch {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
for (const child of children) {
|
|
248
|
+
visited += 1;
|
|
249
|
+
if (visited > limit) {
|
|
250
|
+
truncated = true;
|
|
251
|
+
return { root, entries, truncated };
|
|
252
|
+
}
|
|
253
|
+
const childRel = rel === '' ? child.name : `${rel}/${child.name}`;
|
|
254
|
+
const directory = child.isDirectory();
|
|
255
|
+
if (matcher.ignores(childRel, directory)) entries.push({ path: join(root, childRel), directory });
|
|
256
|
+
else if (directory && child.name !== '.git') stack.push(childRel);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return { root, entries, truncated };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const isWithin = (parent, child) => child === parent || child.startsWith(parent.endsWith(sep) ? parent : `${parent}${sep}`);
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Whether reading `dir` as a tree would reach an ignored path for a session
|
|
266
|
+
* in `cwd`. With `gitTracked`, only ignored files git tracks count (a git
|
|
267
|
+
* read sees the repository, not the work tree). A truncated scan is treated
|
|
268
|
+
* as containing ignored files.
|
|
269
|
+
*/
|
|
270
|
+
export function containsIgnored(index, cwd, dir, { gitTracked = false } = {}) {
|
|
271
|
+
const { root, entries, truncated } = index.scan(cwd);
|
|
272
|
+
if (root === undefined) return false;
|
|
273
|
+
const target = resolve(dir);
|
|
274
|
+
if (!isWithin(root, target) && !isWithin(target, root)) return false;
|
|
275
|
+
let inside = entries.filter((entry) => isWithin(target, entry.path) || isWithin(entry.path, target));
|
|
276
|
+
if (inside.length === 0 && truncated && target !== root && isWithin(root, target)) {
|
|
277
|
+
// The workspace is too large to scan whole: scan just the directory read.
|
|
278
|
+
const sub = index.scan(cwd, target);
|
|
279
|
+
if (sub.truncated) return true;
|
|
280
|
+
inside = sub.entries;
|
|
281
|
+
} else if (inside.length === 0) return truncated && (isWithin(target, root) || isWithin(root, target));
|
|
282
|
+
if (inside.length === 0) return false;
|
|
283
|
+
if (!gitTracked) return true;
|
|
284
|
+
try {
|
|
285
|
+
const top = execFileSync('git', ['-C', target, 'rev-parse', '--show-toplevel'], { encoding: 'utf8', timeout: 5000, stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
286
|
+
const tracked = execFileSync('git', ['-C', top, 'ls-files', '-z', '--', ...inside.map((entry) => `:(literal)${relative(top, entry.path).split(sep).join('/')}`)], {
|
|
287
|
+
encoding: 'utf8',
|
|
288
|
+
timeout: 5000,
|
|
289
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
290
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
291
|
+
});
|
|
292
|
+
return tracked.length > 0;
|
|
293
|
+
} catch {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const PATH_ARGUMENTS = Object.freeze({
|
|
299
|
+
read: ['file_path'],
|
|
300
|
+
write: ['file_path'],
|
|
301
|
+
edit: ['file_path'],
|
|
302
|
+
read_image: ['file_path'],
|
|
303
|
+
str_replace_editor: ['path'],
|
|
304
|
+
glob: ['path'],
|
|
305
|
+
grep: ['path'],
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
/** Shell tools: the argument holding the command line and the one holding its working directory. */
|
|
309
|
+
const SHELL_TOOLS = Object.freeze({
|
|
310
|
+
bash: { command: 'command', workdir: 'workdir' },
|
|
311
|
+
pwsh: { command: 'command', workdir: 'workdir' },
|
|
312
|
+
terminal_send: { command: 'text' },
|
|
313
|
+
terminal_open: { workdir: 'cwd' },
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Argument names that carry paths in tools Picasso does not know by name
|
|
318
|
+
* (`read_many`, `ls`, LSP tools, MCP file tools): checked wherever they appear.
|
|
319
|
+
*/
|
|
320
|
+
const GENERIC_PATH_KEYS = new Set(['file_path', 'filePath', 'file', 'path', 'paths', 'file_paths', 'filePaths', 'files', 'uri', 'textDocument', 'directory', 'dir', 'target_file', 'targetFile', 'notebook_path', 'source', 'destination']);
|
|
321
|
+
|
|
322
|
+
function genericPaths(args, out = [], depth = 0) {
|
|
323
|
+
if (depth > 3 || args === null || typeof args !== 'object') return out;
|
|
324
|
+
for (const [key, value] of Object.entries(args)) {
|
|
325
|
+
if (GENERIC_PATH_KEYS.has(key)) {
|
|
326
|
+
for (const item of Array.isArray(value) ? value : [value]) {
|
|
327
|
+
if (typeof item === 'string' && item.length > 0) out.push(item.startsWith('file://') ? safeFileUrl(item) : item);
|
|
328
|
+
else if (item !== null && typeof item === 'object') {
|
|
329
|
+
if (typeof item.uri === 'string') out.push(item.uri.startsWith('file://') ? safeFileUrl(item.uri) : item.uri);
|
|
330
|
+
if (typeof item.path === 'string') out.push(item.path);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
} else if (value !== null && typeof value === 'object') genericPaths(value, out, depth + 1);
|
|
334
|
+
}
|
|
335
|
+
return out.filter((item) => typeof item === 'string' && item.length > 0);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function safeFileUrl(url) {
|
|
339
|
+
try {
|
|
340
|
+
return fileURLToPath(url);
|
|
341
|
+
} catch {
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** The paths one tool call names directly (file tools and unknown tools with path-like arguments). */
|
|
347
|
+
export function toolCallPaths(name, args, _cwd) {
|
|
348
|
+
if (args === null || typeof args !== 'object') return [];
|
|
349
|
+
const keys = PATH_ARGUMENTS[name];
|
|
350
|
+
if (keys !== undefined) return keys.map((key) => args[key]).filter((value) => typeof value === 'string' && value.length > 0);
|
|
351
|
+
if (SHELL_TOOLS[name] !== undefined) return [];
|
|
352
|
+
return genericPaths(args);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Everything one tool call would touch, as references for the guard:
|
|
357
|
+
* `{ path, recursive, always, gitTracked }` (see shell-paths.js). Shell tool
|
|
358
|
+
* command lines are parsed relative to their working directory.
|
|
359
|
+
*/
|
|
360
|
+
export function toolCallReferences(name, args, cwd) {
|
|
361
|
+
if (args === null || typeof args !== 'object') return [];
|
|
362
|
+
const shell = SHELL_TOOLS[name];
|
|
363
|
+
if (shell === undefined) return toolCallPaths(name, args, cwd).map((path) => ({ path: resolve(cwd, path), recursive: false, always: true, gitTracked: false }));
|
|
364
|
+
const workdirArg = shell.workdir === undefined ? undefined : args[shell.workdir];
|
|
365
|
+
const workdir = typeof workdirArg === 'string' && workdirArg.length > 0 ? resolve(cwd, workdirArg) : cwd;
|
|
366
|
+
const references = workdir === cwd ? [] : [{ path: workdir, recursive: false, always: true, gitTracked: false }];
|
|
367
|
+
const command = shell.command === undefined ? undefined : args[shell.command];
|
|
368
|
+
if (typeof command === 'string') references.push(...shellReferences(command, workdir, { exists: existsSync }));
|
|
369
|
+
return references;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const isDirectoryPath = (path) => {
|
|
373
|
+
try {
|
|
374
|
+
return statSync(path).isDirectory();
|
|
375
|
+
} catch {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
/** The model-visible reason a tool call is refused, or undefined when nothing it touches is ignored. */
|
|
381
|
+
export function ignoreDenial(index, cwd, name, args) {
|
|
382
|
+
// A sandbox escalation runs outside the sandbox's ignored-path denies
|
|
383
|
+
// (ignore-sandbox.js), so a command that builds paths at run time cannot be
|
|
384
|
+
// verified and is refused while the workspace has ignored files.
|
|
385
|
+
const escalating = typeof args?.sandbox_permissions === 'string' && args.sandbox_permissions.length > 0;
|
|
386
|
+
for (const reference of toolCallReferences(name, args, cwd)) {
|
|
387
|
+
if (reference.opaque === true) {
|
|
388
|
+
if (escalating && index.scan(cwd).entries.length > 0) {
|
|
389
|
+
return `this command builds paths at run time, so it cannot be checked against ${PICASSO_IGNORE_FILE}; a sandbox escalation is refused for it. Name the files explicitly.`;
|
|
390
|
+
}
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
const present = existsSync(reference.path);
|
|
394
|
+
if ((present || reference.always) && index.ignored(cwd, reference.path)) {
|
|
395
|
+
return `${displayPath(cwd, reference.path)} is excluded by ${PICASSO_IGNORE_FILE}; it cannot be read, searched or changed in this workspace.`;
|
|
396
|
+
}
|
|
397
|
+
if (reference.recursive && present && isDirectoryPath(reference.path) && containsIgnored(index, cwd, reference.path, { gitTracked: reference.gitTracked })) {
|
|
398
|
+
return `${reference.command ?? name} would read ${displayPath(cwd, reference.path)}, which contains files excluded by ${PICASSO_IGNORE_FILE}; name the specific files or directories you need, or use the glob/grep tools (they skip ignored files).`;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return undefined;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function displayPath(cwd, path) {
|
|
405
|
+
const rel = relative(cwd, path);
|
|
406
|
+
return rel === '' ? '.' : rel.startsWith('..') || isAbsolute(rel) ? path : rel;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** A glob/grep value without ignored paths, or undefined when nothing was removed. */
|
|
410
|
+
export function filterSearchValue(name, value, isIgnored) {
|
|
411
|
+
if (value === null || typeof value !== 'object') return undefined;
|
|
412
|
+
if (name === 'glob' && Array.isArray(value.paths)) {
|
|
413
|
+
const paths = value.paths.filter((path) => !isIgnored(path));
|
|
414
|
+
return paths.length === value.paths.length ? undefined : { ...value, paths };
|
|
415
|
+
}
|
|
416
|
+
if (name === 'grep' && Array.isArray(value.matches)) {
|
|
417
|
+
const matches = value.matches.filter((match) => !isIgnored(match?.path));
|
|
418
|
+
return matches.length === value.matches.length ? undefined : { ...value, matches };
|
|
419
|
+
}
|
|
420
|
+
return undefined;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Install the `.picassoignore` guard on dsh's tool pipeline. `cwdOf(session)`
|
|
425
|
+
* is the session's working directory (dsh's `workingDirectory` service).
|
|
426
|
+
*/
|
|
427
|
+
export function installIgnoreGuard(ctx, { cwdOf, index = createIgnoreIndex() }) {
|
|
428
|
+
const sessionCwd = (exec) => {
|
|
429
|
+
const session = exec?.agent?.session;
|
|
430
|
+
try {
|
|
431
|
+
return (session === undefined ? undefined : cwdOf(session)) ?? process.cwd();
|
|
432
|
+
} catch {
|
|
433
|
+
return process.cwd();
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
const disposePre = ctx.on('tools/pre-execute', async (exec, next) => {
|
|
437
|
+
const cwd = sessionCwd(exec);
|
|
438
|
+
const reason = ignoreDenial(index, cwd, exec?.name, exec?.arguments);
|
|
439
|
+
if (reason !== undefined) return { kind: 'deny', reason };
|
|
440
|
+
return next();
|
|
441
|
+
}, { prepend: true });
|
|
442
|
+
const disposePost = ctx.on('tools/post-execute', async (exec, result, next) => {
|
|
443
|
+
const decision = await next();
|
|
444
|
+
if (decision?.kind !== 'accept' || result?.isError === true) return decision;
|
|
445
|
+
if (exec?.name !== 'glob' && exec?.name !== 'grep') return decision;
|
|
446
|
+
const cwd = sessionCwd(exec);
|
|
447
|
+
const filtered = filterSearchValue(exec.name, result.value, (path) => typeof path === 'string' && index.ignored(cwd, path, false));
|
|
448
|
+
if (filtered === undefined) return decision;
|
|
449
|
+
const { content: _content, value: _value, ...rest } = decision;
|
|
450
|
+
return { ...rest, kind: 'accept', value: filtered };
|
|
451
|
+
}, { prepend: true });
|
|
452
|
+
const disposeSandbox = installIgnoreSandbox(ctx, { scan: (root) => index.scan(root) });
|
|
453
|
+
return () => {
|
|
454
|
+
disposePre?.();
|
|
455
|
+
disposePost?.();
|
|
456
|
+
disposeSandbox?.();
|
|
457
|
+
};
|
|
458
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Standalone cordis plugin for `.picassoignore` (see ignore-file.js), for dsh
|
|
2
|
+
// profiles that do not mount @picasso/sdk-server.
|
|
3
|
+
import { installIgnoreGuard } from './ignore-file.js';
|
|
4
|
+
|
|
5
|
+
export const name = 'picasso-ignore';
|
|
6
|
+
export const inject = ['workingDirectory'];
|
|
7
|
+
|
|
8
|
+
export function apply(ctx) {
|
|
9
|
+
return installIgnoreGuard(ctx, {
|
|
10
|
+
cwdOf: (session) => (ctx.get?.('workingDirectory') ?? ctx.workingDirectory)?.get(session),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// `.picassoignore` defence in depth for confined shell commands.
|
|
2
|
+
//
|
|
3
|
+
// dsh's sandbox seam has no deny-list configuration: `dsh-sandbox-local`
|
|
4
|
+
// builds its profile from the mode and workspace root only (Seatbelt on
|
|
5
|
+
// macOS: `(allow default) (deny file-write*) …`; bubblewrap on Linux:
|
|
6
|
+
// `--ro-bind / / … --bind <root> <root>`; Landlock: an allow-list). So the
|
|
7
|
+
// Picasso plugins wrap the mounted `sandbox` provider's `confine()` and add
|
|
8
|
+
// the ignored paths of the session workspace to the profile it returns:
|
|
9
|
+
//
|
|
10
|
+
// Seatbelt (deny file-read* file-write* (literal|subpath "<path>"))
|
|
11
|
+
// bubblewrap --ro-bind /dev/null <file> --tmpfs <directory>
|
|
12
|
+
//
|
|
13
|
+
// so a shell command the static guard (shell-paths.js) could not resolve —
|
|
14
|
+
// a path built at run time, a script reading files — still cannot read them.
|
|
15
|
+
// Landlock (allow-list only) and Windows ACL runners are left unchanged, and
|
|
16
|
+
// `danger-full-access` runs are never confined, so this layer only adds to
|
|
17
|
+
// the pre-execute guard; it never replaces it.
|
|
18
|
+
import { realpathSync } from 'node:fs';
|
|
19
|
+
import { basename } from 'node:path';
|
|
20
|
+
|
|
21
|
+
const PATCHED = Symbol.for('picasso.ignore-sandbox');
|
|
22
|
+
const MAX_DENIES = 4096;
|
|
23
|
+
|
|
24
|
+
function sbplString(path) {
|
|
25
|
+
return `"${path.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function canonical(entries) {
|
|
29
|
+
const seen = new Set();
|
|
30
|
+
const result = [];
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
let path;
|
|
33
|
+
try {
|
|
34
|
+
path = realpathSync(entry.path);
|
|
35
|
+
} catch {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (seen.has(path)) continue;
|
|
39
|
+
seen.add(path);
|
|
40
|
+
result.push({ path, directory: entry.directory });
|
|
41
|
+
if (result.length >= MAX_DENIES) break;
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Add read/write denies for `entries` (`{ path, directory }`, absolute) to a
|
|
48
|
+
* confined argv from dsh's local sandbox provider. Unknown runners are
|
|
49
|
+
* returned unchanged.
|
|
50
|
+
* @param {readonly string[]} argv - `[...runner, '--', ...command]`.
|
|
51
|
+
* @param {readonly { path: string, directory: boolean }[]} entries
|
|
52
|
+
* @returns {string[]}
|
|
53
|
+
*/
|
|
54
|
+
export function denyIgnoredInArgv(argv, entries) {
|
|
55
|
+
if (!Array.isArray(argv) || entries.length === 0) return argv;
|
|
56
|
+
const separator = argv.indexOf('--');
|
|
57
|
+
if (separator < 0) return argv;
|
|
58
|
+
const runner = basename(String(argv[0] ?? ''));
|
|
59
|
+
if (runner === 'sandbox-exec' && argv[1] === '-p' && typeof argv[2] === 'string' && separator > 2) {
|
|
60
|
+
const forms = entries.map((entry) => `(deny file-read* file-write* (${entry.directory ? 'subpath' : 'literal'} ${sbplString(entry.path)}))`);
|
|
61
|
+
return [argv[0], argv[1], `${argv[2]} ${forms.join(' ')}`, ...argv.slice(3)];
|
|
62
|
+
}
|
|
63
|
+
const head = argv.slice(0, separator);
|
|
64
|
+
const bwrap = runner === 'bwrap' || head.some((arg, index) => arg === '--ro-bind' && head[index + 1] === '/' && head[index + 2] === '/');
|
|
65
|
+
if (bwrap) {
|
|
66
|
+
const masks = entries.flatMap((entry) => (entry.directory ? ['--tmpfs', entry.path] : ['--ro-bind', '/dev/null', entry.path]));
|
|
67
|
+
return [...head, ...masks, ...argv.slice(separator)];
|
|
68
|
+
}
|
|
69
|
+
return argv;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Wrap `sandbox.confine` once so every confined run hides the ignored paths
|
|
74
|
+
* of its workspace. `scan(workspaceRoot)` lists them (createIgnoreIndex().scan).
|
|
75
|
+
* Idempotent per provider instance; returns whether the provider is wrapped.
|
|
76
|
+
*/
|
|
77
|
+
export function wrapSandboxProvider(provider, scan) {
|
|
78
|
+
if (provider === undefined || provider === null || typeof provider.confine !== 'function') return false;
|
|
79
|
+
if (provider[PATCHED] === true) return true;
|
|
80
|
+
const confine = provider.confine;
|
|
81
|
+
const wrapped = async function picassoIgnoreConfine(argv, policy, signal) {
|
|
82
|
+
const confined = await confine.call(this ?? provider, argv, policy, signal);
|
|
83
|
+
try {
|
|
84
|
+
const root = policy?.workspaceRoot;
|
|
85
|
+
if (typeof root !== 'string' || !Array.isArray(confined?.argv)) return confined;
|
|
86
|
+
const entries = canonical(scan(root).entries);
|
|
87
|
+
if (entries.length === 0) return confined;
|
|
88
|
+
return { ...confined, argv: denyIgnoredInArgv(confined.argv, entries) };
|
|
89
|
+
} catch {
|
|
90
|
+
return confined;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
try {
|
|
94
|
+
provider.confine = wrapped;
|
|
95
|
+
Object.defineProperty(provider, PATCHED, { value: true, enumerable: false, configurable: true });
|
|
96
|
+
} catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return provider.confine === wrapped;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Install the wrapper on the context's `sandbox` service as soon as one is
|
|
104
|
+
* reachable: now when mounted, and again before each tool call (the provider
|
|
105
|
+
* may mount after this plugin).
|
|
106
|
+
*/
|
|
107
|
+
export function installIgnoreSandbox(ctx, { scan }) {
|
|
108
|
+
const attempt = () => {
|
|
109
|
+
let provider;
|
|
110
|
+
try {
|
|
111
|
+
provider = ctx.get?.('sandbox') ?? ctx.sandbox;
|
|
112
|
+
} catch {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
wrapSandboxProvider(provider, scan);
|
|
116
|
+
};
|
|
117
|
+
attempt();
|
|
118
|
+
return ctx.on('tools/pre-execute', async (_exec, next) => {
|
|
119
|
+
attempt();
|
|
120
|
+
return next();
|
|
121
|
+
}, { prepend: true });
|
|
122
|
+
}
|