@causyne/agent 1.20.0 → 1.20.5

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 (125) hide show
  1. package/README.md +0 -18
  2. package/package.json +1 -1
  3. package/src/acp/client.js +2 -1
  4. package/src/acp/client.ts +2 -1
  5. package/src/acp/server.js +5 -6
  6. package/src/acp/server.ts +4 -6
  7. package/src/agentLoop.d.ts +1 -0
  8. package/src/agentLoop.js +505 -241
  9. package/src/agentLoop.ts +527 -258
  10. package/src/agentPolicy.js +9 -0
  11. package/src/agentPolicy.ts +9 -0
  12. package/src/approvalPolicy.js +55 -0
  13. package/src/approvalPolicy.ts +66 -0
  14. package/src/browser/browserRuntime.js +217 -14
  15. package/src/browser/browserRuntime.ts +255 -14
  16. package/src/browser/causyneBrowser.js +1215 -68
  17. package/src/browser/causyneBrowser.ts +1340 -72
  18. package/src/cliMode.js +52 -29
  19. package/src/commands.js +141 -17
  20. package/src/config.js +22 -12
  21. package/src/continuum/ui/continuumPicker.js +18 -1
  22. package/src/continuum/ui/continuumPicker.ts +19 -1
  23. package/src/dynamicCatalogue.js +87 -20
  24. package/src/dynamicCatalogue.ts +85 -15
  25. package/src/launchIntent.js +40 -0
  26. package/src/launchIntent.ts +49 -0
  27. package/src/memoryManager.js +26 -2
  28. package/src/modelCatalogue.js +2 -0
  29. package/src/planCache.js +320 -11
  30. package/src/planCache.ts +402 -13
  31. package/src/providers/acp.js +67 -1
  32. package/src/providers/acp.ts +65 -2
  33. package/src/providers/antigravity.d.ts +5 -1
  34. package/src/providers/antigravity.js +643 -32
  35. package/src/providers/antigravity.ts +671 -33
  36. package/src/providers/base.d.ts +9 -0
  37. package/src/providers/factory.js +2 -0
  38. package/src/providers/pi.js +157 -0
  39. package/src/providers/pi.ts +144 -0
  40. package/src/provisioning/capabilityProvisioner.js +17 -0
  41. package/src/provisioning/capabilityTools.js +1 -1
  42. package/src/sandbox.js +30 -39
  43. package/src/sessionJournal.js +53 -10
  44. package/src/sessionJournal.ts +64 -10
  45. package/src/taskShape.js +9 -9
  46. package/src/taskShape.ts +9 -9
  47. package/src/timeMachine.js +124 -0
  48. package/src/timeMachine.ts +141 -0
  49. package/src/toolPacks.js +4 -10
  50. package/src/tools/archive.js +196 -59
  51. package/src/tools/archive.ts +220 -0
  52. package/src/tools/browserAutomator.js +78 -9
  53. package/src/tools/browserAutomator.ts +90 -9
  54. package/src/tools/desktopOpen.js +114 -31
  55. package/src/tools/desktopOpen.ts +144 -0
  56. package/src/tools/gitExec.js +5 -3
  57. package/src/tools/nativeEngine.js +4 -3
  58. package/src/tools/nativeEngine.ts +5 -3
  59. package/src/tools/openSourceToolProvisioner.js +5 -4
  60. package/src/tools/openSourceToolProvisioner.ts +5 -4
  61. package/src/tools/registry.js +3 -0
  62. package/src/tools/screenshot.js +55 -71
  63. package/src/tools/screenshot.ts +70 -0
  64. package/src/tools/sysRun.js +284 -117
  65. package/src/tools/sysRun.ts +347 -0
  66. package/src/tools/toolSelfRepair.js +109 -2
  67. package/src/tools/toolSelfRepair.ts +100 -2
  68. package/src/tools/updatePlan.js +49 -1
  69. package/src/tools/updatePlan.ts +43 -1
  70. package/src/tools/viewImage.js +93 -78
  71. package/src/tools/viewImage.ts +116 -0
  72. package/src/tools/webFetch.js +20 -6
  73. package/src/tools/webFetch.ts +26 -6
  74. package/src/tui/block.d.ts +1 -0
  75. package/src/tui/chatRenderer.d.ts +21 -0
  76. package/src/tui/chatRenderer.js +34 -47
  77. package/src/tui/clipboardSync.js +28 -1
  78. package/src/tui/clipboardSync.ts +26 -1
  79. package/src/tui/codeProgress.js +299 -0
  80. package/src/tui/codeProgress.ts +304 -0
  81. package/src/tui/codeStreamRenderer.js +116 -0
  82. package/src/tui/codeStreamRenderer.ts +124 -0
  83. package/src/tui/commandPresentation.js +11 -0
  84. package/src/tui/commandPresentation.ts +18 -0
  85. package/src/tui/completion.js +45 -13
  86. package/src/tui/composerControls.js +66 -0
  87. package/src/tui/composerControls.ts +78 -0
  88. package/src/tui/diff.d.ts +2 -0
  89. package/src/tui/home.js +4 -2
  90. package/src/tui/homeTransition.js +21 -0
  91. package/src/tui/homeTransition.ts +27 -0
  92. package/src/tui/homeView.js +62 -0
  93. package/src/tui/homeView.ts +91 -0
  94. package/src/tui/layout.js +46 -0
  95. package/src/tui/layout.ts +52 -0
  96. package/src/tui/messageActionPlacement.js +16 -0
  97. package/src/tui/messageActionPlacement.ts +25 -0
  98. package/src/tui/messageInteraction.js +221 -0
  99. package/src/tui/messageInteraction.ts +275 -0
  100. package/src/tui/modelPicker.js +4 -24
  101. package/src/tui/modelPicker.ts +4 -20
  102. package/src/tui/mouseHover.js +6 -0
  103. package/src/tui/mouseHover.ts +5 -0
  104. package/src/tui/prompt.js +152 -76
  105. package/src/tui/resizeRecovery.js +15 -0
  106. package/src/tui/resizeRecovery.ts +27 -0
  107. package/src/tui/scrollInteraction.js +97 -0
  108. package/src/tui/scrollInteraction.ts +189 -0
  109. package/src/tui/sessionLayout.js +12 -0
  110. package/src/tui/sessionLayout.ts +12 -0
  111. package/src/tui/sessionPicker.js +111 -16
  112. package/src/tui/sessionPicker.ts +121 -16
  113. package/src/tui/sessionSidebar.js +78 -0
  114. package/src/tui/sessionSidebar.ts +95 -0
  115. package/src/tui/setup.js +1 -1
  116. package/src/tui/setup.ts +1 -1
  117. package/src/tui/stageSurface.js +120 -58
  118. package/src/tui/text.d.ts +5 -0
  119. package/src/tui/textLayout.js +23 -0
  120. package/src/tui/textLayout.ts +28 -0
  121. package/src/tui/viewport.js +204 -279
  122. package/src/tui/viewport.ts +326 -0
  123. package/src/types/contracts.ts +54 -0
  124. package/src/utils/paths.js +5 -4
  125. package/src/utils/paths.ts +5 -5
@@ -15,7 +15,7 @@ import { execFile } from 'node:child_process';
15
15
  import { promisify } from 'node:util';
16
16
  import { causyneHome } from './utils/paths.js';
17
17
  import { MODEL_CATALOGUE, PEER_MODEL_CATALOGUE, DEFAULT_MODEL_BY_PROVIDER } from './modelCatalogue.js';
18
- import { ANTIGRAVITY_MODELS, ANTIGRAVITY_LABEL_BY_ID, resolveAgyBinary } from './providers/antigravity.js';
18
+ import { ANTIGRAVITY_MODELS, ANTIGRAVITY_LABEL_BY_ID, registerAntigravityModel, parseAgyModelsOutput, resolveAgyBinary } from './providers/antigravity.js';
19
19
  import { isBinaryOnPath, BUILTIN_PEER_PRESETS } from './acp/agentCatalog.js';
20
20
  const execFileAsync = promisify(execFile);
21
21
  const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
@@ -75,6 +75,8 @@ export function getCuratedModels(provider) {
75
75
  const norm = normalizeProviderKey(provider);
76
76
  if (norm === 'antigravity')
77
77
  return [...ANTIGRAVITY_MODELS];
78
+ if (norm === 'pi')
79
+ return [...(MODEL_CATALOGUE['Pi (Local Peer)'] || [])];
78
80
  const peer = peerIdFromProviderKey(norm);
79
81
  if (peer)
80
82
  return [...(PEER_MODEL_CATALOGUE[peer] ?? [])];
@@ -193,6 +195,14 @@ export function getAvailableProvidersOverview(config = {}) {
193
195
  models: [...ANTIGRAVITY_MODELS],
194
196
  setupInstruction: 'Install Antigravity IDE or agy CLI to enable Google AGY models.'
195
197
  });
198
+ const hasPi = isBinaryOnPath('pi');
199
+ acpPeers.push({
200
+ id: 'pi', providerKey: 'pi', label: 'Pi coding agent',
201
+ installed: hasPi, status: hasPi ? 'ready' : 'not_installed',
202
+ isCurrent: currentProvider === 'pi', command: 'pi --mode rpc --no-tools',
203
+ models: ['default'],
204
+ setupInstruction: 'Install Pi CLI and configure its model login before selecting it in Causyne.'
205
+ });
196
206
  // Standard ACP presets
197
207
  const presetOrder = ['opencode', 'claude', 'codex', 'gemini', 'cursor', 'hermes', 'qwen', 'copilot', 'kimi', 'goose'];
198
208
  for (const presetId of presetOrder) {
@@ -208,8 +218,15 @@ export function getAvailableProvidersOverview(config = {}) {
208
218
  }
209
219
  const providerKey = `acp/${preset.id}`;
210
220
  const isCurrent = currentProvider === providerKey;
221
+ const cachedPeerModels = getCachedModels(providerKey) || getCachedModels(preset.id);
211
222
  let models = [];
212
- if (PEER_MODEL_CATALOGUE[preset.id]) {
223
+ if (cachedPeerModels && cachedPeerModels.length > 0) {
224
+ models = [...cachedPeerModels];
225
+ }
226
+ else if (preset.id === 'claude') {
227
+ models = detectClaudeModels();
228
+ }
229
+ else if (PEER_MODEL_CATALOGUE[preset.id]) {
213
230
  models = [...(PEER_MODEL_CATALOGUE[preset.id] || [])];
214
231
  }
215
232
  else if (DEFAULT_MODEL_BY_PROVIDER[providerKey]) {
@@ -258,15 +275,52 @@ async function runModelList(command, args) {
258
275
  }
259
276
  function parseModelIds(lines) {
260
277
  const models = [];
261
- for (const line of lines) {
278
+ for (const rawLine of lines) {
279
+ const line = rawLine.replace(ANSI_ESCAPE, '').trim();
280
+ if (!line)
281
+ continue;
262
282
  if (/^(fetching|loading|no models|error)/i.test(line))
263
283
  continue;
264
284
  if (line.endsWith('…') || line.endsWith('...'))
265
285
  continue;
266
- const firstColumn = (line.split('\t')[0] ?? '').trim();
267
- if (!firstColumn || firstColumn.includes(' '))
268
- continue;
269
- models.push(firstColumn);
286
+ const match = line.match(/^([a-z0-9_./-]+)/i);
287
+ if (match && match[1]) {
288
+ models.push(match[1]);
289
+ }
290
+ }
291
+ return [...new Set(models)];
292
+ }
293
+ function detectClaudeModels() {
294
+ const models = [];
295
+ try {
296
+ const home = process.env.HOME || process.env.USERPROFILE || '';
297
+ if (home) {
298
+ const settingsFile = path.join(home, '.claude', 'settings.json');
299
+ if (fs.existsSync(settingsFile)) {
300
+ const content = fs.readFileSync(settingsFile, 'utf8');
301
+ const parsed = JSON.parse(content);
302
+ if (typeof parsed?.model === 'string' && parsed.model.trim()) {
303
+ models.push(parsed.model.trim());
304
+ }
305
+ if (Array.isArray(parsed?.availableModels)) {
306
+ for (const m of parsed.availableModels) {
307
+ if (typeof m === 'string' && m.trim())
308
+ models.push(m.trim());
309
+ }
310
+ }
311
+ }
312
+ }
313
+ }
314
+ catch {
315
+ // Ignore settings read errors
316
+ }
317
+ const envModel = process.env.ANTHROPIC_MODEL || process.env.CLAUDE_MODEL;
318
+ if (envModel && typeof envModel === 'string' && envModel.trim()) {
319
+ models.push(envModel.trim());
320
+ }
321
+ const curated = PEER_MODEL_CATALOGUE['claude'] ?? ['sonnet', 'opus', 'haiku'];
322
+ for (const m of curated) {
323
+ models.push(m);
270
324
  }
271
325
  return [...new Set(models)];
272
326
  }
@@ -276,24 +330,37 @@ function parseModelIds(lines) {
276
330
  */
277
331
  export async function discoverPeerModels(peerId) {
278
332
  const peer = (peerId || '').toLowerCase().trim();
333
+ if (peer === 'claude') {
334
+ return detectClaudeModels();
335
+ }
279
336
  const listing = PEER_MODEL_COMMANDS[peer];
280
- if (!listing)
281
- return [];
282
- return parseModelIds(await runModelList(listing.command, listing.args));
337
+ if (listing) {
338
+ const discovered = parseModelIds(await runModelList(listing.command, listing.args));
339
+ if (discovered.length > 0)
340
+ return discovered;
341
+ }
342
+ return PEER_MODEL_CATALOGUE[peer] ? [...PEER_MODEL_CATALOGUE[peer]] : [];
283
343
  }
284
344
  /** Ask Antigravity for its live model list and return the readable labels. */
285
345
  export async function discoverAntigravityModels() {
286
- const lines = await runModelList(resolveAgyBinary(), ['models']);
287
- const models = [];
288
- for (const line of lines) {
289
- if (/^(fetching|loading|no models|error)/i.test(line))
290
- continue;
291
- const [id, label] = line.split('\t').map((part) => part.trim());
292
- if (!id || id.includes(' '))
293
- continue;
294
- models.push(label || ANTIGRAVITY_LABEL_BY_ID[id] || id);
346
+ try {
347
+ const { stdout } = await execFileAsync(resolveAgyBinary(), ['models'], {
348
+ timeout: MODEL_LIST_TIMEOUT_MS,
349
+ maxBuffer: 4 * 1024 * 1024,
350
+ windowsHide: true
351
+ });
352
+ const parsed = parseAgyModelsOutput(stdout);
353
+ if (parsed.length > 0) {
354
+ for (const item of parsed) {
355
+ registerAntigravityModel(item.id, item.label);
356
+ }
357
+ return [...new Set(parsed.map((item) => item.label || item.id))];
358
+ }
295
359
  }
296
- return [...new Set(models)];
360
+ catch {
361
+ // Fall back to current registered or baseline models
362
+ }
363
+ return [...ANTIGRAVITY_MODELS];
297
364
  }
298
365
  /** Read cache safely from ~/.causyne/models_cache.json */
299
366
  export function readModelCache() {
@@ -19,6 +19,8 @@ import { MODEL_CATALOGUE, PEER_MODEL_CATALOGUE, DEFAULT_MODEL_BY_PROVIDER } from
19
19
  import {
20
20
  ANTIGRAVITY_MODELS,
21
21
  ANTIGRAVITY_LABEL_BY_ID,
22
+ registerAntigravityModel,
23
+ parseAgyModelsOutput,
22
24
  resolveAgyBinary
23
25
  } from './providers/antigravity.js';
24
26
  import { isBinaryOnPath, BUILTIN_PEER_PRESETS } from './acp/agentCatalog.js';
@@ -81,6 +83,7 @@ export function peerIdFromProviderKey(provider: string): string | null {
81
83
  export function getCuratedModels(provider: string): string[] {
82
84
  const norm = normalizeProviderKey(provider);
83
85
  if (norm === 'antigravity') return [...ANTIGRAVITY_MODELS];
86
+ if (norm === 'pi') return [...(MODEL_CATALOGUE['Pi (Local Peer)'] || [])];
84
87
  const peer = peerIdFromProviderKey(norm);
85
88
  if (peer) return [...(PEER_MODEL_CATALOGUE[peer] ?? [])];
86
89
  if (norm === 'acp') return [...(MODEL_CATALOGUE['ACP (Peer Agents)'] ?? [])];
@@ -235,6 +238,15 @@ export function getAvailableProvidersOverview(
235
238
  setupInstruction: 'Install Antigravity IDE or agy CLI to enable Google AGY models.'
236
239
  });
237
240
 
241
+ const hasPi = isBinaryOnPath('pi');
242
+ acpPeers.push({
243
+ id: 'pi', providerKey: 'pi', label: 'Pi coding agent',
244
+ installed: hasPi, status: hasPi ? 'ready' : 'not_installed',
245
+ isCurrent: currentProvider === 'pi', command: 'pi --mode rpc --no-tools',
246
+ models: ['default'],
247
+ setupInstruction: 'Install Pi CLI and configure its model login before selecting it in Causyne.'
248
+ });
249
+
238
250
  // Standard ACP presets
239
251
  const presetOrder = ['opencode', 'claude', 'codex', 'gemini', 'cursor', 'hermes', 'qwen', 'copilot', 'kimi', 'goose'];
240
252
  for (const presetId of presetOrder) {
@@ -251,8 +263,13 @@ export function getAvailableProvidersOverview(
251
263
  const providerKey = `acp/${preset.id}`;
252
264
  const isCurrent = currentProvider === providerKey;
253
265
 
266
+ const cachedPeerModels = getCachedModels(providerKey) || getCachedModels(preset.id);
254
267
  let models: string[] = [];
255
- if (PEER_MODEL_CATALOGUE[preset.id]) {
268
+ if (cachedPeerModels && cachedPeerModels.length > 0) {
269
+ models = [...cachedPeerModels];
270
+ } else if (preset.id === 'claude') {
271
+ models = detectClaudeModels();
272
+ } else if (PEER_MODEL_CATALOGUE[preset.id]) {
256
273
  models = [...(PEER_MODEL_CATALOGUE[preset.id] || [])];
257
274
  } else if (DEFAULT_MODEL_BY_PROVIDER[providerKey]) {
258
275
  models = [DEFAULT_MODEL_BY_PROVIDER[providerKey]];
@@ -304,38 +321,91 @@ async function runModelList(command: string, args: string[]): Promise<string[]>
304
321
 
305
322
  function parseModelIds(lines: string[]): string[] {
306
323
  const models: string[] = [];
307
- for (const line of lines) {
324
+ for (const rawLine of lines) {
325
+ const line = rawLine.replace(ANSI_ESCAPE, '').trim();
326
+ if (!line) continue;
308
327
  if (/^(fetching|loading|no models|error)/i.test(line)) continue;
309
328
  if (line.endsWith('…') || line.endsWith('...')) continue;
310
- const firstColumn = (line.split('\t')[0] ?? '').trim();
311
- if (!firstColumn || firstColumn.includes(' ')) continue;
312
- models.push(firstColumn);
329
+ const match = line.match(/^([a-z0-9_./-]+)/i);
330
+ if (match && match[1]) {
331
+ models.push(match[1]);
332
+ }
313
333
  }
314
334
  return [...new Set(models)];
315
335
  }
316
336
 
337
+ function detectClaudeModels(): string[] {
338
+ const models: string[] = [];
339
+ try {
340
+ const home = process.env.HOME || process.env.USERPROFILE || '';
341
+ if (home) {
342
+ const settingsFile = path.join(home, '.claude', 'settings.json');
343
+ if (fs.existsSync(settingsFile)) {
344
+ const content = fs.readFileSync(settingsFile, 'utf8');
345
+ const parsed = JSON.parse(content) as { model?: string; availableModels?: string[] };
346
+ if (typeof parsed?.model === 'string' && parsed.model.trim()) {
347
+ models.push(parsed.model.trim());
348
+ }
349
+ if (Array.isArray(parsed?.availableModels)) {
350
+ for (const m of parsed.availableModels) {
351
+ if (typeof m === 'string' && m.trim()) models.push(m.trim());
352
+ }
353
+ }
354
+ }
355
+ }
356
+ } catch {
357
+ // Ignore settings read errors
358
+ }
359
+
360
+ const envModel = process.env.ANTHROPIC_MODEL || process.env.CLAUDE_MODEL;
361
+ if (envModel && typeof envModel === 'string' && envModel.trim()) {
362
+ models.push(envModel.trim());
363
+ }
364
+
365
+ const curated = PEER_MODEL_CATALOGUE['claude'] ?? ['sonnet', 'opus', 'haiku'];
366
+ for (const m of curated) {
367
+ models.push(m);
368
+ }
369
+
370
+ return [...new Set(models)];
371
+ }
372
+
317
373
  /**
318
374
  * Ask a peer CLI which models its account can reach. Zero tokens: this runs the
319
375
  * peer's own listing command, never a model request.
320
376
  */
321
377
  export async function discoverPeerModels(peerId: string): Promise<string[]> {
322
378
  const peer = (peerId || '').toLowerCase().trim();
379
+ if (peer === 'claude') {
380
+ return detectClaudeModels();
381
+ }
323
382
  const listing = PEER_MODEL_COMMANDS[peer];
324
- if (!listing) return [];
325
- return parseModelIds(await runModelList(listing.command, listing.args));
383
+ if (listing) {
384
+ const discovered = parseModelIds(await runModelList(listing.command, listing.args));
385
+ if (discovered.length > 0) return discovered;
386
+ }
387
+ return PEER_MODEL_CATALOGUE[peer] ? [...PEER_MODEL_CATALOGUE[peer]] : [];
326
388
  }
327
389
 
328
390
  /** Ask Antigravity for its live model list and return the readable labels. */
329
391
  export async function discoverAntigravityModels(): Promise<string[]> {
330
- const lines = await runModelList(resolveAgyBinary(), ['models']);
331
- const models: string[] = [];
332
- for (const line of lines) {
333
- if (/^(fetching|loading|no models|error)/i.test(line)) continue;
334
- const [id, label] = line.split('\t').map((part) => part.trim());
335
- if (!id || id.includes(' ')) continue;
336
- models.push(label || ANTIGRAVITY_LABEL_BY_ID[id] || id);
392
+ try {
393
+ const { stdout } = await execFileAsync(resolveAgyBinary(), ['models'], {
394
+ timeout: MODEL_LIST_TIMEOUT_MS,
395
+ maxBuffer: 4 * 1024 * 1024,
396
+ windowsHide: true
397
+ });
398
+ const parsed = parseAgyModelsOutput(stdout);
399
+ if (parsed.length > 0) {
400
+ for (const item of parsed) {
401
+ registerAntigravityModel(item.id, item.label);
402
+ }
403
+ return [...new Set(parsed.map((item) => item.label || item.id))];
404
+ }
405
+ } catch {
406
+ // Fall back to current registered or baseline models
337
407
  }
338
- return [...new Set(models)];
408
+ return [...ANTIGRAVITY_MODELS];
339
409
  }
340
410
 
341
411
  /** Read cache safely from ~/.causyne/models_cache.json */
@@ -0,0 +1,40 @@
1
+ const LAUNCH_VERBS = /\b(open|launch|start|run|play|serve|preview|buka|jalankan|mainkan|pratinjau)\b/i;
2
+ const CHANGE_VERBS = /\b(create|build|make|write|edit|fix|modify|change|update|implement|generate|refactor|delete|remove|install|deploy|buat|bangun|tulis|ubah|perbaiki|hapus|pasang)\b/i;
3
+ const SERVER_COMMAND = /^\s*(?:python(?:3(?:\.\d+)?)?\s+(?:-u\s+)?(?:\S*\/)?server\.py\b|python(?:3(?:\.\d+)?)?\s+-m\s+http\.server\b|(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start|serve)\b|(?:npx|bunx)\s+(?:vite|next\s+dev|http-server)\b|uvicorn\b|gunicorn\b|flask\s+run\b)/i;
4
+ const READ_ONLY_COMMAND = /^\s*(?:pwd|ls|rg|grep|cat|head|tail|find|which|where|ps|pgrep|lsof|netstat|ss|git\s+(?:status|diff|log|show)|node\s+(?:-v|--version)|python(?:3(?:\.\d+)?)?\s+(?:-V|--version))\b/i;
5
+ const OPEN_COMMAND = /^\s*(?:open|xdg-open|start)\s+\S+/i;
6
+ const LOCAL_HEALTH_CHECK = /^\s*curl\s+(?:(?:-I|-s|-S|-f|--head|--silent|--show-error|--fail|--max-time\s+\d+)\s+)*https?:\/\/(?:localhost|127\.0\.0\.1):\d+(?:\/\S*)?\s*$/i;
7
+ const PORT_CLEANUP_COMMAND = /^\s*(?:pkill|kill|fuser)\b/i;
8
+ const MUTATION_TOOLS = new Set([
9
+ 'fs_write', 'fs_edit', 'fs_delete', 'fs_move',
10
+ 'multi_edit', 'MultiEdit', 'edit_file', 'write_to_file', 'delete_file',
11
+ 'create_skill', 'manage_local_dependencies'
12
+ ]);
13
+ export function isLaunchOnlyPrompt(prompt) {
14
+ if (/\b(?:run|jalankan)\s+(?:the\s+)?(?:tests?|checks?|lint|benchmarks?|scripts?|commands?)\b/i.test(prompt))
15
+ return false;
16
+ return LAUNCH_VERBS.test(prompt) && !CHANGE_VERBS.test(prompt);
17
+ }
18
+ export function isServerLaunchCommand(command) {
19
+ return SERVER_COMMAND.test(command.trim());
20
+ }
21
+ /** A launch-only request authorizes inspection, starting the app, and opening it. */
22
+ export function launchScopeError(tool, args) {
23
+ if (MUTATION_TOOLS.has(tool)) {
24
+ return 'The user asked to open the existing project, not change its files or configuration.';
25
+ }
26
+ if (tool === 'sysRun' || tool === 'sysRunBg' || tool === 'terminal_persistent_shell') {
27
+ const command = String(args.command ?? args.input ?? '').trim();
28
+ if (OPEN_COMMAND.test(command) || isServerLaunchCommand(command) || LOCAL_HEALTH_CHECK.test(command) || PORT_CLEANUP_COMMAND.test(command)) {
29
+ return null;
30
+ }
31
+ if (/[;&|><`$()]/.test(command)) {
32
+ return 'A launch-only request does not authorize chained shell commands. Use one scoped command per tool call.';
33
+ }
34
+ if (READ_ONLY_COMMAND.test(command)) {
35
+ return null;
36
+ }
37
+ return 'The user asked to open the existing project. Use read-only inspection, a background server, or desktop.open; do not run unrelated commands.';
38
+ }
39
+ return null;
40
+ }
@@ -0,0 +1,49 @@
1
+ const LAUNCH_VERBS = /\b(open|launch|start|run|play|serve|preview|buka|jalankan|mainkan|pratinjau)\b/i;
2
+ const CHANGE_VERBS = /\b(create|build|make|write|edit|fix|modify|change|update|implement|generate|refactor|delete|remove|install|deploy|buat|bangun|tulis|ubah|perbaiki|hapus|pasang)\b/i;
3
+ const SERVER_COMMAND = /^\s*(?:python(?:3(?:\.\d+)?)?\s+(?:-u\s+)?(?:\S*\/)?server\.py\b|python(?:3(?:\.\d+)?)?\s+-m\s+http\.server\b|(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start|serve)\b|(?:npx|bunx)\s+(?:vite|next\s+dev|http-server)\b|uvicorn\b|gunicorn\b|flask\s+run\b)/i;
4
+ const READ_ONLY_COMMAND = /^\s*(?:pwd|ls|rg|grep|cat|head|tail|find|which|where|ps|pgrep|lsof|netstat|ss|git\s+(?:status|diff|log|show)|node\s+(?:-v|--version)|python(?:3(?:\.\d+)?)?\s+(?:-V|--version))\b/i;
5
+ const OPEN_COMMAND = /^\s*(?:open|xdg-open|start)\s+\S+/i;
6
+ const LOCAL_HEALTH_CHECK = /^\s*curl\s+(?:(?:-I|-s|-S|-f|--head|--silent|--show-error|--fail|--max-time\s+\d+)\s+)*https?:\/\/(?:localhost|127\.0\.0\.1):\d+(?:\/\S*)?\s*$/i;
7
+ const PORT_CLEANUP_COMMAND = /^\s*(?:pkill|kill|fuser)\b/i;
8
+
9
+ const MUTATION_TOOLS = new Set([
10
+ 'fs_write', 'fs_edit', 'fs_delete', 'fs_move',
11
+ 'multi_edit', 'MultiEdit', 'edit_file', 'write_to_file', 'delete_file',
12
+ 'create_skill', 'manage_local_dependencies'
13
+ ]);
14
+
15
+ export function isLaunchOnlyPrompt(prompt: string): boolean {
16
+ if (/\b(?:run|jalankan)\s+(?:the\s+)?(?:tests?|checks?|lint|benchmarks?|scripts?|commands?)\b/i.test(prompt)) return false;
17
+ return LAUNCH_VERBS.test(prompt) && !CHANGE_VERBS.test(prompt);
18
+ }
19
+
20
+ export function isServerLaunchCommand(command: string): boolean {
21
+ return SERVER_COMMAND.test(command.trim());
22
+ }
23
+
24
+ /** A launch-only request authorizes inspection, starting the app, and opening it. */
25
+ export function launchScopeError(tool: string, args: Record<string, unknown>): string | null {
26
+ if (MUTATION_TOOLS.has(tool)) {
27
+ return 'The user asked to open the existing project, not change its files or configuration.';
28
+ }
29
+
30
+ if (tool === 'sysRun' || tool === 'sysRunBg' || tool === 'terminal_persistent_shell') {
31
+ const command = String(args.command ?? args.input ?? '').trim();
32
+
33
+ if (OPEN_COMMAND.test(command) || isServerLaunchCommand(command) || LOCAL_HEALTH_CHECK.test(command) || PORT_CLEANUP_COMMAND.test(command)) {
34
+ return null;
35
+ }
36
+
37
+ if (/[;&|><`$()]/.test(command)) {
38
+ return 'A launch-only request does not authorize chained shell commands. Use one scoped command per tool call.';
39
+ }
40
+
41
+ if (READ_ONLY_COMMAND.test(command)) {
42
+ return null;
43
+ }
44
+
45
+ return 'The user asked to open the existing project. Use read-only inspection, a background server, or desktop.open; do not run unrelated commands.';
46
+ }
47
+
48
+ return null;
49
+ }
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { resolveSession, createSession, getSession, switchSession, saveSessionMessages } from './sessionStore.js';
3
+ import { resolveSession, createSession, getSession, switchSession, saveSessionMessages, forkSession } from './sessionStore.js';
4
4
  import os from 'os';
5
5
  import { causyneHome } from './utils/paths.js';
6
6
 
@@ -59,6 +59,26 @@ export class MemoryManager {
59
59
  return next;
60
60
  }
61
61
 
62
+ /**
63
+ * Fork current session into a new conversation without copying permissions.
64
+ *
65
+ * @param {string} [title]
66
+ * @param {number} [upToMessageIndex]
67
+ * @returns {import('./sessionStore.js').SessionRecord | null}
68
+ */
69
+ forkSession(title = null, upToMessageIndex = null) {
70
+ if (!this.session) return null;
71
+ const forked = forkSession(this.session.id, {
72
+ title: title || undefined,
73
+ upToMessageIndex: typeof upToMessageIndex === 'number' ? upToMessageIndex : undefined,
74
+ makeActive: true
75
+ });
76
+ if (forked) {
77
+ this.session = forked;
78
+ }
79
+ return forked;
80
+ }
81
+
62
82
  ensureMemoryDir() {
63
83
  if (!fs.existsSync(MEMORY_DIR)) {
64
84
  fs.mkdirSync(MEMORY_DIR, { recursive: true, mode: 0o700 });
@@ -77,7 +97,11 @@ export class MemoryManager {
77
97
 
78
98
 
79
99
  boundHistory(messages) {
80
- const persistable = messages.filter(m => m.role !== 'system');
100
+ const persistable = messages.filter(m => {
101
+ if (m.role !== 'system') return true;
102
+ if (typeof m.content === 'string' && m.content.startsWith('[Continuum')) return true;
103
+ return false;
104
+ });
81
105
  const bounded = [];
82
106
  let totalChars = 0;
83
107
 
@@ -134,6 +134,7 @@ export const MODEL_CATALOGUE = {
134
134
  'Claude Opus 5.5 (High)',
135
135
  'GPT-OSS 120B (Medium)'
136
136
  ],
137
+ 'Pi (Local Peer)': ['default'],
137
138
  'ACP (Peer Agents)': ['opencode', 'claude', 'codex', 'gemini', 'cursor', 'hermes', 'qwen', 'copilot', 'kimi', 'goose'],
138
139
  'OpenCode (ACP)': PEER_MODEL_CATALOGUE.opencode,
139
140
  'Claude Code (ACP)': PEER_MODEL_CATALOGUE.claude
@@ -167,6 +168,7 @@ export const DEFAULT_MODEL_BY_PROVIDER = {
167
168
  'acp/goose': 'goose',
168
169
  'acp/hermes': 'hermes',
169
170
  antigravity: 'Gemini 3.8 Flash (Low)',
171
+ pi: 'default',
170
172
  'openai-compatible': ''
171
173
  };
172
174