@xenosystem/primitives 0.8.0 → 0.8.1

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.
@@ -20,6 +20,7 @@ const read_ts_1 = require("./read.js");
20
20
  const transcript_ts_1 = require("./transcript.js");
21
21
  const write_ts_1 = require("./write.js");
22
22
  const types_ts_1 = require("./types.js");
23
+ const owned_ts_1 = require("./owned.js");
23
24
  const asVendor = (v) => {
24
25
  if (!types_ts_1.VENDORS.includes(v))
25
26
  throw new Error(`Unknown agent: ${v}. Known: ${types_ts_1.VENDORS.join(', ')}.`);
@@ -91,36 +92,15 @@ async function convertSession(source, target, ctx) {
91
92
  }
92
93
  }
93
94
  /* ------------------------------------------------------------------ removal, of exactly what a conversion created */
94
- /** `path`, strictly inside `root`, with no link anywhere on its way. */
95
- function ownedPath(root, path) {
96
- const base = (0, node_path_1.resolve)(root), target = (0, node_path_1.resolve)(path), rel = (0, node_path_1.relative)(base, target);
97
- if (!rel || rel === '..' || rel.startsWith('..\\') || rel.startsWith('../') || (0, node_path_1.isAbsolute)(rel))
98
- throw new Error(`Path is not strictly inside its ownership root: ${target}`);
99
- for (let part = target;;) {
100
- try {
101
- if ((0, node_fs_1.lstatSync)(part).isSymbolicLink())
102
- throw new Error(`Refusing reparse point/symlink: ${part}`);
103
- }
104
- catch (e) {
105
- if (e.code !== 'ENOENT')
106
- throw e;
107
- }
108
- const parent = (0, node_path_1.dirname)(part);
109
- if (parent === part)
110
- break;
111
- part = parent;
112
- }
113
- return target;
114
- }
115
95
  /**
116
96
  * Remove a tree only after checking ALL of it: never a recursive rm, because an agent may have placed a junction even inside a private
117
97
  * staging folder. `allowed` limits a vendor folder to the files a writer creates.
118
98
  */
119
99
  function removeOwnedPath(root, path, allowed = null) {
120
- const target = ownedPath(root, path);
100
+ const target = (0, owned_ts_1.ownedPath)(root, path);
121
101
  const entries = [];
122
102
  const walk = (p) => {
123
- ownedPath(root, p);
103
+ (0, owned_ts_1.ownedPath)(root, p);
124
104
  let st;
125
105
  try {
126
106
  st = (0, node_fs_1.lstatSync)(p);
@@ -143,7 +123,7 @@ function removeOwnedPath(root, path, allowed = null) {
143
123
  };
144
124
  walk(target);
145
125
  for (const e of entries) {
146
- ownedPath(root, e.path);
126
+ (0, owned_ts_1.ownedPath)(root, e.path);
147
127
  const st = (0, node_fs_1.lstatSync)(e.path);
148
128
  if (st.dev !== e.dev || st.ino !== e.ino || st.isDirectory() !== e.dir)
149
129
  throw new Error(`Artifact changed during cleanup: ${e.path}`);
@@ -187,14 +167,14 @@ async function removeArtifacts(artifacts, ctx) {
187
167
  removeOwnedPath(workdir, a.path);
188
168
  continue;
189
169
  }
190
- const projects = (0, node_path_1.join)(ctx.stores.claude, 'projects');
191
- ownedPath(projects, a.path);
170
+ const projects = (0, owned_ts_1.claudeProjectsDir)(ctx.stores);
171
+ (0, owned_ts_1.ownedPath)(projects, a.path);
192
172
  if (!/^[0-9a-f-]{36}\.jsonl$/i.test((0, node_path_1.basename)(a.path)))
193
173
  throw new Error(`not a converted Claude session file: ${a.path}`);
194
174
  removeOwnedPath(projects, a.path);
195
175
  }
196
176
  else if (a.kind === 'dir') {
197
- const sessions = (0, node_path_1.join)(ctx.stores.xenoAgent, 'sessions'), path = ownedPath(sessions, a.path);
177
+ const sessions = (0, node_path_1.join)(ctx.stores.xenoAgent, 'sessions'), path = (0, owned_ts_1.ownedPath)(sessions, a.path);
198
178
  if ((0, node_path_1.dirname)(path) !== (0, node_path_1.resolve)(sessions) || !/^xeno-copy-\d{14}-[0-9a-f]{5}$/.test((0, node_path_1.basename)(path)))
199
179
  throw new Error(`not a converted XENO agent session: ${path}`);
200
180
  removeOwnedPath(sessions, path, ['meta.json', 'transcript.jsonl', 'session.lock', 'audit.jsonl', 'transcript.md']);
@@ -11,3 +11,4 @@ export { toTranscript, losses, type Transcript, type Message, type Report } from
11
11
  export { buildLayers, layersPrompt, RECENT_CAP, type Layer, type Layers } from './layers.ts';
12
12
  export { TARGETS, writeSession, handoffDocument, claudeLines, slugForCwd, transcriptDir, type Artifact, type Written, type WriteContext } from './write.ts';
13
13
  export { planConversion, convertSession, removeArtifacts, fingerprint, locateSession, type Plan, type Conversion, type SourceSpec } from './convert.ts';
14
+ export { ownedPath, claudeProjectsDir } from './owned.ts';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.locateSession = exports.fingerprint = exports.removeArtifacts = exports.convertSession = exports.planConversion = exports.transcriptDir = exports.slugForCwd = exports.claudeLines = exports.handoffDocument = exports.writeSession = exports.TARGETS = exports.RECENT_CAP = exports.layersPrompt = exports.buildLayers = exports.losses = exports.toTranscript = exports.OUTPUT_KEPT = exports.exportOpencodeSession = exports.safeSessionId = exports.resumeArgs = exports.readSubagents = exports.readSession = exports.newestSessionIn = exports.findAnySession = exports.findSession = exports.listSessions = exports.spawnAgent = exports.runAgent = exports.defaultStores = exports.VENDORS = void 0;
3
+ exports.claudeProjectsDir = exports.ownedPath = exports.locateSession = exports.fingerprint = exports.removeArtifacts = exports.convertSession = exports.planConversion = exports.transcriptDir = exports.slugForCwd = exports.claudeLines = exports.handoffDocument = exports.writeSession = exports.TARGETS = exports.RECENT_CAP = exports.layersPrompt = exports.buildLayers = exports.losses = exports.toTranscript = exports.OUTPUT_KEPT = exports.exportOpencodeSession = exports.safeSessionId = exports.resumeArgs = exports.readSubagents = exports.readSession = exports.newestSessionIn = exports.findAnySession = exports.findSession = exports.listSessions = exports.spawnAgent = exports.runAgent = exports.defaultStores = exports.VENDORS = void 0;
4
4
  /**
5
5
  * @xenosystem/primitives/sessions: one agent-neutral conversation format, with a reader and a writer for each agent (Claude Code,
6
6
  * Codex, agy, opencode, the XENO agent), so a session started in one can be continued in another. Back-end rung 1: no product logic.
@@ -44,3 +44,6 @@ Object.defineProperty(exports, "convertSession", { enumerable: true, get: functi
44
44
  Object.defineProperty(exports, "removeArtifacts", { enumerable: true, get: function () { return convert_ts_1.removeArtifacts; } });
45
45
  Object.defineProperty(exports, "fingerprint", { enumerable: true, get: function () { return convert_ts_1.fingerprint; } });
46
46
  Object.defineProperty(exports, "locateSession", { enumerable: true, get: function () { return convert_ts_1.locateSession; } });
47
+ var owned_ts_1 = require("./owned.js");
48
+ Object.defineProperty(exports, "ownedPath", { enumerable: true, get: function () { return owned_ts_1.ownedPath; } });
49
+ Object.defineProperty(exports, "claudeProjectsDir", { enumerable: true, get: function () { return owned_ts_1.claudeProjectsDir; } });
@@ -0,0 +1,5 @@
1
+ import type { Stores } from './types.ts';
2
+ /** `path`, strictly inside `root`, with no symlink or junction at any component up to the filesystem root. Throws otherwise. */
3
+ export declare function ownedPath(root: string, path: string): string;
4
+ /** Claude Code's project folders: `stores.claudeProjects` when a caller keeps them elsewhere, else `<claude>/projects`. */
5
+ export declare const claudeProjectsDir: (stores: Stores) => string;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.claudeProjectsDir = void 0;
4
+ exports.ownedPath = ownedPath;
5
+ /**
6
+ * Where a converter may write and delete: strictly inside an agent's own store, with no link anywhere on the way. Shared by the writers
7
+ * (write.ts) and the removal (convert.ts), so a path refused for deletion is refused for creation too.
8
+ *
9
+ * 🔴 A copy is never written THROUGH a junction or symlink (0.8.1, moved down from XENO Spawn's `ownedFiles.js`): a store reached
10
+ * through a link puts the copy somewhere the person did not choose, and its removal later deletes there too. A prefix check on the
11
+ * string cannot see a link; only walking the path with lstat can.
12
+ */
13
+ const node_fs_1 = require("node:fs");
14
+ const node_path_1 = require("node:path");
15
+ /** `path`, strictly inside `root`, with no symlink or junction at any component up to the filesystem root. Throws otherwise. */
16
+ function ownedPath(root, path) {
17
+ const base = (0, node_path_1.resolve)(root), target = (0, node_path_1.resolve)(path), rel = (0, node_path_1.relative)(base, target);
18
+ if (!rel || rel === '..' || rel.startsWith('..\\') || rel.startsWith('../') || (0, node_path_1.isAbsolute)(rel))
19
+ throw new Error(`Path is not strictly inside its ownership root: ${target}`);
20
+ for (let part = target;;) {
21
+ try {
22
+ if ((0, node_fs_1.lstatSync)(part).isSymbolicLink())
23
+ throw new Error(`Refusing reparse point/symlink: ${part}`);
24
+ }
25
+ catch (e) {
26
+ if (e.code !== 'ENOENT')
27
+ throw e;
28
+ }
29
+ const parent = (0, node_path_1.dirname)(part);
30
+ if (parent === part)
31
+ break;
32
+ part = parent;
33
+ }
34
+ return target;
35
+ }
36
+ /** Claude Code's project folders: `stores.claudeProjects` when a caller keeps them elsewhere, else `<claude>/projects`. */
37
+ const claudeProjectsDir = (stores) => stores.claudeProjects ?? (0, node_path_1.join)(stores.claude, 'projects');
38
+ exports.claudeProjectsDir = claudeProjectsDir;
@@ -24,6 +24,7 @@ const node_fs_1 = require("node:fs");
24
24
  const node_path_1 = require("node:path");
25
25
  const node_readline_1 = require("node:readline");
26
26
  const types_ts_1 = require("./types.js");
27
+ const owned_ts_1 = require("./owned.js");
27
28
  const TITLE_CAP = 160, LINE_CAP = 8 << 20;
28
29
  const SAFE_ID = /^[A-Za-z0-9._:-]{1,128}$/;
29
30
  /** A session id an agent's command can take as one word, or null. */
@@ -130,7 +131,7 @@ function claudeHeadIn(text) {
130
131
  const claude = {
131
132
  vendor: 'Claude Code',
132
133
  async list({ stores }) {
133
- const root = (0, node_path_1.join)(stores.claude, 'projects');
134
+ const root = (0, owned_ts_1.claudeProjectsDir)(stores);
134
135
  if (!(0, node_fs_1.existsSync)(root))
135
136
  return [];
136
137
  const out = [];
@@ -50,6 +50,11 @@ export interface Subagent {
50
50
  export interface Stores {
51
51
  /** Claude Code's configuration folder (its sessions are under `projects/`). */
52
52
  claude: string;
53
+ /**
54
+ * Claude Code's project folders, when a caller keeps them somewhere other than `<claude>/projects` (XENO Spawn's isolated test homes
55
+ * do). Optional; absent means `<claude>/projects`.
56
+ */
57
+ claudeProjects?: string;
53
58
  /** Codex's home (`sessions/`, `state_5.sqlite`). */
54
59
  codex: string;
55
60
  /** agy's (Antigravity CLI) data folder (`conversation_summaries.db`, `brain/`). */
@@ -29,6 +29,7 @@ const run_ts_1 = require("./run.js");
29
29
  const read_ts_1 = require("./read.js");
30
30
  const transcript_ts_1 = require("./transcript.js");
31
31
  const layers_ts_1 = require("./layers.js");
32
+ const owned_ts_1 = require("./owned.js");
32
33
  /** How each agent takes a copy, and whether it can resume it as its own conversation. */
33
34
  exports.TARGETS = Object.freeze({
34
35
  'Claude Code': { fidelity: 'native', via: "a new session file in Claude Code's own layout" },
@@ -152,6 +153,7 @@ async function writeSession(target, msgs, source, ctx) {
152
153
  const record = (a) => { artifacts.push(a); ctx.record?.(a); };
153
154
  if ((0, node_fs_1.existsSync)(ctx.workDir))
154
155
  throw new Error(`Refusing to reuse ${ctx.workDir}: a conversion's folder must be new.`);
156
+ (0, owned_ts_1.ownedPath)((0, node_path_1.dirname)(ctx.workDir), ctx.workDir);
155
157
  (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(ctx.workDir), { recursive: true });
156
158
  (0, node_fs_1.mkdirSync)(ctx.workDir);
157
159
  record({ kind: 'workdir', path: ctx.workDir });
@@ -165,7 +167,7 @@ async function writeSession(target, msgs, source, ctx) {
165
167
  writeNew(index, l.readme.text);
166
168
  }
167
169
  if (target === 'Claude Code') {
168
- const sid = (0, node_crypto_1.randomUUID)(), file = (0, node_path_1.join)(ctx.stores.claude, 'projects', (0, exports.slugForCwd)(cwd), `${sid}.jsonl`);
170
+ const projects = (0, owned_ts_1.claudeProjectsDir)(ctx.stores), sid = (0, node_crypto_1.randomUUID)(), file = (0, owned_ts_1.ownedPath)(projects, (0, node_path_1.join)(projects, (0, exports.slugForCwd)(cwd), `${sid}.jsonl`));
169
171
  writeNew(file, claudeLines(msgs, sid, cwd));
170
172
  record({ kind: 'file', path: file });
171
173
  return { id: sid, cwd, artifacts, resume: ['--resume', sid] };
@@ -207,7 +209,7 @@ async function writeSession(target, msgs, source, ctx) {
207
209
  }
208
210
  if (target === 'XENO agent') {
209
211
  const stamp = new Date().toISOString().replace(/\D/g, '').slice(0, 14);
210
- const sid = `xeno-copy-${stamp}-${(0, node_crypto_1.randomUUID)().slice(0, 5)}`, dir = (0, node_path_1.join)(ctx.stores.xenoAgent, 'sessions', sid);
212
+ const sessions = (0, node_path_1.join)(ctx.stores.xenoAgent, 'sessions'), sid = `xeno-copy-${stamp}-${(0, node_crypto_1.randomUUID)().slice(0, 5)}`, dir = (0, owned_ts_1.ownedPath)(sessions, (0, node_path_1.join)(sessions, sid));
211
213
  if ((0, node_fs_1.existsSync)(dir))
212
214
  throw new Error(`Refusing to overwrite ${dir}`);
213
215
  (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(dir), { recursive: true });
@@ -13,6 +13,7 @@ import { findAnySession, findSession, readSession, readSubagents, safeSessionId
13
13
  import { losses, toTranscript } from "./transcript.js";
14
14
  import { TARGETS, transcriptDir, writeSession } from "./write.js";
15
15
  import { VENDORS } from "./types.js";
16
+ import { claudeProjectsDir, ownedPath } from "./owned.js";
16
17
  const asVendor = (v) => {
17
18
  if (!VENDORS.includes(v))
18
19
  throw new Error(`Unknown agent: ${v}. Known: ${VENDORS.join(', ')}.`);
@@ -83,27 +84,6 @@ export async function convertSession(source, target, ctx) {
83
84
  }
84
85
  }
85
86
  /* ------------------------------------------------------------------ removal, of exactly what a conversion created */
86
- /** `path`, strictly inside `root`, with no link anywhere on its way. */
87
- function ownedPath(root, path) {
88
- const base = resolve(root), target = resolve(path), rel = relative(base, target);
89
- if (!rel || rel === '..' || rel.startsWith('..\\') || rel.startsWith('../') || isAbsolute(rel))
90
- throw new Error(`Path is not strictly inside its ownership root: ${target}`);
91
- for (let part = target;;) {
92
- try {
93
- if (lstatSync(part).isSymbolicLink())
94
- throw new Error(`Refusing reparse point/symlink: ${part}`);
95
- }
96
- catch (e) {
97
- if (e.code !== 'ENOENT')
98
- throw e;
99
- }
100
- const parent = dirname(part);
101
- if (parent === part)
102
- break;
103
- part = parent;
104
- }
105
- return target;
106
- }
107
87
  /**
108
88
  * Remove a tree only after checking ALL of it: never a recursive rm, because an agent may have placed a junction even inside a private
109
89
  * staging folder. `allowed` limits a vendor folder to the files a writer creates.
@@ -179,7 +159,7 @@ export async function removeArtifacts(artifacts, ctx) {
179
159
  removeOwnedPath(workdir, a.path);
180
160
  continue;
181
161
  }
182
- const projects = join(ctx.stores.claude, 'projects');
162
+ const projects = claudeProjectsDir(ctx.stores);
183
163
  ownedPath(projects, a.path);
184
164
  if (!/^[0-9a-f-]{36}\.jsonl$/i.test(basename(a.path)))
185
165
  throw new Error(`not a converted Claude session file: ${a.path}`);
@@ -11,3 +11,4 @@ export { toTranscript, losses, type Transcript, type Message, type Report } from
11
11
  export { buildLayers, layersPrompt, RECENT_CAP, type Layer, type Layers } from './layers.ts';
12
12
  export { TARGETS, writeSession, handoffDocument, claudeLines, slugForCwd, transcriptDir, type Artifact, type Written, type WriteContext } from './write.ts';
13
13
  export { planConversion, convertSession, removeArtifacts, fingerprint, locateSession, type Plan, type Conversion, type SourceSpec } from './convert.ts';
14
+ export { ownedPath, claudeProjectsDir } from './owned.ts';
@@ -11,3 +11,4 @@ export { toTranscript, losses } from "./transcript.js";
11
11
  export { buildLayers, layersPrompt, RECENT_CAP } from "./layers.js";
12
12
  export { TARGETS, writeSession, handoffDocument, claudeLines, slugForCwd, transcriptDir } from "./write.js";
13
13
  export { planConversion, convertSession, removeArtifacts, fingerprint, locateSession } from "./convert.js";
14
+ export { ownedPath, claudeProjectsDir } from "./owned.js";
@@ -0,0 +1,5 @@
1
+ import type { Stores } from './types.ts';
2
+ /** `path`, strictly inside `root`, with no symlink or junction at any component up to the filesystem root. Throws otherwise. */
3
+ export declare function ownedPath(root: string, path: string): string;
4
+ /** Claude Code's project folders: `stores.claudeProjects` when a caller keeps them elsewhere, else `<claude>/projects`. */
5
+ export declare const claudeProjectsDir: (stores: Stores) => string;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Where a converter may write and delete: strictly inside an agent's own store, with no link anywhere on the way. Shared by the writers
3
+ * (write.ts) and the removal (convert.ts), so a path refused for deletion is refused for creation too.
4
+ *
5
+ * 🔴 A copy is never written THROUGH a junction or symlink (0.8.1, moved down from XENO Spawn's `ownedFiles.js`): a store reached
6
+ * through a link puts the copy somewhere the person did not choose, and its removal later deletes there too. A prefix check on the
7
+ * string cannot see a link; only walking the path with lstat can.
8
+ */
9
+ import { lstatSync } from 'node:fs';
10
+ import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
11
+ /** `path`, strictly inside `root`, with no symlink or junction at any component up to the filesystem root. Throws otherwise. */
12
+ export function ownedPath(root, path) {
13
+ const base = resolve(root), target = resolve(path), rel = relative(base, target);
14
+ if (!rel || rel === '..' || rel.startsWith('..\\') || rel.startsWith('../') || isAbsolute(rel))
15
+ throw new Error(`Path is not strictly inside its ownership root: ${target}`);
16
+ for (let part = target;;) {
17
+ try {
18
+ if (lstatSync(part).isSymbolicLink())
19
+ throw new Error(`Refusing reparse point/symlink: ${part}`);
20
+ }
21
+ catch (e) {
22
+ if (e.code !== 'ENOENT')
23
+ throw e;
24
+ }
25
+ const parent = dirname(part);
26
+ if (parent === part)
27
+ break;
28
+ part = parent;
29
+ }
30
+ return target;
31
+ }
32
+ /** Claude Code's project folders: `stores.claudeProjects` when a caller keeps them elsewhere, else `<claude>/projects`. */
33
+ export const claudeProjectsDir = (stores) => stores.claudeProjects ?? join(stores.claude, 'projects');
@@ -12,6 +12,7 @@ import { closeSync, createReadStream, existsSync, lstatSync, openSync, readdirSy
12
12
  import { join } from 'node:path';
13
13
  import { createInterface } from 'node:readline';
14
14
  import { VENDORS } from "./types.js";
15
+ import { claudeProjectsDir } from "./owned.js";
15
16
  const TITLE_CAP = 160, LINE_CAP = 8 << 20;
16
17
  const SAFE_ID = /^[A-Za-z0-9._:-]{1,128}$/;
17
18
  /** A session id an agent's command can take as one word, or null. */
@@ -117,7 +118,7 @@ function claudeHeadIn(text) {
117
118
  const claude = {
118
119
  vendor: 'Claude Code',
119
120
  async list({ stores }) {
120
- const root = join(stores.claude, 'projects');
121
+ const root = claudeProjectsDir(stores);
121
122
  if (!existsSync(root))
122
123
  return [];
123
124
  const out = [];
@@ -50,6 +50,11 @@ export interface Subagent {
50
50
  export interface Stores {
51
51
  /** Claude Code's configuration folder (its sessions are under `projects/`). */
52
52
  claude: string;
53
+ /**
54
+ * Claude Code's project folders, when a caller keeps them somewhere other than `<claude>/projects` (XENO Spawn's isolated test homes
55
+ * do). Optional; absent means `<claude>/projects`.
56
+ */
57
+ claudeProjects?: string;
53
58
  /** Codex's home (`sessions/`, `state_5.sqlite`). */
54
59
  codex: string;
55
60
  /** agy's (Antigravity CLI) data folder (`conversation_summaries.db`, `brain/`). */
@@ -22,6 +22,7 @@ import { spawnAgent } from "./run.js";
22
22
  import { safeSessionId } from "./read.js";
23
23
  import { cap } from "./transcript.js";
24
24
  import { buildLayers, layersPrompt } from "./layers.js";
25
+ import { claudeProjectsDir, ownedPath } from "./owned.js";
25
26
  /** How each agent takes a copy, and whether it can resume it as its own conversation. */
26
27
  export const TARGETS = Object.freeze({
27
28
  'Claude Code': { fidelity: 'native', via: "a new session file in Claude Code's own layout" },
@@ -143,6 +144,7 @@ export async function writeSession(target, msgs, source, ctx) {
143
144
  const record = (a) => { artifacts.push(a); ctx.record?.(a); };
144
145
  if (existsSync(ctx.workDir))
145
146
  throw new Error(`Refusing to reuse ${ctx.workDir}: a conversion's folder must be new.`);
147
+ ownedPath(dirname(ctx.workDir), ctx.workDir);
146
148
  mkdirSync(dirname(ctx.workDir), { recursive: true });
147
149
  mkdirSync(ctx.workDir);
148
150
  record({ kind: 'workdir', path: ctx.workDir });
@@ -156,7 +158,7 @@ export async function writeSession(target, msgs, source, ctx) {
156
158
  writeNew(index, l.readme.text);
157
159
  }
158
160
  if (target === 'Claude Code') {
159
- const sid = randomUUID(), file = join(ctx.stores.claude, 'projects', slugForCwd(cwd), `${sid}.jsonl`);
161
+ const projects = claudeProjectsDir(ctx.stores), sid = randomUUID(), file = ownedPath(projects, join(projects, slugForCwd(cwd), `${sid}.jsonl`));
160
162
  writeNew(file, claudeLines(msgs, sid, cwd));
161
163
  record({ kind: 'file', path: file });
162
164
  return { id: sid, cwd, artifacts, resume: ['--resume', sid] };
@@ -198,7 +200,7 @@ export async function writeSession(target, msgs, source, ctx) {
198
200
  }
199
201
  if (target === 'XENO agent') {
200
202
  const stamp = new Date().toISOString().replace(/\D/g, '').slice(0, 14);
201
- const sid = `xeno-copy-${stamp}-${randomUUID().slice(0, 5)}`, dir = join(ctx.stores.xenoAgent, 'sessions', sid);
203
+ const sessions = join(ctx.stores.xenoAgent, 'sessions'), sid = `xeno-copy-${stamp}-${randomUUID().slice(0, 5)}`, dir = ownedPath(sessions, join(sessions, sid));
202
204
  if (existsSync(dir))
203
205
  throw new Error(`Refusing to overwrite ${dir}`);
204
206
  mkdirSync(dirname(dir), { recursive: true });
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xenosystem/primitives",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "XENO back-end rung 1 primitives: dirs (the XENO local home), secrets (envelope-encrypted credentials), updates (the gated app updater), live (the client for XENO Multiplayer) process (start a command so that stopping it stops everything it started), private-file (owner-only files, published atomically, without a helper process) and sessions (one conversation format with a reader and a writer for each agent, so a session moves between Claude Code, Codex, agy, opencode and the XENO agent).",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",