@cohesivity/init 0.2.3 → 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 -62
  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.3';
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,64 +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
- const roots = [
146
- join(homedir(), '.' + harness),
147
- join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), harness),
148
- join(process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share'), harness),
149
- ];
150
- const cutoff = Date.now() - 10 * 60 * 1000;
151
- const files = [];
152
- const walk = (dir, depth) => {
153
- if (depth > 6 || files.length > 400) return;
154
- let entries; try { entries = readdirSync(dir, { withFileTypes: true }); } catch { return; }
155
- for (const e of entries) {
156
- if (files.length > 400) return;
157
- const p = join(dir, e.name);
158
- if (e.isDirectory()) walk(p, depth + 1);
159
- else if (e.isFile()) {
160
- try { const st = statSync(p); if (st.mtimeMs >= cutoff) files.push({ p, m: st.mtimeMs, s: st.size }); } catch { /* unreadable: skip */ }
161
- }
162
- }
163
- };
164
- for (const r of roots) walk(r, 0);
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.
171
- const cwdKey = CWD.split('/').pop();
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;
192
- } catch { return null; }
193
- }
194
-
195
137
  const DRY = has('--dry-run');
196
138
  const NO_BRANDING = has('--no-branding');
197
139
 
@@ -205,8 +147,7 @@ const ANCESTRY = ancestry();
205
147
  // intent, not detection. Everything else is measured.
206
148
  const EXPLICIT = String(flag('--runtime') || process.env.COHESIVITY_RUNTIME || '').toLowerCase().replace(/[^a-z0-9-]/g, '');
207
149
  const HARNESS = EXPLICIT || inferHarness(ANCESTRY) || 'none';
208
- const MODEL = inferModel(HARNESS) || 'none';
209
- const UA = `{npx:${HARNESS}, ${MODEL}}`;
150
+ const UA = `{npx:${HARNESS}}`;
210
151
 
211
152
  // claude-web's sandbox is non-persistent, so a global skill install cannot
212
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.3",
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": {