@cohesivity/init 0.2.1 → 0.2.3
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/bin/cli.js +50 -15
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -34,7 +34,7 @@ const flag = (f) => { const i = argv.indexOf(f); return i >= 0 ? argv[i + 1] : u
|
|
|
34
34
|
if (has('--help') || has('-h')) { help(); process.exit(0); }
|
|
35
35
|
|
|
36
36
|
// ── config ──────────────────────────────────────────────────────────────────
|
|
37
|
-
const PKG_VERSION = '0.2.
|
|
37
|
+
const PKG_VERSION = '0.2.3';
|
|
38
38
|
const BASE = (flag('--base') || process.env.COHESIVITY_BASE || 'https://cohesivity.ai').replace(/\/+$/, '');
|
|
39
39
|
|
|
40
40
|
// Machine id: one per machine, stored outside any project. A project's
|
|
@@ -68,7 +68,7 @@ const ANCESTRY_HEADER = 'X-Cohesivity-Ancestry';
|
|
|
68
68
|
// Closed sets: the plumbing an ancestor chain routes through, the interpreter
|
|
69
69
|
// binaries whose script path carries the real name, and the generic segments
|
|
70
70
|
// inside those paths. Harness names never belong in any of these.
|
|
71
|
-
const PLUMBING = new Set(['sh', 'bash', 'zsh', 'fish', 'dash', 'ksh', 'csh', 'tcsh', 'env', 'sudo', 'doas', 'timeout', 'nice', 'ionice', 'stdbuf', 'setsid', 'nohup', 'xargs', 'script', 'ssh', 'sshd', 'tmux', 'screen', 'login', 'su', 'init', 'systemd', 'launchd', 'docker', 'containerd', 'containerd-shim', 'runc', 'podman', 'npm', 'npx', 'pnpm', 'yarn', 'bunx', 'corepack', 'ps', 'awk', 'grep', 'sed', 'cat', 'tr', 'cut', 'head', 'tail', 'find', 'curl', 'wget', 'gnome-terminal', 'konsole', 'xterm', 'alacritty', 'kitty', 'wezterm', 'tilix', 'terminator', 'iterm2', 'terminal', 'warp-terminal']);
|
|
71
|
+
const PLUMBING = new Set(['sh', 'bash', 'zsh', 'fish', 'dash', 'ksh', 'csh', 'tcsh', 'env', 'sudo', 'doas', 'timeout', 'timelimit', 'nice', 'ionice', 'stdbuf', 'setsid', 'nohup', 'xargs', 'script', 'ssh', 'sshd', 'tmux', 'screen', 'login', 'su', 'init', 'systemd', 'launchd', 'docker', 'containerd', 'containerd-shim', 'runc', 'podman', 'npm', 'npx', 'pnpm', 'yarn', 'bunx', 'corepack', 'ps', 'awk', 'grep', 'sed', 'cat', 'tr', 'cut', 'head', 'tail', 'find', 'curl', 'wget', 'gnome-terminal', 'konsole', 'xterm', 'alacritty', 'kitty', 'wezterm', 'tilix', 'terminator', 'iterm2', 'terminal', 'warp-terminal']);
|
|
72
72
|
const INTERPRETERS = new Set(['node', 'bun', 'deno', 'python', 'python3', 'python2', 'ruby', 'perl']);
|
|
73
73
|
const GENERIC_SEGMENTS = new Set(['dist', 'build', 'bin', '.bin', 'lib', 'libexec', 'src', 'out', 'app', 'node_modules', '_npx', 'versions', 'current', 'cli.js', 'index.js', 'main.js', 'app.js', 'run.py', 'main.py', '__main__.py', 'npm-cli.js', 'npx-cli.js', 'yarn.js', 'pnpm.cjs', 'corepack.js']);
|
|
74
74
|
|
|
@@ -85,11 +85,32 @@ function ancestry() {
|
|
|
85
85
|
const chain = [];
|
|
86
86
|
// Start at the PARENT: this process is `node .../cli.js` and must never
|
|
87
87
|
// infer itself as the harness.
|
|
88
|
-
for (let p = pp[String(process.pid)], i = 0; i < 20 && cmd[p]; p = pp[p], i++) chain.push(cmd[p]);
|
|
89
|
-
return chain.join(' | ').replace(/[^\w ._:;()
|
|
88
|
+
for (let p = pp[String(process.pid)], i = 0; i < 20 && cmd[p]; p = pp[p], i++) chain.push(reduceEntry(cmd[p]));
|
|
89
|
+
return chain.filter(Boolean).join(' | ').replace(/[^\w ._:;()/+~@,|-]/g, '').slice(0, 800) || null;
|
|
90
90
|
} catch { return null; }
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
// Keep the program that ran; drop its arguments before anything is sent.
|
|
94
|
+
//
|
|
95
|
+
// Arguments are pure liability and identify nothing. A real caller's chain
|
|
96
|
+
// reached the server carrying live AWS credentials, because its parent was
|
|
97
|
+
// `sh -c export AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=...`; agent
|
|
98
|
+
// invocations put the user's prompt on the command line the same way. argv[0]
|
|
99
|
+
// names the harness, and for an interpreter the script path does, so one
|
|
100
|
+
// path-like argument that is neither a URL nor a k=v assignment survives.
|
|
101
|
+
function reduceEntry(entry) {
|
|
102
|
+
const tokens = String(entry).trim().split(/\s+/).filter(Boolean);
|
|
103
|
+
if (!tokens.length) return '';
|
|
104
|
+
const prog = tokens[0];
|
|
105
|
+
const base = prog.split('/').pop().replace(/^-/, '');
|
|
106
|
+
if (!INTERPRETERS.has(base)) return prog;
|
|
107
|
+
for (const tok of tokens.slice(1)) {
|
|
108
|
+
if (tok.includes('=') || tok.includes('://')) continue;
|
|
109
|
+
if (tok.includes('/')) return `${prog} ${tok}`;
|
|
110
|
+
}
|
|
111
|
+
return prog;
|
|
112
|
+
}
|
|
113
|
+
|
|
93
114
|
function inferHarness(chain) {
|
|
94
115
|
for (const entry of (chain || '').split(' | ')) {
|
|
95
116
|
const tokens = entry.trim().split(' ');
|
|
@@ -142,18 +163,32 @@ function inferModel(harness) {
|
|
|
142
163
|
};
|
|
143
164
|
for (const r of roots) walk(r, 0);
|
|
144
165
|
files.sort((a, b) => b.m - a.m);
|
|
166
|
+
// Try candidates in order until one yields a model. Testing only the
|
|
167
|
+
// newest file is not enough: a harness touches lock, session-env and
|
|
168
|
+
// file-history files alongside its session log, so the most recently
|
|
169
|
+
// written file frequently carries no model — and reporting "none" while
|
|
170
|
+
// the answer sits in the next file is a loss, not a safe default.
|
|
145
171
|
const cwdKey = CWD.split('/').pop();
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
172
|
+
const ordered = [
|
|
173
|
+
...files.filter((f) => cwdKey && f.p.includes(cwdKey)),
|
|
174
|
+
...files,
|
|
175
|
+
].slice(0, 20);
|
|
176
|
+
for (const pick of ordered) {
|
|
177
|
+
let text;
|
|
178
|
+
try {
|
|
179
|
+
const fd = openSync(pick.p, 'r');
|
|
180
|
+
const len = Math.min(pick.s, 100000);
|
|
181
|
+
const buf = Buffer.alloc(len);
|
|
182
|
+
readSync(fd, buf, 0, len, Math.max(0, pick.s - len));
|
|
183
|
+
closeSync(fd);
|
|
184
|
+
text = buf.toString('utf8');
|
|
185
|
+
} catch { continue; }
|
|
186
|
+
const matches = text.match(/"model(_?[iI][dD])?"\s*:\s*"([^"]{2,50})"/g);
|
|
187
|
+
if (!matches) continue;
|
|
188
|
+
const value = matches[matches.length - 1].match(/"([^"]{2,50})"$/)[1];
|
|
189
|
+
if (/^[A-Za-z0-9][\w .,:=[\]-]{1,63}$/.test(value)) return value;
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
157
192
|
} catch { return null; }
|
|
158
193
|
}
|
|
159
194
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cohesivity/init",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Set up Cohesivity in a project: install the agent skill, create a managed backend tenant, write the project config. Run with `npx @cohesivity/init`.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|