@cohesivity/init 0.2.2 → 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.
Files changed (2) hide show
  1. package/bin/cli.js +26 -12
  2. 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.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
@@ -163,18 +163,32 @@ function inferModel(harness) {
163
163
  };
164
164
  for (const r of roots) walk(r, 0);
165
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.
166
171
  const cwdKey = CWD.split('/').pop();
167
- const pick = files.find((f) => cwdKey && f.p.includes(cwdKey)) || files[0];
168
- if (!pick) return null;
169
- const fd = openSync(pick.p, 'r');
170
- const len = Math.min(pick.s, 100000);
171
- const buf = Buffer.alloc(len);
172
- readSync(fd, buf, 0, len, Math.max(0, pick.s - len));
173
- closeSync(fd);
174
- const matches = buf.toString('utf8').match(/"model(_?[iI][dD])?"\s*:\s*"([^"]{2,50})"/g);
175
- if (!matches) return null;
176
- const value = matches[matches.length - 1].match(/"([^"]{2,50})"$/)[1];
177
- return /^[A-Za-z0-9][\w .,:=[\]-]{1,63}$/.test(value) ? value : null;
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;
178
192
  } catch { return null; }
179
193
  }
180
194
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohesivity/init",
3
- "version": "0.2.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": {