@commonlyai/cli 0.1.317 → 0.1.318

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.317",
3
+ "version": "0.1.318",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  * restart can still suppress a re-delivered event whose ack previously failed.
22
22
  */
23
23
 
24
- import { readFileSync, writeFileSync, mkdirSync, existsSync, rmSync, renameSync } from 'fs';
24
+ import { readFileSync, writeFileSync, mkdirSync, existsSync, rmSync, renameSync, chmodSync } from 'fs';
25
25
  import { join } from 'path';
26
26
  import { homedir } from 'os';
27
27
 
@@ -32,6 +32,23 @@ const noticesFile = (agentName) => join(sessionsDir(), `${agentName}.notices.jso
32
32
  const MAX_HANDLED_EVENTS = 500;
33
33
  const handledEventsCache = new Map();
34
34
 
35
+ // Everything under ~/.commonly is private (D275). These files hold per-(agent,
36
+ // pod) session IDs and event rings; keep the dir and its files owner-only, and
37
+ // tighten an existing dir or file that a pre-0.1.309 CLI left group/world-
38
+ // readable. A mode arg applies only when the path is created, so each write
39
+ // chmods after — the same belt-and-braces config.js uses for the token file.
40
+ const ensureSessionsDir = () => {
41
+ const dir = sessionsDir();
42
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true, mode: 0o700 });
43
+ try { chmodSync(dir, 0o700); } catch { /* a dir we don't own: leave it */ }
44
+ return dir;
45
+ };
46
+
47
+ const writeSessionFile = (file, data) => {
48
+ writeFileSync(file, data, { encoding: 'utf8', mode: 0o600 });
49
+ try { chmodSync(file, 0o600); } catch { /* best effort to tighten an existing file */ }
50
+ };
51
+
35
52
  const readAgent = (agentName) => {
36
53
  const file = sessionsFile(agentName);
37
54
  if (!existsSync(file)) return {};
@@ -43,8 +60,8 @@ const readAgent = (agentName) => {
43
60
  };
44
61
 
45
62
  const writeAgent = (agentName, state) => {
46
- if (!existsSync(sessionsDir())) mkdirSync(sessionsDir(), { recursive: true });
47
- writeFileSync(sessionsFile(agentName), JSON.stringify(state, null, 2), 'utf8');
63
+ ensureSessionsDir();
64
+ writeSessionFile(sessionsFile(agentName), JSON.stringify(state, null, 2));
48
65
  };
49
66
 
50
67
  const readHandledEvents = (agentName) => {
@@ -79,8 +96,8 @@ const getHandledEvents = (agentName) => {
79
96
  };
80
97
 
81
98
  const writeHandledEvents = (agentName, ids) => {
82
- if (!existsSync(sessionsDir())) mkdirSync(sessionsDir(), { recursive: true });
83
- writeFileSync(handledEventsFile(agentName), JSON.stringify(ids, null, 2), 'utf8');
99
+ ensureSessionsDir();
100
+ writeSessionFile(handledEventsFile(agentName), JSON.stringify(ids, null, 2));
84
101
  };
85
102
 
86
103
  export const getSession = (agentName, podId, { binding = null } = {}) => {
@@ -173,7 +190,7 @@ export const recordNotice = (agentName, key, now = Date.now()) => {
173
190
  if (!agentName || !key) return;
174
191
  const state = readNotices(agentName);
175
192
  state[key] = new Date(now).toISOString();
176
- if (!existsSync(sessionsDir())) mkdirSync(sessionsDir(), { recursive: true });
193
+ ensureSessionsDir();
177
194
  // Temp file then rename, so a crash mid-write never leaves a torn file, and
178
195
  // 0600 because the record says which models this seat's key cannot use.
179
196
  const file = noticesFile(agentName);