agentpen-cli 0.1.1 → 0.1.4

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/cli/handoff.js CHANGED
@@ -5,7 +5,12 @@ import fs from 'node:fs';
5
5
  import os from 'node:os';
6
6
  import path from 'node:path';
7
7
  import zlib from 'node:zlib';
8
- import { execFileSync } from 'node:child_process';
8
+ import { execFile, execFileSync } from 'node:child_process';
9
+ import { promisify } from 'node:util';
10
+ import { collectSecrets } from './redact.js';
11
+
12
+ const execFileAsync = promisify(execFile);
13
+ const gzipAsync = promisify(zlib.gzip);
9
14
 
10
15
  const INTERVAL_MS = Number(process.env.AGENTPEN_CHECKPOINT_MS) || 20_000;
11
16
  const MAX_BUNDLE = 100 * 1024 * 1024;
@@ -23,6 +28,12 @@ function git(args, { cwd, env, input } = {}) {
23
28
  }
24
29
  const tryGit = (args, opts) => { try { return git(args, opts); } catch { return ''; } };
25
30
 
31
+ async function gitAsync(args, { cwd, env } = {}) {
32
+ const { stdout } = await execFileAsync('git', args, { cwd, env: { ...process.env, ...env }, maxBuffer: 64 * 1024 * 1024 });
33
+ return stdout.trim();
34
+ }
35
+ const tryGitAsync = async (args, opts) => { try { return await gitAsync(args, opts); } catch { return ''; } };
36
+
26
37
  // A link to the repository that is safe to store: no embedded credentials.
27
38
  const cleanRepo = (url) => url.replace(/^(\w+:\/\/)[^@/]*@/, '$1');
28
39
  // Two clones of one repository rarely spell its address the same way.
@@ -31,35 +42,37 @@ export const repoKey = (url) => cleanRepo(url || '').toLowerCase().replace(/^\w+
31
42
  // Snapshot the working tree as a commit nobody sees: built on a scratch index,
32
43
  // so the host's own index, branch and stash are untouched. Ignored files
33
44
  // (.env, node_modules) stay out, exactly as they would stay out of a commit.
34
- function snapshot(top) {
35
- const head = tryGit(['rev-parse', 'HEAD'], { cwd: top });
45
+ async function snapshot(top) {
46
+ const head = await tryGitAsync(['rev-parse', 'HEAD'], { cwd: top });
36
47
  if (!head) return null;
37
- const index = path.join(os.tmpdir(), `agentpen-index-${process.pid}`);
48
+ const index = path.join(os.tmpdir(), `agentpen-index-${process.pid}-${Date.now()}`);
38
49
  try {
39
- const real = path.resolve(top, tryGit(['rev-parse', '--git-path', 'index'], { cwd: top }));
40
- if (fs.existsSync(real)) fs.copyFileSync(real, index); // keeps git's stat cache, so unchanged files are not re-read
50
+ const real = path.resolve(top, await tryGitAsync(['rev-parse', '--git-path', 'index'], { cwd: top }));
51
+ if (fs.existsSync(real)) await fs.promises.copyFile(real, index); // keeps git's stat cache, so unchanged files are not re-read
41
52
  const env = { GIT_INDEX_FILE: index };
42
- git(['add', '-A'], { cwd: top, env });
43
- const tree = git(['write-tree'], { cwd: top, env });
44
- if (tree === git(['rev-parse', 'HEAD^{tree}'], { cwd: top })) return { head, checkpoint: head, tree, changed: 0 };
45
- return { head, tree, changed: git(['diff', '--name-only', head, tree], { cwd: top }).split('\n').filter(Boolean).length };
53
+ await gitAsync(['add', '-A'], { cwd: top, env });
54
+ const tree = await gitAsync(['write-tree'], { cwd: top, env });
55
+ if (tree === await gitAsync(['rev-parse', 'HEAD^{tree}'], { cwd: top })) return { head, checkpoint: head, tree, changed: 0 };
56
+ const diff = await gitAsync(['diff', '--name-only', head, tree], { cwd: top });
57
+ return { head, tree, changed: diff.split('\n').filter(Boolean).length };
46
58
  } catch { return null; } finally { fs.rmSync(index, { force: true }); }
47
59
  }
48
60
 
49
- function commitSnapshot(top, snap) {
61
+ async function commitSnapshot(top, snap) {
50
62
  if (snap.checkpoint) return snap.checkpoint;
51
63
  const who = { GIT_AUTHOR_NAME: 'Agentpen', GIT_AUTHOR_EMAIL: 'checkpoint@agentpen.invalid', GIT_COMMITTER_NAME: 'Agentpen', GIT_COMMITTER_EMAIL: 'checkpoint@agentpen.invalid' };
52
- return git(['commit-tree', snap.tree, '-p', snap.head, '-m', 'Agentpen checkpoint (uncommitted work)'], { cwd: top, env: who });
64
+ return gitAsync(['commit-tree', snap.tree, '-p', snap.head, '-m', 'Agentpen checkpoint (uncommitted work)'], { cwd: top, env: who });
53
65
  }
54
66
 
55
67
  // Everything the team's remote does not already have: unpushed commits plus the snapshot.
56
- function bundle(top, commit) {
57
- const file = path.join(os.tmpdir(), `agentpen-${process.pid}.bundle`);
68
+ async function bundle(top, commit) {
69
+ const file = path.join(os.tmpdir(), `agentpen-${process.pid}-${Date.now()}.bundle`);
58
70
  try {
59
- git(['update-ref', 'refs/agentpen/checkpoint', commit], { cwd: top });
60
- git(['bundle', 'create', file, 'refs/agentpen/checkpoint', '--not', '--remotes'], { cwd: top });
71
+ await gitAsync(['update-ref', 'refs/agentpen/checkpoint', commit], { cwd: top });
72
+ await gitAsync(['bundle', 'create', file, 'refs/agentpen/checkpoint', '--not', '--remotes'], { cwd: top });
61
73
  return file;
62
74
  } catch { fs.rmSync(file, { force: true }); return null; } // git refuses an empty bundle: nothing unpushed
75
+ finally { await tryGitAsync(['update-ref', '-d', 'refs/agentpen/checkpoint'], { cwd: top }); }
63
76
  }
64
77
 
65
78
  function newestTranscript(dir, since) {
@@ -74,18 +87,17 @@ function newestTranscript(dir, since) {
74
87
  return best?.id || null;
75
88
  }
76
89
 
77
- export function startCheckpoints({ cfg, getSession, cwd, agentSession, secrets, onError }) {
90
+ export function startCheckpoints({ cfg, getSession, cwd, agentSession, secrets, shareSecrets = false, onError }) {
78
91
  const started = Date.now() - 2000;
79
92
  const dir = claudeProjectDir(cwd);
80
93
  const top = tryGit(['rev-parse', '--show-toplevel'], { cwd });
81
94
  const repo = top ? cleanRepo(tryGit(['remote', 'get-url', 'origin'], { cwd: top })) : '';
82
- const needles = [...secrets].sort((a, b) => b.length - a.length);
83
95
  let last = '';
84
96
  let busy = false;
85
97
  let warned = false;
86
98
 
87
99
  const put = async (sid, part, body) => {
88
- const r = await fetch(`${cfg.server}/api/sessions/${sid}/handoff/${part}`, { method: 'PUT', headers: { authorization: `Bearer ${cfg.token}`, 'content-type': 'application/octet-stream' }, body });
100
+ const r = await fetch(`${cfg.server}/api/sessions/${sid}/handoff/${part}`, { method: 'PUT', headers: { authorization: `Bearer ${cfg.token}`, 'content-type': 'application/octet-stream' }, body, signal: AbortSignal.timeout(60_000) });
89
101
  if (!r.ok) throw new Error((await r.json().catch(() => ({}))).error || `HTTP ${r.status}`);
90
102
  };
91
103
 
@@ -97,32 +109,35 @@ export function startCheckpoints({ cfg, getSession, cwd, agentSession, secrets,
97
109
  const id = agentSession || newestTranscript(dir, started);
98
110
  const file = id && path.join(dir, `${id}.jsonl`);
99
111
  if (!file || !fs.existsSync(file)) return; // the agent has not written anything yet
100
- const st = fs.statSync(file);
101
- const snap = top ? snapshot(top) : null;
112
+ const st = await fs.promises.stat(file);
113
+ const snap = top ? await snapshot(top) : null;
102
114
  const sig = [s.id, id, st.size, st.mtimeMs, snap?.head, snap?.tree].join(':');
103
115
  if (sig === last) return;
104
116
 
105
117
  if (st.size > MAX_TRANSCRIPT * 8) throw new Error('the conversation is too large to checkpoint');
106
- let text = fs.readFileSync(file, 'utf8');
118
+ let text = await fs.promises.readFile(file, 'utf8');
119
+ const needles = shareSecrets ? [] : [...new Set([...(secrets || []), ...collectSecrets(cwd, top)])].sort((a, b) => b.length - a.length);
107
120
  for (const v of needles) text = text.split(v).join('••••••'); // same .env masking as the live stream
108
- await put(s.id, 'transcript', zlib.gzipSync(text));
121
+ await put(s.id, 'transcript', await gzipAsync(text));
109
122
 
110
123
  let checkpoint = '';
111
124
  let hasBundle = false;
112
125
  if (snap) {
113
- checkpoint = commitSnapshot(top, snap);
114
- const b = bundle(top, checkpoint);
126
+ checkpoint = await commitSnapshot(top, snap);
127
+ const b = await bundle(top, checkpoint);
115
128
  if (b) {
116
129
  try {
117
- if (fs.statSync(b).size > MAX_BUNDLE) throw new Error('unpushed work is over 100 MB; only the conversation was checkpointed');
118
- await put(s.id, 'bundle', fs.readFileSync(b));
130
+ if ((await fs.promises.stat(b)).size > MAX_BUNDLE) throw new Error('unpushed work is over 100 MB; only the conversation was checkpointed');
131
+ await put(s.id, 'bundle', await fs.promises.readFile(b));
119
132
  hasBundle = true;
120
133
  } finally { fs.rmSync(b, { force: true }); }
121
134
  }
122
135
  }
136
+ const branch = top ? await tryGitAsync(['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: top }) : '';
123
137
  const r = await fetch(`${cfg.server}/api/sessions/${s.id}/handoff`, {
124
138
  method: 'POST', headers: { authorization: `Bearer ${cfg.token}`, 'content-type': 'application/json' },
125
- body: JSON.stringify({ agentSession: id, cwd, subdir: top ? path.relative(top, cwd) : '', repo, branch: top ? tryGit(['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: top }) : '', head: snap?.head, checkpoint, changed: snap?.changed || 0, hasBundle }),
139
+ body: JSON.stringify({ agentSession: id, cwd, subdir: top ? path.relative(top, cwd) : '', repo, branch, head: snap?.head, checkpoint, changed: snap?.changed || 0, hasBundle }),
140
+ signal: AbortSignal.timeout(30_000),
126
141
  });
127
142
  if (!r.ok) throw new Error((await r.json().catch(() => ({}))).error || `HTTP ${r.status}`);
128
143
  last = sig;
@@ -185,6 +200,7 @@ export async function pickup(cfg, ref, opts, ui) {
185
200
  } catch { ui.die(`could not create branch ${branch}. It may exist already from an earlier pickup.`); }
186
201
  // their uncommitted work comes back as uncommitted work, not as a commit
187
202
  if (meta.checkpoint !== meta.head) git(['restore', `--source=${meta.checkpoint}`, '--worktree', '--', '.'], { cwd: root });
203
+ if (meta.hasBundle) tryGit(['update-ref', '-d', `refs/agentpen/pickup-${sid}`], { cwd: top });
188
204
  cwd = meta.subdir && fs.existsSync(path.join(root, meta.subdir)) ? path.join(root, meta.subdir) : root;
189
205
  }
190
206
 
package/cli/install.js CHANGED
@@ -1,10 +1,12 @@
1
1
  // `agentpen install`: after this, nobody has to remember a prefix.
2
2
  // - A small shell hook makes plain `claude` go through Agentpen.
3
- // - On macOS a background helper shares Codex app conversations while they are active.
3
+ // - On macOS a background helper shares Codex app conversations while they are active,
4
+ // and the menu bar app is installed into Applications when a release is available.
4
5
  import fs from 'node:fs';
5
6
  import os from 'node:os';
6
7
  import path from 'node:path';
7
- import { execFileSync } from 'node:child_process';
8
+ import { createHash } from 'node:crypto';
9
+ import { execFileSync, spawn } from 'node:child_process';
8
10
  import { fileURLToPath } from 'node:url';
9
11
 
10
12
  const START = '# >>> agentpen >>>';
@@ -28,7 +30,9 @@ const plistPath = () => path.join(os.homedir(), 'Library', 'LaunchAgents', `${LA
28
30
  const rcFiles = () => {
29
31
  const home = os.homedir();
30
32
  const files = [path.join(home, '.zshrc'), path.join(home, '.bashrc')].filter((f) => fs.existsSync(f));
31
- // zsh is the default shell on a Mac; make its file if this machine has neither
33
+ const bashProfile = path.join(home, '.bash_profile');
34
+ if (!files.includes(path.join(home, '.bashrc')) && fs.existsSync(bashProfile)) files.push(bashProfile);
35
+ // zsh is the default shell on a Mac; make its file if this machine has none
32
36
  return files.length ? files : [path.join(home, '.zshrc')];
33
37
  };
34
38
 
@@ -49,7 +53,15 @@ const xml = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g,
49
53
  function launchAgent() {
50
54
  const cli = path.join(path.dirname(fileURLToPath(import.meta.url)), 'agentpen.js');
51
55
  const log = path.join(process.env.AGENTPEN_HOME || path.join(os.homedir(), '.agentpen'), 'watch.log');
52
- const args = [process.execPath, cli, 'watch'].map((a) => ` <string>${xml(a)}</string>`).join('\n');
56
+ const envPath = [...new Set([path.dirname(process.execPath), ...(process.env.PATH || '/usr/bin:/bin').split(':')])].filter(Boolean).join(':');
57
+ // Prefer `agentpen` on PATH so Node/nvm upgrades do not break the LaunchAgent; fall back to direct script path.
58
+ const hasBin = envPath.split(':').some((d) => { try { fs.accessSync(path.join(d, 'agentpen'), fs.constants.X_OK); return true; } catch { return false; } });
59
+ const argv = hasBin ? ['/usr/bin/env', 'agentpen', 'watch'] : [process.execPath, cli, 'watch'];
60
+ const args = argv.map((a) => ` <string>${xml(a)}</string>`).join('\n');
61
+ const envEntries = [['PATH', envPath]];
62
+ if (process.env.AGENTPEN_HOME) envEntries.push(['AGENTPEN_HOME', process.env.AGENTPEN_HOME]);
63
+ if (process.env.AGENTPEN_URL) envEntries.push(['AGENTPEN_URL', process.env.AGENTPEN_URL]);
64
+ const envXml = envEntries.map(([k, v]) => ` <key>${xml(k)}</key><string>${xml(v)}</string>`).join('\n');
53
65
  return `<?xml version="1.0" encoding="UTF-8"?>
54
66
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
55
67
  <plist version="1.0">
@@ -65,7 +77,9 @@ ${args}
65
77
  <key>StandardOutPath</key><string>${xml(log)}</string>
66
78
  <key>StandardErrorPath</key><string>${xml(log)}</string>
67
79
  <key>EnvironmentVariables</key>
68
- <dict><key>PATH</key><string>${xml(process.env.PATH || '/usr/bin:/bin')}</string></dict>
80
+ <dict>
81
+ ${envXml}
82
+ </dict>
69
83
  </dict>
70
84
  </plist>
71
85
  `;
@@ -75,18 +89,27 @@ const launchctl = (...args) => { try { execFileSync('launchctl', args, { stdio:
75
89
 
76
90
  // ---- /agentpen inside Claude Code -------------------------------------------
77
91
  // A personal skill, so typing /agentpen in a session that is already running
78
- // shares it. It runs `agentpen share` for that conversation and nothing else.
92
+ // shares it. It runs `agentpen share` for that conversation, and registers a
93
+ // hook for the rest of that session: each time Claude finishes a turn, the hook
94
+ // waits in the background for a teammate's prompt and wakes Claude with it.
79
95
  const SKILL = `---
80
96
  name: agentpen
81
97
  description: Share this Claude Code session with your Agentpen workspace so teammates can watch it live. "/agentpen stop" stops sharing.
82
98
  argument-hint: "[stop | --private]"
83
99
  disable-model-invocation: true
84
100
  allowed-tools: Bash(agentpen share *)
101
+ hooks:
102
+ Stop:
103
+ - hooks:
104
+ - type: command
105
+ command: agentpen share --await-prompt
106
+ asyncRewake: true
107
+ timeout: 43200
85
108
  ---
86
109
  <!-- installed by agentpen. Remove with: agentpen uninstall -->
87
110
  The user asked to share this session with their team through Agentpen. This command has already run:
88
111
 
89
- !\`agentpen share --in-claude --session \${CLAUDE_SESSION_ID} $ARGUMENTS\`
112
+ !\`agentpen share --in-claude --session "\${CLAUDE_SESSION_ID}" --args "$ARGUMENTS"\`
90
113
 
91
114
  Reply with one or two short lines that pass on what it printed: the link if there is one, or the problem and the fix it suggests. Do not run anything else.
92
115
  `;
@@ -112,12 +135,99 @@ export function removeSkill() {
112
135
  } catch { return false; }
113
136
  }
114
137
 
115
- export function install({ workspace, shellOnly }, ui) {
138
+ const APP_BUNDLE_ID = 'app.agentpen.mac';
139
+ const MAX_APP_BYTES = 100 * 1024 * 1024;
140
+ const isOurAppBundle = (appPath) => {
141
+ try {
142
+ return fs.existsSync(path.join(appPath, 'Contents', 'MacOS', 'Agentpen'))
143
+ && fs.readFileSync(path.join(appPath, 'Contents', 'Info.plist'), 'utf8').includes(APP_BUNDLE_ID);
144
+ } catch { return false; }
145
+ };
146
+ const pickApplicationsDir = (override) => {
147
+ if (override) { fs.mkdirSync(override, { recursive: true }); return override; }
148
+ try { fs.accessSync('/Applications', fs.constants.W_OK); return '/Applications'; } catch {}
149
+ const userApps = path.join(os.homedir(), 'Applications');
150
+ fs.mkdirSync(userApps, { recursive: true });
151
+ return userApps;
152
+ };
153
+
154
+ /**
155
+ * Download and install Agentpen.app on macOS. Verifies SHA-256 when a `.sha256`
156
+ * sidecar is published alongside the zip. Never throws: failures are reported calmly
157
+ * so `agentpen install` always finishes setting up the CLI.
158
+ */
159
+ export async function installMacApp({ url, server, appDir, noOpen = false }) {
160
+ if (!url || !/^https?:\/\//.test(url)) return { status: 'skipped' };
161
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'agentpen-app-'));
162
+ try {
163
+ let res;
164
+ try { res = await fetch(url, { redirect: 'follow', signal: AbortSignal.timeout(30_000) }); }
165
+ catch (e) { return { status: 'unavailable', reason: e.message }; }
166
+ if (!res.ok) return { status: 'unavailable', reason: `HTTP ${res.status}` };
167
+ const len = Number(res.headers.get('content-length') || 0);
168
+ if (len > MAX_APP_BYTES) return { status: 'failed', reason: 'download too large' };
169
+ const buf = Buffer.from(await res.arrayBuffer());
170
+ if (!buf.length || buf.length > MAX_APP_BYTES) return { status: 'failed', reason: 'invalid download size' };
171
+
172
+ // Verify SHA-256 if a `.sha256` sidecar file exists next to the release zip.
173
+ try {
174
+ const sumRes = await fetch(`${url}.sha256`, { redirect: 'follow', signal: AbortSignal.timeout(5000) });
175
+ if (sumRes.ok) {
176
+ const expected = /^([0-9a-f]{64})\b/i.exec((await sumRes.text()).trim())?.[1]?.toLowerCase();
177
+ const actual = createHash('sha256').update(buf).digest('hex');
178
+ if (expected && actual !== expected) return { status: 'failed', reason: 'checksum mismatch' };
179
+ }
180
+ } catch {}
181
+
182
+ const zip = path.join(tmp, 'Agentpen.zip');
183
+ const unpack = path.join(tmp, 'unpack');
184
+ fs.writeFileSync(zip, buf);
185
+ fs.mkdirSync(unpack);
186
+ execFileSync('ditto', ['-xk', zip, unpack], { stdio: 'ignore' });
187
+ const extracted = path.join(unpack, 'Agentpen.app');
188
+ if (!isOurAppBundle(extracted)) return { status: 'failed', reason: 'archive did not contain Agentpen.app' };
189
+
190
+ const targetDir = pickApplicationsDir(appDir);
191
+ const dest = path.join(targetDir, 'Agentpen.app');
192
+ if (fs.existsSync(dest)) {
193
+ try { execFileSync('osascript', ['-e', `tell application id "${APP_BUNDLE_ID}" to quit`], { stdio: 'ignore', timeout: 3000 }); } catch {}
194
+ fs.rmSync(dest, { recursive: true, force: true });
195
+ }
196
+ execFileSync('ditto', [extracted, dest], { stdio: 'ignore' });
197
+
198
+ if (server && server !== 'https://agentpen.app') {
199
+ try { execFileSync('defaults', ['write', APP_BUNDLE_ID, 'server', server], { stdio: 'ignore' }); } catch {}
200
+ }
201
+ if (!noOpen && !process.env.AGENTPEN_NO_OPEN) {
202
+ try { spawn('open', ['-a', dest], { stdio: 'ignore', detached: true }).on('error', () => {}).unref(); } catch {}
203
+ }
204
+ return { status: 'installed', path: dest };
205
+ } catch (e) {
206
+ return { status: 'failed', reason: e.message };
207
+ } finally {
208
+ fs.rmSync(tmp, { recursive: true, force: true });
209
+ }
210
+ }
211
+
212
+ export function removeMacApp({ appDir } = {}) {
213
+ const dirs = appDir ? [appDir] : ['/Applications', path.join(os.homedir(), 'Applications')];
214
+ const removed = [];
215
+ for (const d of dirs) {
216
+ const p = path.join(d, 'Agentpen.app');
217
+ if (!isOurAppBundle(p)) continue;
218
+ try { execFileSync('osascript', ['-e', `tell application id "${APP_BUNDLE_ID}" to quit`], { stdio: 'ignore', timeout: 3000 }); } catch {}
219
+ try { fs.rmSync(p, { recursive: true, force: true }); removed.push(p); } catch {}
220
+ }
221
+ return removed;
222
+ }
223
+
224
+ export async function install({ workspace, shellOnly, noApp, macAppUrl, server }, ui) {
116
225
  const files = rcFiles();
117
226
  for (const f of files) writeHook(f);
118
227
 
119
228
  const skill = installSkill();
120
229
  let codex = 'skipped';
230
+ let macApp = { status: 'skipped' };
121
231
  if (!shellOnly && process.platform === 'darwin') {
122
232
  const p = plistPath();
123
233
  fs.mkdirSync(path.dirname(p), { recursive: true });
@@ -125,6 +235,9 @@ export function install({ workspace, shellOnly }, ui) {
125
235
  const target = `gui/${process.getuid()}`;
126
236
  launchctl('bootout', `${target}/${LABEL}`);
127
237
  codex = launchctl('bootstrap', target, p) ? 'on' : 'failed';
238
+ if (!noApp && process.env.AGENTPEN_NO_APP !== '1' && macAppUrl) {
239
+ macApp = await installMacApp({ url: macAppUrl, server });
240
+ }
128
241
  } else if (!shellOnly) codex = 'manual';
129
242
 
130
243
  ui.say();
@@ -136,7 +249,12 @@ export function install({ workspace, shellOnly }, ui) {
136
249
  if (skill) {
137
250
  ui.say();
138
251
  ui.say(` ${ui.accent('/agentpen')} In a Claude Code session that is already running, type ${ui.bold('/agentpen')} to share it.`);
139
- ui.say(ui.dim(' Teammates can watch that one and chat. They cannot type into it.'));
252
+ ui.say(ui.dim(' Teammates can watch, chat, and send attributed prompts into the session.'));
253
+ }
254
+ if (/\/fish$/.test(process.env.SHELL || '')) {
255
+ ui.say();
256
+ ui.say(` ${ui.accent('fish shell')} Add this function to ~/.config/fish/config.fish for automatic sharing:`);
257
+ ui.say(ui.dim(' function claude; command agentpen --auto claude $argv; end'));
140
258
  }
141
259
  ui.say();
142
260
  if (codex === 'on') {
@@ -147,6 +265,14 @@ export function install({ workspace, shellOnly }, ui) {
147
265
  } else if (codex === 'manual') {
148
266
  ui.say(` ${ui.accent('Codex app')} The background helper is set up on macOS only. Here, keep ${ui.bold('agentpen watch')} running.`);
149
267
  }
268
+ if (macApp.status === 'installed') {
269
+ ui.say();
270
+ ui.say(` ${ui.accent('Mac app')} Installed to ${macApp.path.replace(os.homedir(), '~')}.`);
271
+ ui.say(ui.dim(' Click the menu bar icon to sign in and get native macOS notifications.'));
272
+ } else if (macApp.status === 'unavailable' || macApp.status === 'failed') {
273
+ ui.say();
274
+ ui.say(` ${ui.accent('Mac app')} Not installed (${macApp.reason}). You can download it anytime from Settings in the web app.`);
275
+ }
150
276
  ui.say();
151
277
  ui.say(ui.dim(' Everyone in the workspace can see shared sessions.'));
152
278
  ui.say(ui.dim(' agentpen pause stop sharing new sessions for now'));
@@ -163,11 +289,14 @@ export function uninstall(ui) {
163
289
  const after = strip(before);
164
290
  if (after !== before) { fs.writeFileSync(f, after); touched.push(f.replace(os.homedir(), '~')); }
165
291
  }
292
+ let removedApps = [];
166
293
  if (process.platform === 'darwin') {
167
294
  launchctl('bootout', `gui/${process.getuid()}/${LABEL}`);
168
295
  fs.rmSync(plistPath(), { force: true });
296
+ removedApps = removeMacApp();
169
297
  }
170
298
  if (removeSkill()) ui.say('Removed /agentpen from Claude Code.');
171
299
  ui.say(touched.length ? `Removed the claude hook from ${touched.join(' and ')}. Open a new terminal for it to take effect.` : 'No claude hook was installed.');
172
300
  if (process.platform === 'darwin') ui.say('Stopped the Codex app helper.');
301
+ for (const p of removedApps) ui.say(`Removed ${p.replace(os.homedir(), '~')}.`);
173
302
  }
package/cli/redact.js CHANGED
@@ -7,21 +7,29 @@ import path from 'node:path';
7
7
  const BORING = new Set(['true', 'false', 'null', 'undefined', 'localhost', 'development', 'production', 'staging', 'test', 'debug', 'info', 'warn', 'error', 'example', 'changeme', 'change-me', 'password', 'secret', 'default']);
8
8
  const MASK = Buffer.from('••••••').toString('latin1');
9
9
 
10
- export function collectSecrets(dir) {
10
+ export function collectSecrets(...dirs) {
11
11
  const values = new Set();
12
- let files = [];
13
- try { files = fs.readdirSync(dir).filter((f) => f === '.env' || f.startsWith('.env.')); } catch {}
14
- for (const f of files) {
15
- let text;
16
- try { text = fs.readFileSync(path.join(dir, f), 'utf8'); } catch { continue; }
17
- for (let line of text.split('\n')) {
18
- line = line.trim().replace(/^export\s+/, '');
19
- const eq = line.indexOf('=');
20
- if (eq <= 0 || line.startsWith('#')) continue;
21
- let v = line.slice(eq + 1).trim();
22
- const quoted = /^(["'])(.*)\1$/.exec(v);
23
- if (quoted) v = quoted[2];
24
- if (v.length >= 8 && !BORING.has(v.toLowerCase())) values.add(v);
12
+ const seenDirs = new Set();
13
+ for (const dir of dirs) {
14
+ if (!dir) continue;
15
+ const resolved = path.resolve(dir);
16
+ if (seenDirs.has(resolved)) continue;
17
+ seenDirs.add(resolved);
18
+ let files = [];
19
+ try { files = fs.readdirSync(resolved).filter((f) => f === '.env' || f.startsWith('.env.')); } catch {}
20
+ for (const f of files) {
21
+ let text;
22
+ try { text = fs.readFileSync(path.join(resolved, f), 'utf8'); } catch { continue; }
23
+ for (let line of text.split('\n')) {
24
+ line = line.trim().replace(/^export\s+/, '');
25
+ const eq = line.indexOf('=');
26
+ if (eq <= 0 || line.startsWith('#')) continue;
27
+ let v = line.slice(eq + 1).trim();
28
+ const quoted = /^(["'])(.*)\1(?:\s+#.*)?$/.exec(v);
29
+ if (quoted) v = quoted[2];
30
+ else v = v.replace(/\s+#.*$/, '').trim();
31
+ if (v.length >= 8 && !BORING.has(v.toLowerCase())) values.add(v);
32
+ }
25
33
  }
26
34
  }
27
35
  return [...values];
@@ -30,8 +38,11 @@ export function collectSecrets(dir) {
30
38
  // Streaming: bytes that could be the start of a secret are held until the next
31
39
  // chunk (or a 25ms timer) settles it. latin1 keeps the splice byte-exact.
32
40
  export function makeRedactor(values, emit) {
33
- if (!values.length) return { write: emit, flush() {} };
34
- const needles = values.map((v) => Buffer.from(v).toString('latin1')).sort((a, b) => b.length - a.length);
41
+ let needles = [];
42
+ const update = (nextValues) => {
43
+ needles = (nextValues || []).map((v) => Buffer.from(v).toString('latin1')).sort((a, b) => b.length - a.length);
44
+ };
45
+ update(values);
35
46
  const mask = (t) => { for (const n of needles) t = t.split(n).join(MASK); return t; };
36
47
  let carry = '';
37
48
  let timer = null;
@@ -44,7 +55,12 @@ export function makeRedactor(values, emit) {
44
55
  emit(Buffer.from(out, 'latin1'));
45
56
  };
46
57
  return {
58
+ update,
47
59
  write(buf) {
60
+ if (!needles.length) {
61
+ if (carry) flush();
62
+ return emit(buf);
63
+ }
48
64
  clearTimeout(timer);
49
65
  const text = mask(carry + buf.toString('latin1'));
50
66
  let hold = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentpen-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "description": "The team room for your coding agents - share live Claude Code / Codex sessions with your whole company",
5
5
  "license": "MIT",
6
6
  "homepage": "https://agentpen.app",
@@ -24,7 +24,7 @@
24
24
  "postinstall": "node cli/postinstall.js"
25
25
  },
26
26
  "engines": {
27
- "node": ">=22.13"
27
+ "node": ">=20"
28
28
  },
29
29
  "dependencies": {
30
30
  "@anthropic-ai/sdk": "^1.12.0",
@@ -37,8 +37,6 @@
37
37
  },
38
38
  "files": [
39
39
  "cli/",
40
- "server/",
41
- "web/",
42
40
  "README.md",
43
41
  "LICENSE"
44
42
  ]