@commonlyai/cli 0.1.308 → 0.1.309

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.308",
3
+ "version": "0.1.309",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -18,7 +18,7 @@ import { createRuntimeReporter } from '../lib/runtime-observation.js';
18
18
  */
19
19
 
20
20
  import { refreshMcpTokenCopy, removeMcpTokenCopy } from '../lib/mcp-token.js';
21
- import { readFileSync, writeFileSync, mkdirSync, existsSync, rmSync, readdirSync } from 'fs';
21
+ import { readFileSync, writeFileSync, mkdirSync, existsSync, rmSync, readdirSync, chmodSync } from 'fs';
22
22
  import { join, dirname, basename, resolve as pathResolve } from 'path';
23
23
  import { homedir, tmpdir } from 'os';
24
24
  import { fileURLToPath } from 'url';
@@ -169,14 +169,16 @@ const tokensDir = () => join(homedir(), '.commonly', 'tokens');
169
169
  const tokenFile = (name) => join(tokensDir(), `${name}.json`);
170
170
 
171
171
  export const saveAgentToken = (name, record) => {
172
- if (!existsSync(tokensDir())) mkdirSync(tokensDir(), { recursive: true });
173
- // mode applies on create only — the record carries a live cm_agent_* secret,
174
- // same handling as performInit's .commonly-env.
172
+ if (!existsSync(tokensDir())) mkdirSync(tokensDir(), { recursive: true, mode: 0o700 });
173
+ // The record carries a live cm_agent_* secret. The mode applies on create
174
+ // only and is subject to the umask, so chmod every time: that also tightens
175
+ // a record an older CLI left 0644.
175
176
  writeFileSync(
176
177
  tokenFile(name),
177
178
  JSON.stringify({ ...record, savedAt: new Date().toISOString() }, null, 2),
178
179
  { encoding: 'utf8', mode: 0o600 },
179
180
  );
181
+ chmodSync(tokenFile(name), 0o600);
180
182
  // After the record is durable, so a failed refresh never loses a freshly minted token.
181
183
  try {
182
184
  refreshMcpTokenCopy(name, record?.runtimeToken);
package/src/lib/config.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * Multiple instances supported (default, local, custom).
6
6
  */
7
7
 
8
- import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'fs';
8
+ import { readFileSync, writeFileSync, mkdirSync, existsSync, chmodSync } from 'fs';
9
9
  import { join } from 'path';
10
10
  import { homedir } from 'os';
11
11
 
@@ -24,9 +24,14 @@ const read = () => {
24
24
  }
25
25
  };
26
26
 
27
+ // The file holds the login's bearer token, so only its owner may read it. The
28
+ // mode on create is subject to the umask, and a file written before this fix is
29
+ // still 0644, so every write ends with chmod. A new directory is made 0700; an
30
+ // existing one is left as it is, because other tools keep files there too.
27
31
  const write = (config) => {
28
- if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true });
29
- writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf8');
32
+ if (!existsSync(CONFIG_DIR)) mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
33
+ writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { encoding: 'utf8', mode: 0o600 });
34
+ chmodSync(CONFIG_FILE, 0o600);
30
35
  };
31
36
 
32
37
  export const getConfig = () => read();