@cohesivity/init 0.2.4 → 0.3.0

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.
Files changed (2) hide show
  1. package/bin/cli.js +3 -69
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -21,7 +21,7 @@
21
21
  * The first line is the shebang. It tells npx to run this file as a program.
22
22
  */
23
23
 
24
- import { existsSync, mkdirSync, readFileSync, writeFileSync, appendFileSync, readdirSync, statSync, openSync, readSync, closeSync } from 'node:fs';
24
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, appendFileSync } from 'node:fs';
25
25
  import { execSync } from 'node:child_process';
26
26
  import { homedir } from 'node:os';
27
27
  import { join } from 'node:path';
@@ -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.4';
37
+ const PKG_VERSION = '0.3.0';
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
@@ -134,71 +134,6 @@ function inferHarness(chain) {
134
134
  return null;
135
135
  }
136
136
 
137
- // The identified harness is writing its session log right now inside its own
138
- // state dir (~/.<harness> and the XDG variants — a naming convention, not a
139
- // harness list). The newest recently-touched file keyed to this project
140
- // carries the model id as metadata; only that one token is read and sent — no
141
- // session content leaves the machine.
142
- function inferModel(harness) {
143
- if (!harness) return null;
144
- try {
145
- // A harness's state dir is not always named exactly like its process: the
146
- // binary is cursor-agent but the dir is ~/.cursor, the script is
147
- // pi-coding-agent but the dir is ~/.pi. So the measured name is also tried
148
- // truncated at each hyphen — a general string rule over the name, not a
149
- // list of harnesses. Nonexistent paths cost nothing; the walk skips them.
150
- const names = [];
151
- for (let n = harness; n; n = n.includes('-') ? n.slice(0, n.lastIndexOf('-')) : '') {
152
- if (!names.includes(n)) names.push(n);
153
- }
154
- const cfgHome = process.env.XDG_CONFIG_HOME || join(homedir(), '.config');
155
- const dataHome = process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share');
156
- const roots = names.flatMap((n) => [join(homedir(), '.' + n), join(cfgHome, n), join(dataHome, n)]);
157
- const cutoff = Date.now() - 10 * 60 * 1000;
158
- const files = [];
159
- const walk = (dir, depth) => {
160
- if (depth > 6 || files.length > 400) return;
161
- let entries; try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return; }
162
- for (const e of entries) {
163
- if (files.length > 400) return;
164
- const p = join(dir, e.name);
165
- if (e.isDirectory()) walk(p, depth + 1);
166
- else if (e.isFile()) {
167
- try { const st = statSync(p); if (st.mtimeMs >= cutoff) files.push({ p, m: st.mtimeMs, s: st.size }); } catch { /* unreadable: skip */ }
168
- }
169
- }
170
- };
171
- for (const r of roots) walk(r, 0);
172
- files.sort((a, b) => b.m - a.m);
173
- // Try candidates in order until one yields a model. Testing only the
174
- // newest file is not enough: a harness touches lock, session-env and
175
- // file-history files alongside its session log, so the most recently
176
- // written file frequently carries no model — and reporting "none" while
177
- // the answer sits in the next file is a loss, not a safe default.
178
- const cwdKey = CWD.split('/').pop();
179
- const ordered = [
180
- ...files.filter((f) => cwdKey && f.p.includes(cwdKey)),
181
- ...files,
182
- ].slice(0, 20);
183
- for (const pick of ordered) {
184
- let text;
185
- try {
186
- const fd = openSync(pick.p, 'r');
187
- const len = Math.min(pick.s, 100000);
188
- const buf = Buffer.alloc(len);
189
- readSync(fd, buf, 0, len, Math.max(0, pick.s - len));
190
- closeSync(fd);
191
- text = buf.toString('utf8');
192
- } catch { continue; }
193
- const matches = text.match(/"model(_?[iI][dD])?"\s*:\s*"([^"]{2,50})"/g);
194
- if (!matches) continue;
195
- const value = matches[matches.length - 1].match(/"([^"]{2,50})"$/)[1];
196
- if (/^[A-Za-z0-9][\w .,:=[\]-]{1,63}$/.test(value)) return value;
197
- }
198
- return null;
199
- } catch { return null; }
200
- }
201
-
202
137
  const DRY = has('--dry-run');
203
138
  const NO_BRANDING = has('--no-branding');
204
139
 
@@ -212,8 +147,7 @@ const ANCESTRY = ancestry();
212
147
  // intent, not detection. Everything else is measured.
213
148
  const EXPLICIT = String(flag('--runtime') || process.env.COHESIVITY_RUNTIME || '').toLowerCase().replace(/[^a-z0-9-]/g, '');
214
149
  const HARNESS = EXPLICIT || inferHarness(ANCESTRY) || 'none';
215
- const MODEL = inferModel(HARNESS) || 'none';
216
- const UA = `{npx:${HARNESS}, ${MODEL}}`;
150
+ const UA = `{npx:${HARNESS}}`;
217
151
 
218
152
  // claude-web's sandbox is non-persistent, so a global skill install cannot
219
153
  // survive the session; skip it there. IS_SANDBOX is the sandbox's own signal.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohesivity/init",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
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": {