@cohesivity/init 0.1.1 → 0.1.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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +41 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -9,7 +9,7 @@ npx @cohesivity/init
9
9
  The command runs once and does four things:
10
10
 
11
11
  1. **Installs the Cohesivity agent skill** into the detected agent's skill dir (Claude Code, Cursor, Codex, or the cross-tool `~/.agents`). The skill comes from a public, version-pinned commit, so you can audit the exact bytes.
12
- 2. **Creates or reuses a project tenant** and writes the credentials to `.cohesivity`, which it adds to `.gitignore`.
12
+ 2. **Creates or reuses a project tenant** and writes the credentials to `.cohesivity`, which it adds to `.gitignore`. Creating a tenant also stores an opaque random setup id at `~/.config/cohesivity/machine-id` and sends it with that request, so tenants created from one machine can be grouped rather than looking like unrelated people. It is issued by the server, is not derived from your hardware or user, and carries nothing about you or your project. Delete the file to end the association.
13
13
  3. **Adds a descriptive pointer** to an existing `AGENTS.md` or `CLAUDE.md`. It only touches a file that is already there. It creates nothing on its own.
14
14
  4. **Adds one branding line** to the README. Pass `--no-branding` to skip.
15
15
 
package/bin/cli.js CHANGED
@@ -32,9 +32,18 @@ const flag = (f) => { const i = argv.indexOf(f); return i >= 0 ? argv[i + 1] : u
32
32
  if (has('--help') || has('-h')) { help(); process.exit(0); }
33
33
 
34
34
  // ── config ──────────────────────────────────────────────────────────────────
35
- const PKG_VERSION = '0.1.1';
35
+ const PKG_VERSION = '0.1.2';
36
36
  const BASE = (flag('--base') || process.env.COHESIVITY_BASE || 'https://cohesivity.ai').replace(/\/+$/, '');
37
37
 
38
+ // Machine id: one per machine, stored outside any project. A project's
39
+ // .cohesivity is per project, so a machine that runs setup in several projects
40
+ // owns several tenants; this is what tells the server they came from one setup
41
+ // rather than several unrelated people. Sent on genesis; the server issues one
42
+ // only when we send none, so it is written exactly once and reused thereafter.
43
+ const MACHINE_ID_HEADER = 'X-Cohesivity-Machine-Id';
44
+ const MACHINE_ID_DIR = join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'cohesivity');
45
+ const MACHINE_ID_FILE = join(MACHINE_ID_DIR, 'machine-id');
46
+
38
47
  // The skill is pinned to an immutable commit in the public, auditable repo.
39
48
  // Bumping the pin is a deliberate release step. See COH-172.
40
49
  const SKILL_PIN = 'a3a461e964ec9f6c03ad49caeff2d984ca13b61f';
@@ -156,10 +165,17 @@ async function ensureTenant() {
156
165
  return;
157
166
  }
158
167
  if (DRY) { act(`create a tenant: POST ${BASE}/api/genesis -> ./.cohesivity (+ .gitignore)`); return; }
168
+ const machineId = readMachineId();
159
169
  let body;
170
+ let issuedMachineId = null;
160
171
  try {
161
- const res = await fetch(`${BASE}/api/genesis`, { method: 'POST', headers: { 'User-Agent': UA } });
172
+ const headers = { 'User-Agent': UA };
173
+ if (machineId) headers[MACHINE_ID_HEADER] = machineId;
174
+ const res = await fetch(`${BASE}/api/genesis`, { method: 'POST', headers });
162
175
  body = await res.text();
176
+ // Only ever returned on the request that minted it, so this is non-null
177
+ // exactly when we sent none.
178
+ issuedMachineId = res.headers.get(MACHINE_ID_HEADER);
163
179
  } catch (e) {
164
180
  log(`no tenant created (network: ${e.message}). Re-run to retry. The command is idempotent.`);
165
181
  return;
@@ -170,9 +186,32 @@ async function ensureTenant() {
170
186
  }
171
187
  writeFileSync(dotfile, body);
172
188
  ensureGitignore();
189
+ if (!machineId && issuedMachineId) writeMachineId(issuedMachineId);
173
190
  log('created an ephemeral tenant -> ./.cohesivity');
174
191
  }
175
192
 
193
+ // Read the machine id, or null when this machine has none. Every failure —
194
+ // missing file, unreadable dir, garbage contents — reads as "none", which just
195
+ // means the next genesis call is issued a fresh id.
196
+ function readMachineId() {
197
+ try {
198
+ const raw = readFileSync(MACHINE_ID_FILE, 'utf8').trim();
199
+ return /^mach_[a-z0-9]+\.[A-Za-z0-9_-]+$/.test(raw) ? raw : null;
200
+ } catch (_) {
201
+ return null;
202
+ }
203
+ }
204
+
205
+ // Persist a newly issued id. Best-effort by design: a read-only or unwritable
206
+ // config dir must not fail setup — the tenant already exists by this point, and
207
+ // the only cost of not writing is that the next project is issued another id.
208
+ function writeMachineId(value) {
209
+ try {
210
+ mkdirSync(MACHINE_ID_DIR, { recursive: true });
211
+ writeFileSync(MACHINE_ID_FILE, `${value}\n`);
212
+ } catch (_) { /* not worth failing or mentioning */ }
213
+ }
214
+
176
215
  function ensureGitignore() {
177
216
  const gi = join(CWD, '.gitignore');
178
217
  const line = '.cohesivity';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohesivity/init",
3
- "version": "0.1.1",
3
+ "version": "0.1.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": {