@cohesivity/init 0.3.0 → 0.3.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/bin/cli.js +41 -84
- 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.3.
|
|
37
|
+
const PKG_VERSION = '0.3.2';
|
|
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
|
|
@@ -51,85 +51,43 @@ const MACHINE_ID_FILE = join(MACHINE_ID_DIR, 'machine-id');
|
|
|
51
51
|
const SKILL_PIN = 'a4c0e90373b2d61501e4fb544a760b4a602fc14e';
|
|
52
52
|
const SKILL_URL = `https://raw.githubusercontent.com/cohesivity-org/cohesivity-skill/${SKILL_PIN}/cohesivity.skill.md`;
|
|
53
53
|
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const pp = {}; const cmd = {};
|
|
81
|
-
for (const line of out.split('\n')) {
|
|
82
|
-
const m = line.match(/^\s*(\d+)\s+(\d+)\s+(.*)/);
|
|
83
|
-
if (m) { pp[m[1]] = m[2]; cmd[m[1]] = m[3].split(homedir()).join('~').slice(0, 120); }
|
|
54
|
+
// Harness: the nearest ancestor process that is not generic plumbing. Only
|
|
55
|
+
// this process's own lineage is read — never the system process list — and only
|
|
56
|
+
// the resulting name is sent. The sets below are closed lists of Unix plumbing,
|
|
57
|
+
// interpreters, and generic path segments; they never name a harness, so any
|
|
58
|
+
// harness, present or future, identifies itself by its own process or script
|
|
59
|
+
// name. Nothing inferable -> null, never a guess.
|
|
60
|
+
const PLUMBING = new Set('sh bash zsh fish dash ksh csh tcsh env sudo doas timeout timelimit nice setsid nohup xargs script ssh sshd tmux screen login su init systemd launchd docker containerd containerd-shim runc podman npm npx pnpm yarn bunx ps awk grep sed find curl wget gnome-terminal konsole xterm alacritty kitty wezterm tilix terminator iterm2 terminal warp-terminal'.split(' '));
|
|
61
|
+
const INTERPRETERS = new Set('node bun deno python python2 python3 ruby perl'.split(' '));
|
|
62
|
+
const GENERIC = new Set('cli index main app run dist build bin lib libexec src out node_modules _npx versions current'.split(' '));
|
|
63
|
+
|
|
64
|
+
function inferHarness() {
|
|
65
|
+
let pid = process.ppid;
|
|
66
|
+
for (let i = 0; i < 20 && pid > 1; i++) {
|
|
67
|
+
let argv, ppid;
|
|
68
|
+
try {
|
|
69
|
+
argv = readFileSync(`/proc/${pid}/cmdline`, 'utf8').split('\0').filter(Boolean);
|
|
70
|
+
// A process that rewrites its title (npm does) has no NUL separators
|
|
71
|
+
// left, so the whole command arrives as one element. Re-split it, or
|
|
72
|
+
// argv[0] is an entire command line rather than a program name.
|
|
73
|
+
if (argv.length === 1 && argv[0].includes(' ')) argv = argv[0].split(/\s+/);
|
|
74
|
+
ppid = Number(readFileSync(`/proc/${pid}/stat`, 'utf8').split(') ').pop().split(' ')[1]);
|
|
75
|
+
} catch {
|
|
76
|
+
try {
|
|
77
|
+
argv = execSync(`ps -o args= -p ${pid}`, { timeout: 2000 }).toString().trim().split(/\s+/);
|
|
78
|
+
ppid = Number(execSync(`ps -o ppid= -p ${pid}`, { timeout: 2000 }).toString().trim());
|
|
79
|
+
} catch { return null; }
|
|
84
80
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
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
|
-
|
|
114
|
-
function inferHarness(chain) {
|
|
115
|
-
for (const entry of (chain || '').split(' | ')) {
|
|
116
|
-
const tokens = entry.trim().split(' ');
|
|
117
|
-
const first = (tokens[0] || '').split('/').pop().replace(/^-/, '');
|
|
118
|
-
if (INTERPRETERS.has(first)) {
|
|
119
|
-
// Interpreter: the name lives in the script path (…/pi-coding-agent/dist/cli.js).
|
|
120
|
-
for (const tok of tokens.slice(1)) {
|
|
121
|
-
if (!tok.includes('/')) continue;
|
|
122
|
-
const segs = tok.split('/');
|
|
123
|
-
for (let k = segs.length - 1; k >= 0; k--) {
|
|
124
|
-
const s = segs[k].replace(/^@/, '');
|
|
125
|
-
if (s && s !== '~' && !GENERIC_SEGMENTS.has(s) && !PLUMBING.has(s)) {
|
|
126
|
-
return s.replace(/\.(js|mjs|cjs|py|rb|pl)$/, '').slice(0, 40);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
} else if (first && !PLUMBING.has(first)) {
|
|
131
|
-
return first.slice(0, 40);
|
|
81
|
+
let name = (argv[0] || '').split('/').pop().replace(/^-/, '');
|
|
82
|
+
if (INTERPRETERS.has(name)) {
|
|
83
|
+
const script = argv.slice(1).find((a) => a.includes('/') && !a.includes('='));
|
|
84
|
+
const segs = (script || '').split('/').filter(Boolean);
|
|
85
|
+
while (segs.length && GENERIC.has(segs[segs.length - 1].replace(/\.\w+$/, ''))) segs.pop();
|
|
86
|
+
if (segs.length) name = segs.pop().replace(/\.\w+$/, '');
|
|
132
87
|
}
|
|
88
|
+
if (name && !PLUMBING.has(name)) return name.replace(/[^\w.-]/g, '').slice(0, 40) || null;
|
|
89
|
+
if (!Number.isFinite(ppid)) return null;
|
|
90
|
+
pid = ppid;
|
|
133
91
|
}
|
|
134
92
|
return null;
|
|
135
93
|
}
|
|
@@ -142,11 +100,10 @@ const rel = (p) => p.replace(CWD + '/', '');
|
|
|
142
100
|
const log = (m) => console.log(`cohesivity: ${m}`);
|
|
143
101
|
const act = (m) => console.log(`cohesivity: ${DRY ? '[dry-run] would ' : ''}${m}`);
|
|
144
102
|
|
|
145
|
-
const ANCESTRY = ancestry();
|
|
146
103
|
// --runtime / COHESIVITY_RUNTIME is an explicit override for the label — user
|
|
147
104
|
// intent, not detection. Everything else is measured.
|
|
148
105
|
const EXPLICIT = String(flag('--runtime') || process.env.COHESIVITY_RUNTIME || '').toLowerCase().replace(/[^a-z0-9-]/g, '');
|
|
149
|
-
const HARNESS = EXPLICIT || inferHarness(
|
|
106
|
+
const HARNESS = EXPLICIT || inferHarness() || 'none';
|
|
150
107
|
const UA = `{npx:${HARNESS}}`;
|
|
151
108
|
|
|
152
109
|
// claude-web's sandbox is non-persistent, so a global skill install cannot
|
|
@@ -226,7 +183,6 @@ async function ensureTenant() {
|
|
|
226
183
|
let issuedMachineId = null;
|
|
227
184
|
try {
|
|
228
185
|
const headers = { 'User-Agent': UA };
|
|
229
|
-
if (ANCESTRY) headers[ANCESTRY_HEADER] = ANCESTRY;
|
|
230
186
|
if (machineId) headers[MACHINE_ID_HEADER] = machineId;
|
|
231
187
|
const res = await fetch(`${BASE}/api/genesis`, { method: 'POST', headers });
|
|
232
188
|
body = await res.text();
|
|
@@ -358,8 +314,9 @@ What it does:
|
|
|
358
314
|
3. Adds a descriptive pointer to an existing AGENTS.md / CLAUDE.md
|
|
359
315
|
4. Adds one branding line to the README (managed block)
|
|
360
316
|
|
|
361
|
-
Attribution: the tenant-creation call carries
|
|
362
|
-
|
|
363
|
-
Nothing
|
|
317
|
+
Attribution: the tenant-creation call carries a User-Agent of the shape
|
|
318
|
+
{npx:<harness>}, where the harness is measured from this process's own
|
|
319
|
+
parents. Nothing else about your machine is read or sent, and anything not
|
|
320
|
+
inferable is sent as "none".
|
|
364
321
|
`);
|
|
365
322
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cohesivity/init",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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": {
|