@causyne/agent 1.20.127 → 1.20.128

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 (69) hide show
  1. package/docs/THIRD_PARTY_NOTICES.md +36 -2
  2. package/package.json +3 -1
  3. package/src/agentLoop.js +59 -26
  4. package/src/agentLoop.ts +59 -24
  5. package/src/browser/causyneBrowser.js +31 -0
  6. package/src/browser/causyneBrowser.ts +32 -0
  7. package/src/commands.js +177 -13
  8. package/src/commands.ts +194 -13
  9. package/src/memory/episodicStore.js +40 -0
  10. package/src/memory/episodicStore.ts +46 -0
  11. package/src/memory.js +67 -0
  12. package/src/memory.ts +65 -0
  13. package/src/personalization.js +365 -0
  14. package/src/personalization.ts +471 -0
  15. package/src/projectInstructions.js +30 -10
  16. package/src/projectInstructions.ts +31 -12
  17. package/src/providers/acp.js +3 -2
  18. package/src/providers/acp.ts +3 -2
  19. package/src/providers/antigravity.js +2 -0
  20. package/src/providers/antigravity.ts +2 -0
  21. package/src/tools/memoryWrite.js +15 -1
  22. package/src/tools/memoryWrite.ts +16 -1
  23. package/src/tools/osSandbox.js +1 -1
  24. package/src/tools/osSandbox.ts +1 -1
  25. package/src/tools/ptyTerminal.js +17 -5
  26. package/src/tools/ptyTerminal.ts +19 -5
  27. package/src/web/client/browserPanel.js +234 -31
  28. package/src/web/client/browserPanel.ts +240 -31
  29. package/src/web/client/chatStream.js +19 -7
  30. package/src/web/client/chatStream.ts +17 -9
  31. package/src/web/client/cliPanel.js +3 -3
  32. package/src/web/client/cliPanel.ts +3 -3
  33. package/src/web/client/dom.js +53 -2
  34. package/src/web/client/dom.ts +54 -3
  35. package/src/web/client/filesAndCanvas.js +3 -1
  36. package/src/web/client/filesAndCanvas.ts +3 -1
  37. package/src/web/client/main.js +28 -13
  38. package/src/web/client/main.ts +35 -12
  39. package/src/web/client/settingsModal.js +641 -8
  40. package/src/web/client/settingsModal.ts +791 -8
  41. package/src/web/client/state.js +31 -1
  42. package/src/web/client/state.ts +27 -1
  43. package/src/web/client/studioLayout.js +39 -4
  44. package/src/web/client/studioLayout.ts +47 -4
  45. package/src/web/client/studioShell.js +370 -37
  46. package/src/web/client/studioShell.ts +368 -36
  47. package/src/web/client/terminalPanel.js +378 -129
  48. package/src/web/client/terminalPanel.ts +394 -107
  49. package/src/web/client/terminalTheme.js +249 -0
  50. package/src/web/client/terminalTheme.ts +258 -0
  51. package/src/web/client/types.ts +3 -0
  52. package/src/web/client/validators.js +51 -10
  53. package/src/web/client/validators.ts +54 -10
  54. package/src/web/server/routesBrowser.js +64 -10
  55. package/src/web/server/routesBrowser.ts +62 -13
  56. package/src/web/server/routesSettings.js +344 -0
  57. package/src/web/server/routesSettings.ts +397 -0
  58. package/src/web/server/staticAssets.js +24 -0
  59. package/src/web/server/staticAssets.ts +25 -0
  60. package/src/web/skybridgeServer.js +3 -0
  61. package/src/web/skybridgeServer.ts +2 -0
  62. package/src/web/skybridgeUi.js +5 -1
  63. package/src/web/skybridgeUi.ts +8 -1
  64. package/src/web/styles/overlays.css +499 -0
  65. package/src/web/styles/studio.css +274 -46
  66. package/src/web/ui/modalsTemplate.js +320 -71
  67. package/src/web/ui/modalsTemplate.ts +320 -71
  68. package/src/web/ui/studioTemplate.js +19 -21
  69. package/src/web/ui/studioTemplate.ts +19 -21
package/src/commands.js CHANGED
@@ -58,6 +58,7 @@ import { collectWorkingTreeDiff, renderDiffReview } from './diffReview.js';
58
58
  import { fetchFailedCiLogs, formatPrStatusReport, inspectPrStatus, preparePrDraft } from './prWorkflow.js';
59
59
  import { formatEvalScorecard, runCodingEvalSuite } from './benchmarks/codingEval.js';
60
60
  import { formatProjectRulesReport } from './projectInstructions.js';
61
+ import { deleteCausyneMemories, readPersonalizationOverview, saveMemoryPreferences, savePersonalizationInstructions } from './personalization.js';
61
62
  import { buildRepoMap } from './codebase/repoMap.js';
62
63
  import { backgroundTaskManager } from './backgroundTasks.js';
63
64
  import { resolveModelVariants, matchVariantOption, normalizeVariantToken } from './modelVariants.js';
@@ -1237,32 +1238,66 @@ export const COMMANDS = [
1237
1238
  },
1238
1239
  {
1239
1240
  name: 'cortex',
1240
- aliases: ['memory'],
1241
+ aliases: ['memory', 'memories'],
1241
1242
  scope: 'local',
1242
- usage: '/cortex [status | list | search <query> | on | off | forget <id|--workspace>]',
1243
- description: 'Inspect, search, toggle, or clear persistent Cortex memory',
1243
+ usage: '/cortex [status | list | search <query> | on | off | tool-assisted on|off | forget <id|--workspace|all>]',
1244
+ description: 'Inspect, search, toggle, or clear Causyne & Cortex persistent memory',
1244
1245
  dialogTitle: 'Cortex Memory',
1245
1246
  complete: () => [
1246
- { value: 'status', label: 'status', description: 'show Cortex memory counts and engine status' },
1247
+ { value: 'status', label: 'status', description: 'show memory controls, counts, and Cortex engine status' },
1247
1248
  { value: 'list', label: 'list', description: 'list recent memories stored for this workspace' },
1248
1249
  { value: 'search', label: 'search', description: 'semantic search across stored memories' },
1249
- { value: 'on', label: 'on', description: 'enable persistent Cortex memory recall' },
1250
- { value: 'off', label: 'off', description: 'disable persistent Cortex memory recall' },
1251
- { value: 'forget --workspace', label: 'forget --workspace', description: 'clear memories for the current workspace' }
1250
+ { value: 'on', label: 'on', description: 'enable Causyne memories for this project (add "global" for all)' },
1251
+ { value: 'off', label: 'off', description: 'disable Causyne memories for this project (add "global" for all)' },
1252
+ { value: 'tool-assisted on', label: 'tool-assisted on', description: 'allow memories from MCP/web tool-assisted chats' },
1253
+ { value: 'tool-assisted off', label: 'tool-assisted off', description: 'block memories from MCP/web tool-assisted chats' },
1254
+ { value: 'forget --workspace', label: 'forget --workspace', description: 'clear memories for the current workspace' },
1255
+ { value: 'forget all', label: 'forget all', description: 'clear all stored Causyne memories on this device' }
1252
1256
  ],
1253
1257
  run: async (argv, ctx = {}) => {
1254
1258
  const sub = String(argv[0] || 'status').trim().toLowerCase();
1255
1259
  const workspace = ctx.loop?.workspaceRoot || process.cwd();
1260
+ const invalidateLoop = () => {
1261
+ if (ctx.loop && 'staticContext' in ctx.loop) {
1262
+ ctx.loop.staticContext = null;
1263
+ }
1264
+ };
1256
1265
  if (sub === 'on' || sub === 'enable' || sub === 'off' || sub === 'disable') {
1257
1266
  const enabled = sub === 'on' || sub === 'enable';
1258
- const config = loadConfig();
1259
- const prev = config.cortex && typeof config.cortex === 'object' ? config.cortex : {};
1260
- config.cortex = { ...prev, enabled };
1261
- saveConfig(config);
1267
+ const explicitScope = String(argv[1] || '').trim().toLowerCase();
1268
+ const scopeArg = explicitScope === 'global'
1269
+ ? 'global'
1270
+ : explicitScope === 'project'
1271
+ ? 'project'
1272
+ : (ctx.loop?.workspaceRoot ? 'project' : 'global');
1273
+ const policy = saveMemoryPreferences(workspace, scopeArg, { enabled });
1274
+ if (scopeArg === 'global') {
1275
+ const config = loadConfig();
1276
+ const prev = config.cortex && typeof config.cortex === 'object' ? config.cortex : {};
1277
+ config.cortex = { ...prev, enabled };
1278
+ saveConfig(config);
1279
+ }
1262
1280
  if (ctx.loop) {
1263
1281
  ctx.loop.config = loadConfig();
1264
1282
  }
1265
- return ok(`Cortex persistent memory is now ${enabled ? 'ENABLED' : 'DISABLED'}.`, { effect: 'inline' });
1283
+ invalidateLoop();
1284
+ return ok(`Causyne & Cortex memory (${scopeArg}) is now ${policy.enabled ? 'ENABLED' : 'DISABLED'}.`, { effect: 'inline' });
1285
+ }
1286
+ if (sub === 'tool-assisted' || sub === 'tool-memory') {
1287
+ const toggle = String(argv[1] || '').trim().toLowerCase();
1288
+ const scopeArg = String(argv[2] || 'project').trim().toLowerCase() === 'global' ? 'global' : 'project';
1289
+ if (toggle !== 'on' && toggle !== 'off') {
1290
+ return fail('Usage: /memory tool-assisted on|off [project|global]');
1291
+ }
1292
+ const policy = saveMemoryPreferences(workspace, scopeArg, { allowToolAssisted: toggle === 'on' });
1293
+ invalidateLoop();
1294
+ return ok(`Tool-assisted chat memories (${scopeArg}) are now ${policy.allowToolAssisted ? 'ALLOWED' : 'BLOCKED'}.`, { effect: 'inline' });
1295
+ }
1296
+ if (sub === 'forget' && (String(argv[1] || '').trim().toLowerCase() === 'all' || String(argv[1] || '').trim().toLowerCase() === 'project')) {
1297
+ const delScope = String(argv[1] || '').trim().toLowerCase() === 'all' ? 'all' : 'project';
1298
+ const deleted = deleteCausyneMemories(workspace, delScope);
1299
+ invalidateLoop();
1300
+ return ok(`Deleted Causyne memories (${delScope}): ${deleted.factsRemoved} facts, ${deleted.observationsRemoved} observations, ${deleted.summariesRemoved} summaries removed.`);
1266
1301
  }
1267
1302
  const config = loadConfig();
1268
1303
  const enabled = config.cortex?.enabled !== false;
@@ -3599,13 +3634,142 @@ export const COMMANDS = [
3599
3634
  name: 'rules',
3600
3635
  scope: 'local',
3601
3636
  usage: '/rules',
3602
- description: 'Show hierarchical project instructions loaded from CAUSYNE.md, AGENTS.md, CLAUDE.md, and .causyne/rules/',
3637
+ description: 'Show hierarchical project instructions loaded from .causyne/personalization.md, CAUSYNE.md, AGENTS.md, CLAUDE.md, and .causyne/rules/',
3603
3638
  dialogTitle: 'Project Rules',
3604
3639
  run: async (_argv, ctx = {}) => {
3605
3640
  const ws = ctx.loop?.workspaceRoot || process.cwd();
3606
3641
  return ok(formatProjectRulesReport(ws));
3607
3642
  }
3608
3643
  },
3644
+ {
3645
+ name: 'personalization',
3646
+ aliases: ['persona', 'instructions'],
3647
+ scope: 'local',
3648
+ usage: '/personalization [show | set <text> | append <text> | global <text> | clear [project|global] | memory on|off [global] | tool-memory on|off [global] | forget [project|all]]',
3649
+ description: 'Manage per-project personalization instructions (.causyne/personalization.md), global instructions, and Causyne memory controls',
3650
+ dialogTitle: 'Personalization',
3651
+ complete: () => [
3652
+ { value: 'show', label: 'show', description: 'inspect project & global personalization and memory controls' },
3653
+ { value: 'set ', label: 'set <text>', description: 'save per-project personalization (.causyne/personalization.md)' },
3654
+ { value: 'append ', label: 'append <text>', description: 'append a directive to this project personalization' },
3655
+ { value: 'global ', label: 'global <text>', description: 'save global instructions (~/.causyne/CAUSYNE.md)' },
3656
+ { value: 'clear project', label: 'clear project', description: 'clear this project personalization' },
3657
+ { value: 'clear global', label: 'clear global', description: 'clear global instructions' },
3658
+ { value: 'memory on', label: 'memory on', description: 'enable Causyne memories for this project' },
3659
+ { value: 'memory off', label: 'memory off', description: 'disable Causyne memories for this project' },
3660
+ { value: 'tool-memory on', label: 'tool-memory on', description: 'allow memories from MCP/web tool-assisted chats' },
3661
+ { value: 'tool-memory off', label: 'tool-memory off', description: 'disable memories from MCP/web tool-assisted chats' },
3662
+ { value: 'forget project', label: 'forget project', description: 'delete stored memories for this project' },
3663
+ { value: 'forget all', label: 'forget all', description: 'delete all Causyne memories on this device' }
3664
+ ],
3665
+ run: async (argv, ctx = {}) => {
3666
+ const ws = ctx.loop?.workspaceRoot || process.cwd();
3667
+ const sub = String(argv[0] || 'show').toLowerCase();
3668
+ const invalidateLoop = () => {
3669
+ if (ctx.loop && 'staticContext' in ctx.loop) {
3670
+ ctx.loop.staticContext = null;
3671
+ }
3672
+ };
3673
+ const renderOverview = () => {
3674
+ const info = readPersonalizationOverview(ws);
3675
+ const lines = [
3676
+ 'Causyne Personalization & Memory',
3677
+ ` Workspace : ${safeDisplay(info.workspaceRoot)}`,
3678
+ ` Project file : ${info.project.displayPath} (${info.project.exists ? `${info.project.bytes} bytes` : 'not set'})`,
3679
+ ` Global file : ${info.global.displayPath} (${info.global.exists ? `${info.global.bytes} bytes` : 'not set'})`,
3680
+ ` Memories : ${info.memory.enabled ? 'enabled' : 'disabled'} (source: ${info.memory.source})`,
3681
+ ` Tool-assisted mem : ${info.memory.allowToolAssisted ? 'allowed' : 'blocked'} (MCP/web chats)`,
3682
+ ` Stored memories : ${info.memoryStats.projectFacts} project facts (${info.memoryStats.totalFacts} total), ${info.memoryStats.projectObservations} project observations (${info.memoryStats.totalObservations} total)`
3683
+ ];
3684
+ if (info.project.content.trim()) {
3685
+ lines.push('', 'Project Personalization (.causyne/personalization.md):', info.project.content.trim());
3686
+ }
3687
+ if (info.global.content.trim()) {
3688
+ lines.push('', 'Global Instructions (~/.causyne/CAUSYNE.md):', info.global.content.trim());
3689
+ }
3690
+ if (info.activeRules.length > 0) {
3691
+ lines.push('', `Active Instruction Files (${info.activeRules.length}):`);
3692
+ for (const r of info.activeRules) {
3693
+ lines.push(` • [${r.scope}] ${safeDisplay(r.label)} (${r.bytes} bytes)`);
3694
+ }
3695
+ }
3696
+ lines.push('', 'Usage: /personalization set <text> | append <text> | global <text> | clear [project|global] | memory on|off [global] | tool-memory on|off [global] | forget [project|all]');
3697
+ return lines.join('\n');
3698
+ };
3699
+ try {
3700
+ if (sub === 'show' || sub === 'status') {
3701
+ return ok(renderOverview());
3702
+ }
3703
+ if (sub === 'set') {
3704
+ const text = argv.slice(1).join(' ').trim();
3705
+ if (!text)
3706
+ return fail('Usage: /personalization set <project instructions>');
3707
+ const doc = savePersonalizationInstructions(ws, 'project', text);
3708
+ invalidateLoop();
3709
+ return ok(`Saved project personalization to ${doc.displayPath} (${doc.bytes} bytes). Active immediately for this workspace.`);
3710
+ }
3711
+ if (sub === 'append') {
3712
+ const text = argv.slice(1).join(' ').trim();
3713
+ if (!text)
3714
+ return fail('Usage: /personalization append <additional project instruction>');
3715
+ const existing = readPersonalizationOverview(ws).project.content.trim();
3716
+ const combined = existing ? `${existing}\n\n${text}` : text;
3717
+ const doc = savePersonalizationInstructions(ws, 'project', combined);
3718
+ invalidateLoop();
3719
+ return ok(`Updated project personalization at ${doc.displayPath} (${doc.bytes} bytes). Active immediately for this workspace.`);
3720
+ }
3721
+ if (sub === 'global') {
3722
+ const text = argv.slice(1).join(' ').trim();
3723
+ if (!text)
3724
+ return fail('Usage: /personalization global <global instructions>');
3725
+ const doc = savePersonalizationInstructions(ws, 'global', text);
3726
+ invalidateLoop();
3727
+ return ok(`Saved global instructions to ${doc.displayPath} (${doc.bytes} bytes).`);
3728
+ }
3729
+ if (sub === 'clear') {
3730
+ const scopeArg = String(argv[1] || 'project').toLowerCase();
3731
+ if (scopeArg !== 'project' && scopeArg !== 'global') {
3732
+ return fail('Usage: /personalization clear [project|global]');
3733
+ }
3734
+ savePersonalizationInstructions(ws, scopeArg, '');
3735
+ invalidateLoop();
3736
+ return ok(`Cleared ${scopeArg} personalization instructions.`);
3737
+ }
3738
+ if (sub === 'memory') {
3739
+ const toggle = String(argv[1] || '').toLowerCase();
3740
+ const scopeArg = String(argv[2] || 'project').toLowerCase() === 'global' ? 'global' : 'project';
3741
+ if (toggle !== 'on' && toggle !== 'off' && toggle !== 'inherit') {
3742
+ return fail('Usage: /personalization memory on|off|inherit [project|global]');
3743
+ }
3744
+ const value = toggle === 'inherit' ? null : toggle === 'on';
3745
+ const policy = saveMemoryPreferences(ws, scopeArg, { enabled: value });
3746
+ invalidateLoop();
3747
+ return ok(`Causyne memories (${scopeArg}): ${policy.enabled ? 'enabled' : 'disabled'} (effective source: ${policy.source}).`);
3748
+ }
3749
+ if (sub === 'tool-memory' || sub === 'tool-assisted') {
3750
+ const toggle = String(argv[1] || '').toLowerCase();
3751
+ const scopeArg = String(argv[2] || 'project').toLowerCase() === 'global' ? 'global' : 'project';
3752
+ if (toggle !== 'on' && toggle !== 'off' && toggle !== 'inherit') {
3753
+ return fail('Usage: /personalization tool-memory on|off|inherit [project|global]');
3754
+ }
3755
+ const value = toggle === 'inherit' ? null : toggle === 'on';
3756
+ const policy = saveMemoryPreferences(ws, scopeArg, { allowToolAssisted: value });
3757
+ invalidateLoop();
3758
+ return ok(`Tool-assisted chat memories (${scopeArg}): ${policy.allowToolAssisted ? 'allowed' : 'blocked'} (effective source: ${policy.source}).`);
3759
+ }
3760
+ if (sub === 'forget' || sub === 'delete') {
3761
+ const scopeArg = String(argv[1] || 'project').toLowerCase() === 'all' ? 'all' : 'project';
3762
+ const deleted = deleteCausyneMemories(ws, scopeArg);
3763
+ invalidateLoop();
3764
+ return ok(`Deleted Causyne memories (${scopeArg}): ${deleted.factsRemoved} facts, ${deleted.observationsRemoved} observations, ${deleted.summariesRemoved} summaries removed.`);
3765
+ }
3766
+ return fail(`Unknown /personalization action "${safeDisplay(sub)}". Try: show, set, append, global, clear, memory, tool-memory, forget.`);
3767
+ }
3768
+ catch (err) {
3769
+ return fail(safeDisplay(errMsg(err)));
3770
+ }
3771
+ }
3772
+ },
3609
3773
  {
3610
3774
  name: 'map',
3611
3775
  aliases: ['repomap'],
package/src/commands.ts CHANGED
@@ -104,6 +104,12 @@ import { collectWorkingTreeDiff, renderDiffReview } from './diffReview.js';
104
104
  import { fetchFailedCiLogs, formatPrStatusReport, inspectPrStatus, preparePrDraft } from './prWorkflow.js';
105
105
  import { formatEvalScorecard, runCodingEvalSuite } from './benchmarks/codingEval.js';
106
106
  import { formatProjectRulesReport } from './projectInstructions.js';
107
+ import {
108
+ deleteCausyneMemories,
109
+ readPersonalizationOverview,
110
+ saveMemoryPreferences,
111
+ savePersonalizationInstructions
112
+ } from './personalization.js';
107
113
  import { buildRepoMap } from './codebase/repoMap.js';
108
114
  import { backgroundTaskManager } from './backgroundTasks.js';
109
115
  import {
@@ -1400,38 +1406,79 @@ export const COMMANDS: SlashCommandDefinition[] = [
1400
1406
 
1401
1407
  {
1402
1408
  name: 'cortex',
1403
- aliases: ['memory'],
1409
+ aliases: ['memory', 'memories'],
1404
1410
  scope: 'local',
1405
- usage: '/cortex [status | list | search <query> | on | off | forget <id|--workspace>]',
1406
- description: 'Inspect, search, toggle, or clear persistent Cortex memory',
1411
+ usage: '/cortex [status | list | search <query> | on | off | tool-assisted on|off | forget <id|--workspace|all>]',
1412
+ description: 'Inspect, search, toggle, or clear Causyne & Cortex persistent memory',
1407
1413
  dialogTitle: 'Cortex Memory',
1408
1414
  complete: () => [
1409
- { value: 'status', label: 'status', description: 'show Cortex memory counts and engine status' },
1415
+ { value: 'status', label: 'status', description: 'show memory controls, counts, and Cortex engine status' },
1410
1416
  { value: 'list', label: 'list', description: 'list recent memories stored for this workspace' },
1411
1417
  { value: 'search', label: 'search', description: 'semantic search across stored memories' },
1412
- { value: 'on', label: 'on', description: 'enable persistent Cortex memory recall' },
1413
- { value: 'off', label: 'off', description: 'disable persistent Cortex memory recall' },
1414
- { value: 'forget --workspace', label: 'forget --workspace', description: 'clear memories for the current workspace' }
1418
+ { value: 'on', label: 'on', description: 'enable Causyne memories for this project (add "global" for all)' },
1419
+ { value: 'off', label: 'off', description: 'disable Causyne memories for this project (add "global" for all)' },
1420
+ { value: 'tool-assisted on', label: 'tool-assisted on', description: 'allow memories from MCP/web tool-assisted chats' },
1421
+ { value: 'tool-assisted off', label: 'tool-assisted off', description: 'block memories from MCP/web tool-assisted chats' },
1422
+ { value: 'forget --workspace', label: 'forget --workspace', description: 'clear memories for the current workspace' },
1423
+ { value: 'forget all', label: 'forget all', description: 'clear all stored Causyne memories on this device' }
1415
1424
  ],
1416
1425
  run: async (argv, ctx = {}) => {
1417
1426
  const sub = String(argv[0] || 'status').trim().toLowerCase();
1418
1427
  const workspace = ctx.loop?.workspaceRoot || process.cwd();
1428
+ const invalidateLoop = (): void => {
1429
+ if (ctx.loop && 'staticContext' in ctx.loop) {
1430
+ (ctx.loop as any).staticContext = null;
1431
+ }
1432
+ };
1419
1433
 
1420
1434
  if (sub === 'on' || sub === 'enable' || sub === 'off' || sub === 'disable') {
1421
1435
  const enabled = sub === 'on' || sub === 'enable';
1422
- const config = loadConfig();
1423
- const prev = config.cortex && typeof config.cortex === 'object' ? config.cortex : {};
1424
- config.cortex = { ...prev, enabled };
1425
- saveConfig(config);
1436
+ const explicitScope = String(argv[1] || '').trim().toLowerCase();
1437
+ const scopeArg: 'project' | 'global' = explicitScope === 'global'
1438
+ ? 'global'
1439
+ : explicitScope === 'project'
1440
+ ? 'project'
1441
+ : (ctx.loop?.workspaceRoot ? 'project' : 'global');
1442
+ const policy = saveMemoryPreferences(workspace, scopeArg, { enabled });
1443
+ if (scopeArg === 'global') {
1444
+ const config = loadConfig();
1445
+ const prev = config.cortex && typeof config.cortex === 'object' ? config.cortex : {};
1446
+ config.cortex = { ...prev, enabled };
1447
+ saveConfig(config);
1448
+ }
1426
1449
  if (ctx.loop) {
1427
1450
  ctx.loop.config = loadConfig();
1428
1451
  }
1452
+ invalidateLoop();
1453
+ return ok(
1454
+ `Causyne & Cortex memory (${scopeArg}) is now ${policy.enabled ? 'ENABLED' : 'DISABLED'}.`,
1455
+ { effect: 'inline' }
1456
+ );
1457
+ }
1458
+
1459
+ if (sub === 'tool-assisted' || sub === 'tool-memory') {
1460
+ const toggle = String(argv[1] || '').trim().toLowerCase();
1461
+ const scopeArg = String(argv[2] || 'project').trim().toLowerCase() === 'global' ? 'global' : 'project';
1462
+ if (toggle !== 'on' && toggle !== 'off') {
1463
+ return fail('Usage: /memory tool-assisted on|off [project|global]');
1464
+ }
1465
+ const policy = saveMemoryPreferences(workspace, scopeArg, { allowToolAssisted: toggle === 'on' });
1466
+ invalidateLoop();
1429
1467
  return ok(
1430
- `Cortex persistent memory is now ${enabled ? 'ENABLED' : 'DISABLED'}.`,
1468
+ `Tool-assisted chat memories (${scopeArg}) are now ${policy.allowToolAssisted ? 'ALLOWED' : 'BLOCKED'}.`,
1431
1469
  { effect: 'inline' }
1432
1470
  );
1433
1471
  }
1434
1472
 
1473
+ if (sub === 'forget' && (String(argv[1] || '').trim().toLowerCase() === 'all' || String(argv[1] || '').trim().toLowerCase() === 'project')) {
1474
+ const delScope = String(argv[1] || '').trim().toLowerCase() === 'all' ? 'all' : 'project';
1475
+ const deleted = deleteCausyneMemories(workspace, delScope);
1476
+ invalidateLoop();
1477
+ return ok(
1478
+ `Deleted Causyne memories (${delScope}): ${deleted.factsRemoved} facts, ${deleted.observationsRemoved} observations, ${deleted.summariesRemoved} summaries removed.`
1479
+ );
1480
+ }
1481
+
1435
1482
  const config = loadConfig();
1436
1483
  const enabled = config.cortex?.enabled !== false;
1437
1484
 
@@ -3843,7 +3890,7 @@ export const COMMANDS: SlashCommandDefinition[] = [
3843
3890
  name: 'rules',
3844
3891
  scope: 'local',
3845
3892
  usage: '/rules',
3846
- description: 'Show hierarchical project instructions loaded from CAUSYNE.md, AGENTS.md, CLAUDE.md, and .causyne/rules/',
3893
+ description: 'Show hierarchical project instructions loaded from .causyne/personalization.md, CAUSYNE.md, AGENTS.md, CLAUDE.md, and .causyne/rules/',
3847
3894
  dialogTitle: 'Project Rules',
3848
3895
  run: async (_argv, ctx = {}) => {
3849
3896
  const ws = ctx.loop?.workspaceRoot || process.cwd();
@@ -3851,6 +3898,140 @@ export const COMMANDS: SlashCommandDefinition[] = [
3851
3898
  }
3852
3899
  },
3853
3900
 
3901
+ {
3902
+ name: 'personalization',
3903
+ aliases: ['persona', 'instructions'],
3904
+ scope: 'local',
3905
+ usage: '/personalization [show | set <text> | append <text> | global <text> | clear [project|global] | memory on|off [global] | tool-memory on|off [global] | forget [project|all]]',
3906
+ description: 'Manage per-project personalization instructions (.causyne/personalization.md), global instructions, and Causyne memory controls',
3907
+ dialogTitle: 'Personalization',
3908
+ complete: () => [
3909
+ { value: 'show', label: 'show', description: 'inspect project & global personalization and memory controls' },
3910
+ { value: 'set ', label: 'set <text>', description: 'save per-project personalization (.causyne/personalization.md)' },
3911
+ { value: 'append ', label: 'append <text>', description: 'append a directive to this project personalization' },
3912
+ { value: 'global ', label: 'global <text>', description: 'save global instructions (~/.causyne/CAUSYNE.md)' },
3913
+ { value: 'clear project', label: 'clear project', description: 'clear this project personalization' },
3914
+ { value: 'clear global', label: 'clear global', description: 'clear global instructions' },
3915
+ { value: 'memory on', label: 'memory on', description: 'enable Causyne memories for this project' },
3916
+ { value: 'memory off', label: 'memory off', description: 'disable Causyne memories for this project' },
3917
+ { value: 'tool-memory on', label: 'tool-memory on', description: 'allow memories from MCP/web tool-assisted chats' },
3918
+ { value: 'tool-memory off', label: 'tool-memory off', description: 'disable memories from MCP/web tool-assisted chats' },
3919
+ { value: 'forget project', label: 'forget project', description: 'delete stored memories for this project' },
3920
+ { value: 'forget all', label: 'forget all', description: 'delete all Causyne memories on this device' }
3921
+ ],
3922
+ run: async (argv, ctx = {}) => {
3923
+ const ws = ctx.loop?.workspaceRoot || process.cwd();
3924
+ const sub = String(argv[0] || 'show').toLowerCase();
3925
+
3926
+ const invalidateLoop = (): void => {
3927
+ if (ctx.loop && 'staticContext' in ctx.loop) {
3928
+ (ctx.loop as any).staticContext = null;
3929
+ }
3930
+ };
3931
+
3932
+ const renderOverview = (): string => {
3933
+ const info = readPersonalizationOverview(ws);
3934
+ const lines = [
3935
+ 'Causyne Personalization & Memory',
3936
+ ` Workspace : ${safeDisplay(info.workspaceRoot)}`,
3937
+ ` Project file : ${info.project.displayPath} (${info.project.exists ? `${info.project.bytes} bytes` : 'not set'})`,
3938
+ ` Global file : ${info.global.displayPath} (${info.global.exists ? `${info.global.bytes} bytes` : 'not set'})`,
3939
+ ` Memories : ${info.memory.enabled ? 'enabled' : 'disabled'} (source: ${info.memory.source})`,
3940
+ ` Tool-assisted mem : ${info.memory.allowToolAssisted ? 'allowed' : 'blocked'} (MCP/web chats)`,
3941
+ ` Stored memories : ${info.memoryStats.projectFacts} project facts (${info.memoryStats.totalFacts} total), ${info.memoryStats.projectObservations} project observations (${info.memoryStats.totalObservations} total)`
3942
+ ];
3943
+ if (info.project.content.trim()) {
3944
+ lines.push('', 'Project Personalization (.causyne/personalization.md):', info.project.content.trim());
3945
+ }
3946
+ if (info.global.content.trim()) {
3947
+ lines.push('', 'Global Instructions (~/.causyne/CAUSYNE.md):', info.global.content.trim());
3948
+ }
3949
+ if (info.activeRules.length > 0) {
3950
+ lines.push('', `Active Instruction Files (${info.activeRules.length}):`);
3951
+ for (const r of info.activeRules) {
3952
+ lines.push(` • [${r.scope}] ${safeDisplay(r.label)} (${r.bytes} bytes)`);
3953
+ }
3954
+ }
3955
+ lines.push(
3956
+ '',
3957
+ 'Usage: /personalization set <text> | append <text> | global <text> | clear [project|global] | memory on|off [global] | tool-memory on|off [global] | forget [project|all]'
3958
+ );
3959
+ return lines.join('\n');
3960
+ };
3961
+
3962
+ try {
3963
+ if (sub === 'show' || sub === 'status') {
3964
+ return ok(renderOverview());
3965
+ }
3966
+ if (sub === 'set') {
3967
+ const text = argv.slice(1).join(' ').trim();
3968
+ if (!text) return fail('Usage: /personalization set <project instructions>');
3969
+ const doc = savePersonalizationInstructions(ws, 'project', text);
3970
+ invalidateLoop();
3971
+ return ok(`Saved project personalization to ${doc.displayPath} (${doc.bytes} bytes). Active immediately for this workspace.`);
3972
+ }
3973
+ if (sub === 'append') {
3974
+ const text = argv.slice(1).join(' ').trim();
3975
+ if (!text) return fail('Usage: /personalization append <additional project instruction>');
3976
+ const existing = readPersonalizationOverview(ws).project.content.trim();
3977
+ const combined = existing ? `${existing}\n\n${text}` : text;
3978
+ const doc = savePersonalizationInstructions(ws, 'project', combined);
3979
+ invalidateLoop();
3980
+ return ok(`Updated project personalization at ${doc.displayPath} (${doc.bytes} bytes). Active immediately for this workspace.`);
3981
+ }
3982
+ if (sub === 'global') {
3983
+ const text = argv.slice(1).join(' ').trim();
3984
+ if (!text) return fail('Usage: /personalization global <global instructions>');
3985
+ const doc = savePersonalizationInstructions(ws, 'global', text);
3986
+ invalidateLoop();
3987
+ return ok(`Saved global instructions to ${doc.displayPath} (${doc.bytes} bytes).`);
3988
+ }
3989
+ if (sub === 'clear') {
3990
+ const scopeArg = String(argv[1] || 'project').toLowerCase();
3991
+ if (scopeArg !== 'project' && scopeArg !== 'global') {
3992
+ return fail('Usage: /personalization clear [project|global]');
3993
+ }
3994
+ savePersonalizationInstructions(ws, scopeArg, '');
3995
+ invalidateLoop();
3996
+ return ok(`Cleared ${scopeArg} personalization instructions.`);
3997
+ }
3998
+ if (sub === 'memory') {
3999
+ const toggle = String(argv[1] || '').toLowerCase();
4000
+ const scopeArg = String(argv[2] || 'project').toLowerCase() === 'global' ? 'global' : 'project';
4001
+ if (toggle !== 'on' && toggle !== 'off' && toggle !== 'inherit') {
4002
+ return fail('Usage: /personalization memory on|off|inherit [project|global]');
4003
+ }
4004
+ const value = toggle === 'inherit' ? null : toggle === 'on';
4005
+ const policy = saveMemoryPreferences(ws, scopeArg, { enabled: value });
4006
+ invalidateLoop();
4007
+ return ok(`Causyne memories (${scopeArg}): ${policy.enabled ? 'enabled' : 'disabled'} (effective source: ${policy.source}).`);
4008
+ }
4009
+ if (sub === 'tool-memory' || sub === 'tool-assisted') {
4010
+ const toggle = String(argv[1] || '').toLowerCase();
4011
+ const scopeArg = String(argv[2] || 'project').toLowerCase() === 'global' ? 'global' : 'project';
4012
+ if (toggle !== 'on' && toggle !== 'off' && toggle !== 'inherit') {
4013
+ return fail('Usage: /personalization tool-memory on|off|inherit [project|global]');
4014
+ }
4015
+ const value = toggle === 'inherit' ? null : toggle === 'on';
4016
+ const policy = saveMemoryPreferences(ws, scopeArg, { allowToolAssisted: value });
4017
+ invalidateLoop();
4018
+ return ok(`Tool-assisted chat memories (${scopeArg}): ${policy.allowToolAssisted ? 'allowed' : 'blocked'} (effective source: ${policy.source}).`);
4019
+ }
4020
+ if (sub === 'forget' || sub === 'delete') {
4021
+ const scopeArg = String(argv[1] || 'project').toLowerCase() === 'all' ? 'all' : 'project';
4022
+ const deleted = deleteCausyneMemories(ws, scopeArg);
4023
+ invalidateLoop();
4024
+ return ok(
4025
+ `Deleted Causyne memories (${scopeArg}): ${deleted.factsRemoved} facts, ${deleted.observationsRemoved} observations, ${deleted.summariesRemoved} summaries removed.`
4026
+ );
4027
+ }
4028
+ return fail(`Unknown /personalization action "${safeDisplay(sub)}". Try: show, set, append, global, clear, memory, tool-memory, forget.`);
4029
+ } catch (err) {
4030
+ return fail(safeDisplay(errMsg(err)));
4031
+ }
4032
+ }
4033
+ },
4034
+
3854
4035
  {
3855
4036
  name: 'map',
3856
4037
  aliases: ['repomap'],
@@ -642,17 +642,57 @@ export class EpisodicMemoryStore {
642
642
  return 0;
643
643
  }
644
644
  }
645
+ clearProject(workspace) {
646
+ const store = this.ensureLoaded();
647
+ const project = projectFromWorkspace(workspace);
648
+ const canonical = (p) => {
649
+ const r = path.resolve(p);
650
+ try {
651
+ const real = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native(r) : fs.realpathSync(r);
652
+ return process.platform === 'win32' ? real.toLowerCase() : real;
653
+ }
654
+ catch {
655
+ return process.platform === 'win32' ? r.toLowerCase() : r;
656
+ }
657
+ };
658
+ const targetWs = canonical(workspace);
659
+ const beforeObs = store.observations.length;
660
+ const beforeSum = store.summaries.length;
661
+ store.observations = store.observations.filter((o) => o.project !== project && (!o.workspace || canonical(o.workspace) !== targetWs));
662
+ store.summaries = store.summaries.filter((s) => s.project !== project && (!s.workspace || canonical(s.workspace) !== targetWs));
663
+ const observationsRemoved = beforeObs - store.observations.length;
664
+ const summariesRemoved = beforeSum - store.summaries.length;
665
+ if (observationsRemoved > 0 || summariesRemoved > 0) {
666
+ this.save();
667
+ }
668
+ return { observationsRemoved, summariesRemoved };
669
+ }
670
+ clearAll() {
671
+ const store = this.ensureLoaded();
672
+ const observationsRemoved = store.observations.length;
673
+ const summariesRemoved = store.summaries.length;
674
+ store.observations = [];
675
+ store.summaries = [];
676
+ if (observationsRemoved > 0 || summariesRemoved > 0) {
677
+ this.save();
678
+ }
679
+ return { observationsRemoved, summariesRemoved };
680
+ }
645
681
  getStats(workspace) {
646
682
  const store = this.ensureLoaded();
647
683
  const project = workspace ? projectFromWorkspace(workspace) : '';
648
684
  const projectObservations = project
649
685
  ? store.observations.filter((o) => o.project === project).length
650
686
  : store.observations.length;
687
+ const projectSummaries = project
688
+ ? store.summaries.filter((s) => s.project === project).length
689
+ : store.summaries.length;
651
690
  const ext = this.detectExternalMemoryStore();
652
691
  return {
653
692
  totalObservations: store.observations.length,
654
693
  totalSummaries: store.summaries.length,
655
694
  projectObservations,
695
+ projectSummaries,
656
696
  externalStoreAvailable: ext.available,
657
697
  externalStorePath: ext.dbPath
658
698
  };
@@ -769,10 +769,52 @@ export class EpisodicMemoryStore {
769
769
  }
770
770
  }
771
771
 
772
+ clearProject(workspace: string): { observationsRemoved: number; summariesRemoved: number } {
773
+ const store = this.ensureLoaded();
774
+ const project = projectFromWorkspace(workspace);
775
+ const canonical = (p: string): string => {
776
+ const r = path.resolve(p);
777
+ try {
778
+ const real = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native(r) : fs.realpathSync(r);
779
+ return process.platform === 'win32' ? real.toLowerCase() : real;
780
+ } catch {
781
+ return process.platform === 'win32' ? r.toLowerCase() : r;
782
+ }
783
+ };
784
+ const targetWs = canonical(workspace);
785
+ const beforeObs = store.observations.length;
786
+ const beforeSum = store.summaries.length;
787
+ store.observations = store.observations.filter(
788
+ (o) => o.project !== project && (!o.workspace || canonical(o.workspace) !== targetWs)
789
+ );
790
+ store.summaries = store.summaries.filter(
791
+ (s) => s.project !== project && (!s.workspace || canonical(s.workspace) !== targetWs)
792
+ );
793
+ const observationsRemoved = beforeObs - store.observations.length;
794
+ const summariesRemoved = beforeSum - store.summaries.length;
795
+ if (observationsRemoved > 0 || summariesRemoved > 0) {
796
+ this.save();
797
+ }
798
+ return { observationsRemoved, summariesRemoved };
799
+ }
800
+
801
+ clearAll(): { observationsRemoved: number; summariesRemoved: number } {
802
+ const store = this.ensureLoaded();
803
+ const observationsRemoved = store.observations.length;
804
+ const summariesRemoved = store.summaries.length;
805
+ store.observations = [];
806
+ store.summaries = [];
807
+ if (observationsRemoved > 0 || summariesRemoved > 0) {
808
+ this.save();
809
+ }
810
+ return { observationsRemoved, summariesRemoved };
811
+ }
812
+
772
813
  getStats(workspace?: string): {
773
814
  totalObservations: number;
774
815
  totalSummaries: number;
775
816
  projectObservations: number;
817
+ projectSummaries: number;
776
818
  externalStoreAvailable: boolean;
777
819
  externalStorePath: string;
778
820
  } {
@@ -781,11 +823,15 @@ export class EpisodicMemoryStore {
781
823
  const projectObservations = project
782
824
  ? store.observations.filter((o) => o.project === project).length
783
825
  : store.observations.length;
826
+ const projectSummaries = project
827
+ ? store.summaries.filter((s) => s.project === project).length
828
+ : store.summaries.length;
784
829
  const ext = this.detectExternalMemoryStore();
785
830
  return {
786
831
  totalObservations: store.observations.length,
787
832
  totalSummaries: store.summaries.length,
788
833
  projectObservations,
834
+ projectSummaries,
789
835
  externalStoreAvailable: ext.available,
790
836
  externalStorePath: ext.dbPath
791
837
  };