@cohesivity/init 0.3.1 → 0.3.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 +17 -5
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -34,14 +34,16 @@ 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.1';
37
+ const PKG_VERSION = '0.3.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
41
41
  // .cohesivity is per project, so a machine that runs setup in several projects
42
42
  // owns several tenants; this is what tells the server they came from one setup
43
43
  // rather than several unrelated people. Sent on genesis; the server issues one
44
- // only when we send none, so it is written exactly once and reused thereafter.
44
+ // whenever it cannot verify what we sent — none at all, or an id gone stale
45
+ // because the signing secret rotated or the file was corrupted — and whatever
46
+ // it issues replaces what is on disk. Steady state is written once and reused.
45
47
  const MACHINE_ID_HEADER = 'X-Cohesivity-Machine-Id';
46
48
  const MACHINE_ID_DIR = join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'cohesivity');
47
49
  const MACHINE_ID_FILE = join(MACHINE_ID_DIR, 'machine-id');
@@ -67,6 +69,10 @@ function inferHarness() {
67
69
  let argv, ppid;
68
70
  try {
69
71
  argv = readFileSync(`/proc/${pid}/cmdline`, 'utf8').split('\0').filter(Boolean);
72
+ // A process that rewrites its title (npm does) has no NUL separators
73
+ // left, so the whole command arrives as one element. Re-split it, or
74
+ // argv[0] is an entire command line rather than a program name.
75
+ if (argv.length === 1 && argv[0].includes(' ')) argv = argv[0].split(/\s+/);
70
76
  ppid = Number(readFileSync(`/proc/${pid}/stat`, 'utf8').split(') ').pop().split(' ')[1]);
71
77
  } catch {
72
78
  try {
@@ -182,8 +188,10 @@ async function ensureTenant() {
182
188
  if (machineId) headers[MACHINE_ID_HEADER] = machineId;
183
189
  const res = await fetch(`${BASE}/api/genesis`, { method: 'POST', headers });
184
190
  body = await res.text();
185
- // Only ever returned on the request that minted it, so this is non-null
186
- // exactly when we sent none.
191
+ // Returned on any request that MINTED an id, which is when we sent none
192
+ // *or* when the id we sent no longer verifies (secret rotated, file
193
+ // corrupted). It is not "non-null exactly when we sent none" — assuming
194
+ // that is what left a machine pinned to a dead id forever.
187
195
  issuedMachineId = res.headers.get(MACHINE_ID_HEADER);
188
196
  } catch (e) {
189
197
  log(`no tenant created (network: ${e.message}). Re-run to retry. The command is idempotent.`);
@@ -195,7 +203,11 @@ async function ensureTenant() {
195
203
  }
196
204
  writeFileSync(dotfile, body);
197
205
  ensureGitignore();
198
- if (!machineId && issuedMachineId) writeMachineId(issuedMachineId);
206
+ // Store whatever the server issued. Its presence already means "we minted
207
+ // this for you", so gating on `!machineId` as well dropped every replacement
208
+ // a machine with a stale id was handed: it re-minted on every genesis, kept
209
+ // none of them, and each project became its own machine row.
210
+ if (issuedMachineId) writeMachineId(issuedMachineId);
199
211
  log('created an ephemeral tenant -> ./.cohesivity');
200
212
  }
201
213
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohesivity/init",
3
- "version": "0.3.1",
3
+ "version": "0.3.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": {