@causyne/agent 1.20.124 → 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 (254) hide show
  1. package/bin/causyne.js +1 -1
  2. package/docs/THIRD_PARTY_NOTICES.md +36 -2
  3. package/package.json +6 -4
  4. package/src/acp/protocol.ts +19 -1
  5. package/src/acp/server.js +282 -8
  6. package/src/acp/server.ts +284 -8
  7. package/src/agent/abortableDelay.js +2 -2
  8. package/src/agent/abortableDelay.ts +2 -2
  9. package/src/agent/errorClassifier.js +9 -1
  10. package/src/agent/errorClassifier.ts +8 -1
  11. package/src/agentLoop.js +142 -53
  12. package/src/agentLoop.ts +151 -50
  13. package/src/approvalPolicy.js +34 -10
  14. package/src/approvalPolicy.ts +42 -11
  15. package/src/browser/causyneBrowser.js +61 -3
  16. package/src/browser/causyneBrowser.ts +65 -3
  17. package/src/browser/urlPolicy.js +14 -1
  18. package/src/browser/urlPolicy.ts +12 -1
  19. package/src/cliMode.js +21 -9
  20. package/src/cliMode.ts +20 -8
  21. package/src/commands.js +365 -45
  22. package/src/commands.ts +403 -45
  23. package/src/config.js +19 -4
  24. package/src/config.ts +18 -4
  25. package/src/core/contextCompactor.js +54 -7
  26. package/src/core/contextCompactor.ts +63 -7
  27. package/src/core/goalLoop.js +257 -0
  28. package/src/core/goalLoop.ts +310 -0
  29. package/src/entrypoint.js +135 -3
  30. package/src/entrypoint.ts +136 -3
  31. package/src/game/causyneCoreBridge.js +686 -0
  32. package/src/game/causyneCoreBridge.ts +702 -0
  33. package/src/game/gameLauncher.js +287 -0
  34. package/src/game/gameLauncher.ts +352 -0
  35. package/src/game/gameProvisioner.js +425 -0
  36. package/src/game/gameProvisioner.ts +488 -0
  37. package/src/headlessCli.js +19 -12
  38. package/src/headlessCli.ts +22 -8
  39. package/src/infra/atomicWriter.js +40 -4
  40. package/src/infra/atomicWriter.ts +36 -4
  41. package/src/launchIntent.js +73 -3
  42. package/src/launchIntent.ts +76 -3
  43. package/src/lsp/lspClient.js +83 -12
  44. package/src/lsp/lspClient.ts +75 -12
  45. package/src/mcp/mcpRegistry.js +75 -8
  46. package/src/mcp/mcpRegistry.ts +70 -7
  47. package/src/memory/contextBudget.js +2 -0
  48. package/src/memory/contextBudget.ts +1 -0
  49. package/src/memory/episodicStore.js +40 -0
  50. package/src/memory/episodicStore.ts +46 -0
  51. package/src/memory.js +67 -0
  52. package/src/memory.ts +65 -0
  53. package/src/modelVariants.js +45 -0
  54. package/src/modelVariants.ts +54 -0
  55. package/src/outputRecovery.js +3 -2
  56. package/src/outputRecovery.ts +4 -2
  57. package/src/permissionPresets.js +327 -0
  58. package/src/permissionPresets.ts +361 -0
  59. package/src/personalization.js +365 -0
  60. package/src/personalization.ts +471 -0
  61. package/src/projectInstructions.js +30 -10
  62. package/src/projectInstructions.ts +31 -12
  63. package/src/providers/acp.js +3 -2
  64. package/src/providers/acp.ts +3 -2
  65. package/src/providers/antigravity.js +64 -9
  66. package/src/providers/antigravity.ts +75 -9
  67. package/src/providers/byokHttp.js +7 -1
  68. package/src/providers/byokHttp.ts +6 -1
  69. package/src/providers/byokStream.js +21 -8
  70. package/src/providers/byokStream.ts +17 -7
  71. package/src/providers/dashscope-byok.js +21 -5
  72. package/src/providers/dashscope-byok.ts +29 -11
  73. package/src/providers/moonshot.js +26 -7
  74. package/src/providers/moonshot.ts +34 -13
  75. package/src/providers/muse.js +6 -0
  76. package/src/providers/muse.ts +8 -0
  77. package/src/providers/ollama.js +39 -7
  78. package/src/providers/ollama.ts +36 -7
  79. package/src/providers/openai-compatible.js +16 -3
  80. package/src/providers/openai-compatible.ts +13 -3
  81. package/src/providers/openai.js +62 -4
  82. package/src/providers/openai.ts +50 -4
  83. package/src/providers/openrouter.js +19 -4
  84. package/src/providers/openrouter.ts +21 -4
  85. package/src/providers/qwen-byok.js +21 -5
  86. package/src/providers/qwen-byok.ts +29 -11
  87. package/src/providers/xai.js +26 -10
  88. package/src/providers/xai.ts +34 -16
  89. package/src/reporting.js +4 -2
  90. package/src/reporting.ts +4 -2
  91. package/src/sandbox.js +34 -0
  92. package/src/sandbox.ts +43 -0
  93. package/src/scheduler/scheduler.js +372 -0
  94. package/src/scheduler/scheduler.ts +433 -0
  95. package/src/sessionSearchIndex.js +267 -0
  96. package/src/sessionSearchIndex.ts +311 -0
  97. package/src/skillsManager.js +2 -3
  98. package/src/skillsManager.ts +2 -3
  99. package/src/toolPacks.js +6 -0
  100. package/src/toolPacks.ts +6 -0
  101. package/src/tools/applyPatch.js +1 -1
  102. package/src/tools/applyPatch.ts +1 -1
  103. package/src/tools/generateMediaViaApi.js +4 -3
  104. package/src/tools/generateMediaViaApi.ts +4 -3
  105. package/src/tools/memoryWrite.js +15 -1
  106. package/src/tools/memoryWrite.ts +16 -1
  107. package/src/tools/nativeEngine.js +2 -2
  108. package/src/tools/nativeEngine.ts +2 -2
  109. package/src/tools/openSourceToolProvisioner.js +2 -2
  110. package/src/tools/openSourceToolProvisioner.ts +2 -2
  111. package/src/tools/osSandbox.js +1 -1
  112. package/src/tools/osSandbox.ts +1 -1
  113. package/src/tools/payloadSanitizer.js +0 -1
  114. package/src/tools/payloadSanitizer.ts +0 -1
  115. package/src/tools/pdfReader.js +122 -20
  116. package/src/tools/pdfReader.ts +111 -20
  117. package/src/tools/presentDeliverable.js +103 -0
  118. package/src/tools/presentDeliverable.ts +127 -0
  119. package/src/tools/ptcRuntime.js +444 -0
  120. package/src/tools/ptcRuntime.ts +490 -0
  121. package/src/tools/ptyTerminal.js +1108 -0
  122. package/src/tools/ptyTerminal.ts +1245 -0
  123. package/src/tools/registry.js +21 -12
  124. package/src/tools/registry.ts +21 -12
  125. package/src/tools/toolOutputStore.js +26 -4
  126. package/src/tools/toolOutputStore.ts +22 -4
  127. package/src/tools/webFetch.js +158 -11
  128. package/src/tools/webFetch.ts +145 -11
  129. package/src/tools/webSearch.js +123 -36
  130. package/src/tools/webSearch.ts +124 -33
  131. package/src/tui/banner.js +5 -1
  132. package/src/tui/banner.ts +6 -1
  133. package/src/tui/chatRenderer.js +1 -2
  134. package/src/tui/chatRenderer.ts +1 -2
  135. package/src/tui/completion.js +1 -0
  136. package/src/tui/completion.ts +1 -0
  137. package/src/tui/composerControls.js +111 -27
  138. package/src/tui/composerControls.ts +124 -28
  139. package/src/tui/dialogs.js +3 -16
  140. package/src/tui/dialogs.ts +3 -16
  141. package/src/tui/home.js +1 -0
  142. package/src/tui/home.ts +1 -0
  143. package/src/tui/invocation.js +1 -2
  144. package/src/tui/invocation.ts +1 -2
  145. package/src/tui/modelPicker.js +22 -12
  146. package/src/tui/modelPicker.ts +22 -12
  147. package/src/tui/overlay.js +2 -5
  148. package/src/tui/overlay.ts +2 -5
  149. package/src/tui/prompt.js +6 -4
  150. package/src/tui/prompt.ts +6 -4
  151. package/src/tui/selectList.js +4 -12
  152. package/src/tui/selectList.ts +4 -12
  153. package/src/tui/setup.js +22 -9
  154. package/src/tui/setup.ts +26 -9
  155. package/src/tui/statusLine.ts +2 -0
  156. package/src/web/client/browserPanel.js +905 -0
  157. package/src/web/client/browserPanel.ts +872 -0
  158. package/src/web/client/chatStream.js +321 -0
  159. package/src/web/client/chatStream.ts +297 -0
  160. package/src/web/client/cliPanel.js +165 -0
  161. package/src/web/client/cliPanel.ts +171 -0
  162. package/src/web/client/composer.js +204 -0
  163. package/src/web/client/composer.ts +209 -0
  164. package/src/web/client/diffPanel.js +176 -0
  165. package/src/web/client/diffPanel.ts +203 -0
  166. package/src/web/client/dom.js +271 -0
  167. package/src/web/client/dom.ts +272 -0
  168. package/src/web/client/filesAndCanvas.js +233 -0
  169. package/src/web/client/filesAndCanvas.ts +240 -0
  170. package/src/web/client/gameLauncherUi.js +78 -0
  171. package/src/web/client/gameLauncherUi.ts +78 -0
  172. package/src/web/client/main.js +316 -0
  173. package/src/web/client/main.ts +391 -0
  174. package/src/web/client/markdown.js +364 -0
  175. package/src/web/client/markdown.ts +373 -0
  176. package/src/web/client/modelPicker.js +455 -0
  177. package/src/web/client/modelPicker.ts +451 -0
  178. package/src/web/client/permissionPresetsUi.js +307 -0
  179. package/src/web/client/permissionPresetsUi.ts +333 -0
  180. package/src/web/client/sessions.js +353 -0
  181. package/src/web/client/sessions.ts +372 -0
  182. package/src/web/client/settingsModal.js +824 -0
  183. package/src/web/client/settingsModal.ts +959 -0
  184. package/src/web/client/state.js +280 -0
  185. package/src/web/client/state.ts +259 -0
  186. package/src/web/client/streamSmoother.js +127 -0
  187. package/src/web/client/streamSmoother.ts +119 -0
  188. package/src/web/client/studioLayout.js +89 -0
  189. package/src/web/client/studioLayout.ts +103 -0
  190. package/src/web/client/studioShell.js +660 -0
  191. package/src/web/client/studioShell.ts +672 -0
  192. package/src/web/client/studioStart.js +77 -0
  193. package/src/web/client/studioStart.ts +89 -0
  194. package/src/web/client/terminalPanel.js +606 -0
  195. package/src/web/client/terminalPanel.ts +632 -0
  196. package/src/web/client/terminalTheme.js +249 -0
  197. package/src/web/client/terminalTheme.ts +258 -0
  198. package/src/web/client/turnView.js +934 -0
  199. package/src/web/client/turnView.ts +981 -0
  200. package/src/web/client/types.js +1 -0
  201. package/src/web/client/types.ts +322 -0
  202. package/src/web/client/validators.js +147 -0
  203. package/src/web/client/validators.ts +140 -0
  204. package/src/web/server/activeRuns.js +152 -0
  205. package/src/web/server/activeRuns.ts +171 -0
  206. package/src/web/server/routesBrowser.js +409 -0
  207. package/src/web/server/routesBrowser.ts +435 -0
  208. package/src/web/server/routesChat.js +304 -0
  209. package/src/web/server/routesChat.ts +347 -0
  210. package/src/web/server/routesCore.js +472 -0
  211. package/src/web/server/routesCore.ts +522 -0
  212. package/src/web/server/routesSettings.js +344 -0
  213. package/src/web/server/routesSettings.ts +397 -0
  214. package/src/web/server/routesTerminal.js +162 -0
  215. package/src/web/server/routesTerminal.ts +182 -0
  216. package/src/web/server/routesWorkspace.js +510 -0
  217. package/src/web/server/routesWorkspace.ts +546 -0
  218. package/src/web/server/security.js +98 -0
  219. package/src/web/server/security.ts +108 -0
  220. package/src/web/server/sessionTranscript.js +586 -0
  221. package/src/web/server/sessionTranscript.ts +566 -0
  222. package/src/web/server/staticAssets.js +104 -0
  223. package/src/web/server/staticAssets.ts +116 -0
  224. package/src/web/server/types.js +1 -0
  225. package/src/web/server/types.ts +135 -0
  226. package/src/web/server/workspaceFiles.js +368 -0
  227. package/src/web/server/workspaceFiles.ts +363 -0
  228. package/src/web/skybridgeServer.js +78 -2448
  229. package/src/web/skybridgeServer.ts +120 -2600
  230. package/src/web/skybridgeUi.js +20 -450
  231. package/src/web/skybridgeUi.ts +24 -455
  232. package/src/web/styles/agent.css +380 -0
  233. package/src/web/styles/composer.css +193 -0
  234. package/src/web/styles/overlays.css +935 -0
  235. package/src/web/styles/shell.css +387 -0
  236. package/src/web/styles/studio.css +951 -0
  237. package/src/web/styles/thread.css +221 -0
  238. package/src/web/styles/tokens.css +94 -0
  239. package/src/web/ui/brandMark.js +73 -0
  240. package/src/web/ui/brandMark.ts +82 -0
  241. package/src/web/ui/modalsTemplate.js +388 -0
  242. package/src/web/ui/modalsTemplate.ts +388 -0
  243. package/src/web/ui/sidebarTemplate.js +63 -0
  244. package/src/web/ui/sidebarTemplate.ts +64 -0
  245. package/src/web/ui/studioTemplate.js +256 -0
  246. package/src/web/ui/studioTemplate.ts +256 -0
  247. package/src/web/ui/workspaceTemplate.js +72 -0
  248. package/src/web/ui/workspaceTemplate.ts +73 -0
  249. package/src/worktreeManager.js +16 -1
  250. package/src/worktreeManager.ts +22 -1
  251. package/src/web/skybridgeClientScript.js +0 -3951
  252. package/src/web/skybridgeClientScript.ts +0 -3952
  253. package/src/web/skybridgeStyles.js +0 -827
  254. package/src/web/skybridgeStyles.ts +0 -828
@@ -0,0 +1,471 @@
1
+ /**
2
+ * Causyne Agent — Per-Project & Global Personalization + Memory Governance
3
+ *
4
+ * Primary behavior is per-project (workspace-scoped) so each repository/project
5
+ * maintains its own high-priority personalization contract and memory policy
6
+ * without leaking into unrelated workspaces:
7
+ * - Project instructions : `<workspaceRoot>/.causyne/personalization.md`
8
+ * - Project settings : `<workspaceRoot>/.causyne/settings.json`
9
+ * - Global instructions : `~/.causyne/CAUSYNE.md`
10
+ * - Global memory prefs : `~/.causyne/config.json` (`memory: { enabled, allowToolAssisted }`)
11
+ *
12
+ * Security invariants:
13
+ * - Fixed allowlisted filenames only (no arbitrary path writes).
14
+ * - Refuses symlinks on both parent `.causyne` directory and target files.
15
+ * - Atomic file writes via `atomicWriteFileSync`.
16
+ * - Enforces 16 KiB single-file cap matching `projectInstructions.ts`.
17
+ */
18
+
19
+ import fs from 'node:fs';
20
+ import path from 'node:path';
21
+ import { causyneHome } from './utils/paths.js';
22
+ import { loadConfig, saveConfig } from './config.js';
23
+ import { atomicWriteFileSync } from './infra/atomicWriter.js';
24
+ import { clearMemory, clearMemoryForWorkspace, getMemoryStats } from './memory.js';
25
+ import { episodicStore } from './memory/episodicStore.js';
26
+ import { loadProjectInstructions } from './projectInstructions.js';
27
+ import { safeDisplay } from './tui/text.js';
28
+
29
+ export type PersonalizationScope = 'project' | 'global';
30
+
31
+ export interface MemoryPreferences {
32
+ enabled: boolean;
33
+ allowToolAssisted: boolean;
34
+ }
35
+
36
+ export interface ProjectMemoryOverrides {
37
+ enabled?: boolean | undefined;
38
+ allowToolAssisted?: boolean | undefined;
39
+ }
40
+
41
+ export interface EffectiveMemoryPolicy {
42
+ enabled: boolean;
43
+ allowToolAssisted: boolean;
44
+ source: 'project' | 'global';
45
+ projectOverrides: ProjectMemoryOverrides;
46
+ globalDefaults: MemoryPreferences;
47
+ }
48
+
49
+ export interface PersonalizationDocumentState {
50
+ scope: PersonalizationScope;
51
+ path: string;
52
+ displayPath: string;
53
+ exists: boolean;
54
+ content: string;
55
+ bytes: number;
56
+ maxBytes: number;
57
+ }
58
+
59
+ export interface PersonalizationRuleSummary {
60
+ scope: 'personalization' | 'global' | 'workspace' | 'rule';
61
+ label: string;
62
+ sourcePath: string;
63
+ bytes: number;
64
+ truncated: boolean;
65
+ globs?: string[] | undefined;
66
+ }
67
+
68
+ export interface MemoryStatsSummary {
69
+ projectFacts: number;
70
+ totalFacts: number;
71
+ projectObservations: number;
72
+ totalObservations: number;
73
+ projectSummaries: number;
74
+ totalSummaries: number;
75
+ }
76
+
77
+ export interface PersonalizationOverview {
78
+ workspaceRoot: string;
79
+ project: PersonalizationDocumentState;
80
+ global: PersonalizationDocumentState;
81
+ memory: EffectiveMemoryPolicy;
82
+ memoryStats: MemoryStatsSummary;
83
+ activeRules: PersonalizationRuleSummary[];
84
+ }
85
+
86
+ export const MAX_PERSONALIZATION_BYTES = 16_384;
87
+ const MAX_SETTINGS_JSON_BYTES = 64 * 1024;
88
+ const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
89
+
90
+ const EXTERNAL_TOOL_ASSISTED_NAMES = new Set([
91
+ 'web_search',
92
+ 'web_fetch',
93
+ 'browser_act',
94
+ 'search_web',
95
+ 'read_url_content',
96
+ 'browser_navigate',
97
+ 'browser_read_page',
98
+ 'browser_interact',
99
+ 'browser_extract',
100
+ 'browser_screenshot',
101
+ 'browser_tabs'
102
+ ]);
103
+
104
+ function resolveHomeDir(env: NodeJS.ProcessEnv = process.env): string {
105
+ const override = env.CAUSYNE_HOME && String(env.CAUSYNE_HOME).trim();
106
+ return override ? path.resolve(override) : causyneHome();
107
+ }
108
+
109
+ export function resolveProjectPersonalizationPath(workspaceRoot: string): string {
110
+ return path.join(path.resolve(workspaceRoot), '.causyne', 'personalization.md');
111
+ }
112
+
113
+ export function resolveProjectSettingsPath(workspaceRoot: string): string {
114
+ return path.join(path.resolve(workspaceRoot), '.causyne', 'settings.json');
115
+ }
116
+
117
+ export function resolveGlobalPersonalizationPath(env: NodeJS.ProcessEnv = process.env): string {
118
+ return path.join(resolveHomeDir(env), 'CAUSYNE.md');
119
+ }
120
+
121
+ function assertNotSymlinkIfPresent(targetPath: string, expectedKind: 'file' | 'dir'): void {
122
+ try {
123
+ const stat = fs.lstatSync(targetPath);
124
+ if (stat.isSymbolicLink()) {
125
+ throw new Error(`Refusing symlink at ${safeDisplay(path.basename(targetPath))}`);
126
+ }
127
+ if (expectedKind === 'dir' && !stat.isDirectory()) {
128
+ throw new Error(`Expected directory at ${safeDisplay(path.basename(targetPath))}`);
129
+ }
130
+ if (expectedKind === 'file' && !stat.isFile()) {
131
+ throw new Error(`Expected regular file at ${safeDisplay(path.basename(targetPath))}`);
132
+ }
133
+ } catch (err: unknown) {
134
+ const code = typeof err === 'object' && err !== null && 'code' in err ? String((err as NodeJS.ErrnoException).code) : '';
135
+ if (code === 'ENOENT') return;
136
+ throw err;
137
+ }
138
+ }
139
+
140
+ function ensureSafeDirectory(dirPath: string, mode: number): void {
141
+ assertNotSymlinkIfPresent(dirPath, 'dir');
142
+ fs.mkdirSync(dirPath, { recursive: true, mode });
143
+ assertNotSymlinkIfPresent(dirPath, 'dir');
144
+ }
145
+
146
+ function readSafeMarkdownFile(
147
+ filePath: string,
148
+ scope: PersonalizationScope,
149
+ displayPath: string
150
+ ): PersonalizationDocumentState {
151
+ try {
152
+ const stat = fs.lstatSync(filePath);
153
+ if (stat.isSymbolicLink() || !stat.isFile()) {
154
+ return {
155
+ scope,
156
+ path: filePath,
157
+ displayPath,
158
+ exists: false,
159
+ content: '',
160
+ bytes: 0,
161
+ maxBytes: MAX_PERSONALIZATION_BYTES
162
+ };
163
+ }
164
+ const raw = fs.readFileSync(filePath, 'utf8').replace(/^\uFEFF/, '').replace(/\r\n/g, '\n');
165
+ const clamped = raw.length > MAX_PERSONALIZATION_BYTES ? raw.slice(0, MAX_PERSONALIZATION_BYTES) : raw;
166
+ return {
167
+ scope,
168
+ path: filePath,
169
+ displayPath,
170
+ exists: true,
171
+ content: clamped,
172
+ bytes: Buffer.byteLength(clamped, 'utf8'),
173
+ maxBytes: MAX_PERSONALIZATION_BYTES
174
+ };
175
+ } catch {
176
+ return {
177
+ scope,
178
+ path: filePath,
179
+ displayPath,
180
+ exists: false,
181
+ content: '',
182
+ bytes: 0,
183
+ maxBytes: MAX_PERSONALIZATION_BYTES
184
+ };
185
+ }
186
+ }
187
+
188
+ function readProjectSettingsRaw(workspaceRoot: string): Record<string, unknown> {
189
+ const settingsPath = resolveProjectSettingsPath(workspaceRoot);
190
+ try {
191
+ const dirPath = path.dirname(settingsPath);
192
+ const dirStat = fs.lstatSync(dirPath);
193
+ if (dirStat.isSymbolicLink() || !dirStat.isDirectory()) return {};
194
+ const stat = fs.lstatSync(settingsPath);
195
+ if (stat.isSymbolicLink() || !stat.isFile() || stat.size === 0 || stat.size > MAX_SETTINGS_JSON_BYTES) {
196
+ return {};
197
+ }
198
+ const parsed: unknown = JSON.parse(fs.readFileSync(settingsPath, 'utf8').replace(/^\uFEFF/, ''));
199
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
200
+ const clean = Object.create(null) as Record<string, unknown>;
201
+ for (const [k, v] of Object.entries(parsed as Record<string, unknown>)) {
202
+ if (!FORBIDDEN_KEYS.has(k)) clean[k] = v;
203
+ }
204
+ return { ...clean };
205
+ } catch {
206
+ return {};
207
+ }
208
+ }
209
+
210
+ function writeProjectSettingsRaw(workspaceRoot: string, nextData: Record<string, unknown>): void {
211
+ const settingsPath = resolveProjectSettingsPath(workspaceRoot);
212
+ const dirPath = path.dirname(settingsPath);
213
+ ensureSafeDirectory(dirPath, 0o755);
214
+ assertNotSymlinkIfPresent(settingsPath, 'file');
215
+ atomicWriteFileSync(settingsPath, `${JSON.stringify(nextData, null, 2)}\n`, { mode: 0o644 });
216
+ }
217
+
218
+ function readGlobalMemoryDefaults(): MemoryPreferences {
219
+ const config = loadConfig();
220
+ const raw = config.memory && typeof config.memory === 'object' && !Array.isArray(config.memory)
221
+ ? (config.memory as Record<string, unknown>)
222
+ : {};
223
+ return {
224
+ enabled: raw.enabled !== false,
225
+ allowToolAssisted: raw.allowToolAssisted !== false
226
+ };
227
+ }
228
+
229
+ function readProjectMemoryOverrides(workspaceRoot: string): ProjectMemoryOverrides {
230
+ const rawSettings = readProjectSettingsRaw(workspaceRoot);
231
+ const rawMem = rawSettings.memory && typeof rawSettings.memory === 'object' && !Array.isArray(rawSettings.memory)
232
+ ? (rawSettings.memory as Record<string, unknown>)
233
+ : {};
234
+ const overrides: ProjectMemoryOverrides = {};
235
+ if (typeof rawMem.enabled === 'boolean') overrides.enabled = rawMem.enabled;
236
+ if (typeof rawMem.allowToolAssisted === 'boolean') overrides.allowToolAssisted = rawMem.allowToolAssisted;
237
+ return overrides;
238
+ }
239
+
240
+ /**
241
+ * Resolves the effective Causyne Memory policy for a workspace:
242
+ * per-project overrides in `<workspace>/.causyne/settings.json` take precedence
243
+ * over global defaults in `~/.causyne/config.json`.
244
+ */
245
+ export function resolveEffectiveMemoryPolicy(workspaceRoot?: string): EffectiveMemoryPolicy {
246
+ const globalDefaults = readGlobalMemoryDefaults();
247
+ const projectOverrides = workspaceRoot ? readProjectMemoryOverrides(workspaceRoot) : {};
248
+ const hasProjectOverride =
249
+ typeof projectOverrides.enabled === 'boolean' || typeof projectOverrides.allowToolAssisted === 'boolean';
250
+ return {
251
+ enabled: typeof projectOverrides.enabled === 'boolean' ? projectOverrides.enabled : globalDefaults.enabled,
252
+ allowToolAssisted: typeof projectOverrides.allowToolAssisted === 'boolean'
253
+ ? projectOverrides.allowToolAssisted
254
+ : globalDefaults.allowToolAssisted,
255
+ source: hasProjectOverride ? 'project' : 'global',
256
+ projectOverrides,
257
+ globalDefaults
258
+ };
259
+ }
260
+
261
+ /**
262
+ * Returns true if a tool invocation brings external/untrusted context
263
+ * (MCP servers, web search, web fetch, or live web browsing), which is gated
264
+ * when `allowToolAssisted` memory generation is turned off.
265
+ */
266
+ export function isExternalToolAssistedToolName(toolName: string): boolean {
267
+ const normalized = String(toolName || '').trim().toLowerCase();
268
+ if (!normalized) return false;
269
+ if (normalized.startsWith('mcp__') || normalized.startsWith('mcp_') || normalized.startsWith('mcp:')) {
270
+ return true;
271
+ }
272
+ return EXTERNAL_TOOL_ASSISTED_NAMES.has(normalized);
273
+ }
274
+
275
+ /**
276
+ * Atomically saves project-scoped (`.causyne/personalization.md`) or global (`~/.causyne/CAUSYNE.md`)
277
+ * personalization instructions. Refuses symlinks and enforces the 16 KiB size ceiling.
278
+ */
279
+ export function savePersonalizationInstructions(
280
+ workspaceRoot: string,
281
+ scope: PersonalizationScope,
282
+ rawContent: string,
283
+ env: NodeJS.ProcessEnv = process.env
284
+ ): PersonalizationDocumentState {
285
+ if (typeof rawContent !== 'string') {
286
+ throw new Error('Personalization instructions must be a string.');
287
+ }
288
+ if (rawContent.includes('\0')) {
289
+ throw new Error('Personalization instructions must not contain NUL bytes.');
290
+ }
291
+ const normalized = rawContent.replace(/\r\n/g, '\n');
292
+ const byteLen = Buffer.byteLength(normalized, 'utf8');
293
+ if (byteLen > MAX_PERSONALIZATION_BYTES) {
294
+ throw new Error(`Personalization instructions exceed maximum size (${MAX_PERSONALIZATION_BYTES} bytes).`);
295
+ }
296
+
297
+ const targetPath = scope === 'global'
298
+ ? resolveGlobalPersonalizationPath(env)
299
+ : resolveProjectPersonalizationPath(workspaceRoot);
300
+ const displayPath = scope === 'global' ? '~/.causyne/CAUSYNE.md' : '.causyne/personalization.md';
301
+ const dirPath = path.dirname(targetPath);
302
+
303
+ if (normalized.trim().length === 0) {
304
+ assertNotSymlinkIfPresent(dirPath, 'dir');
305
+ assertNotSymlinkIfPresent(targetPath, 'file');
306
+ try {
307
+ if (fs.existsSync(targetPath)) fs.unlinkSync(targetPath);
308
+ } catch {
309
+ // Ignore if absent
310
+ }
311
+ return readSafeMarkdownFile(targetPath, scope, displayPath);
312
+ }
313
+
314
+ ensureSafeDirectory(dirPath, scope === 'global' ? 0o700 : 0o755);
315
+ assertNotSymlinkIfPresent(targetPath, 'file');
316
+ const payload = normalized.endsWith('\n') ? normalized : `${normalized}\n`;
317
+ atomicWriteFileSync(targetPath, payload, { mode: scope === 'global' ? 0o600 : 0o644 });
318
+ return readSafeMarkdownFile(targetPath, scope, displayPath);
319
+ }
320
+
321
+ /**
322
+ * Updates memory preferences for either `'project'` (`<workspace>/.causyne/settings.json`)
323
+ * or `'global'` (`~/.causyne/config.json`). Passing `null` on a project field clears the
324
+ * per-project override so it inherits the global default.
325
+ */
326
+ export function saveMemoryPreferences(
327
+ workspaceRoot: string,
328
+ scope: PersonalizationScope,
329
+ patch: { enabled?: boolean | null | undefined; allowToolAssisted?: boolean | null | undefined }
330
+ ): EffectiveMemoryPolicy {
331
+ if (scope === 'global') {
332
+ const config = loadConfig();
333
+ const current = readGlobalMemoryDefaults();
334
+ const next: MemoryPreferences = {
335
+ enabled: typeof patch.enabled === 'boolean' ? patch.enabled : current.enabled,
336
+ allowToolAssisted: typeof patch.allowToolAssisted === 'boolean'
337
+ ? patch.allowToolAssisted
338
+ : current.allowToolAssisted
339
+ };
340
+ config.memory = next;
341
+ saveConfig(config);
342
+ return resolveEffectiveMemoryPolicy(workspaceRoot);
343
+ }
344
+
345
+ const settings = readProjectSettingsRaw(workspaceRoot);
346
+ const currentMem = settings.memory && typeof settings.memory === 'object' && !Array.isArray(settings.memory)
347
+ ? { ...(settings.memory as Record<string, unknown>) }
348
+ : {};
349
+
350
+ if (patch.enabled === null) {
351
+ delete currentMem.enabled;
352
+ } else if (typeof patch.enabled === 'boolean') {
353
+ currentMem.enabled = patch.enabled;
354
+ }
355
+
356
+ if (patch.allowToolAssisted === null) {
357
+ delete currentMem.allowToolAssisted;
358
+ } else if (typeof patch.allowToolAssisted === 'boolean') {
359
+ currentMem.allowToolAssisted = patch.allowToolAssisted;
360
+ }
361
+
362
+ if (Object.keys(currentMem).length === 0) {
363
+ delete settings.memory;
364
+ } else {
365
+ settings.memory = currentMem;
366
+ }
367
+ writeProjectSettingsRaw(workspaceRoot, settings);
368
+ return resolveEffectiveMemoryPolicy(workspaceRoot);
369
+ }
370
+
371
+ /**
372
+ * Collects live memory counts across persistent facts (`memory.json`) and
373
+ * episodic observations/summaries (`episodic-memory.json`).
374
+ */
375
+ export function collectMemoryStats(workspaceRoot: string): MemoryStatsSummary {
376
+ const factStats = getMemoryStats(workspaceRoot);
377
+ const epStats = episodicStore.getStats(workspaceRoot);
378
+ return {
379
+ projectFacts: factStats.projectFacts,
380
+ totalFacts: factStats.totalFacts,
381
+ projectObservations: epStats.projectObservations,
382
+ totalObservations: epStats.totalObservations,
383
+ projectSummaries: epStats.projectSummaries,
384
+ totalSummaries: epStats.totalSummaries
385
+ };
386
+ }
387
+
388
+ /**
389
+ * Deletes stored Causyne memories for either the active project (`'project'`)
390
+ * or across all projects (`'all'`).
391
+ */
392
+ export function deleteCausyneMemories(
393
+ workspaceRoot: string,
394
+ scope: 'project' | 'all' = 'project'
395
+ ): {
396
+ scope: 'project' | 'all';
397
+ factsRemoved: number;
398
+ observationsRemoved: number;
399
+ summariesRemoved: number;
400
+ memoryStats: MemoryStatsSummary;
401
+ } {
402
+ let factsRemoved = 0;
403
+ let observationsRemoved = 0;
404
+ let summariesRemoved = 0;
405
+
406
+ if (scope === 'all') {
407
+ const beforeFacts = getMemoryStats(workspaceRoot).totalFacts;
408
+ clearMemory();
409
+ factsRemoved = beforeFacts;
410
+ const epCleared = episodicStore.clearAll();
411
+ observationsRemoved = epCleared.observationsRemoved;
412
+ summariesRemoved = epCleared.summariesRemoved;
413
+ } else {
414
+ factsRemoved = clearMemoryForWorkspace(workspaceRoot);
415
+ const epCleared = episodicStore.clearProject(workspaceRoot);
416
+ observationsRemoved = epCleared.observationsRemoved;
417
+ summariesRemoved = epCleared.summariesRemoved;
418
+ }
419
+
420
+ return {
421
+ scope,
422
+ factsRemoved,
423
+ observationsRemoved,
424
+ summariesRemoved,
425
+ memoryStats: collectMemoryStats(workspaceRoot)
426
+ };
427
+ }
428
+
429
+ /**
430
+ * Returns the full Personalization + Memory state for Web Studio GUI and CLI inspection.
431
+ */
432
+ export function readPersonalizationOverview(
433
+ workspaceRoot: string,
434
+ env: NodeJS.ProcessEnv = process.env
435
+ ): PersonalizationOverview {
436
+ const resolvedWs = path.resolve(workspaceRoot);
437
+ const projectDoc = readSafeMarkdownFile(
438
+ resolveProjectPersonalizationPath(resolvedWs),
439
+ 'project',
440
+ '.causyne/personalization.md'
441
+ );
442
+ const globalDoc = readSafeMarkdownFile(
443
+ resolveGlobalPersonalizationPath(env),
444
+ 'global',
445
+ '~/.causyne/CAUSYNE.md'
446
+ );
447
+ const loaded = loadProjectInstructions(resolvedWs, env, { includeUnmatchedScoped: true });
448
+ const activeRules: PersonalizationRuleSummary[] = loaded.entries.map((entry) => {
449
+ const rel = path.relative(loaded.workspaceRoot, entry.sourcePath);
450
+ const label = entry.scope === 'global'
451
+ ? `~/.causyne/${path.basename(entry.sourcePath)}`
452
+ : (rel && !rel.startsWith('..') ? rel.replace(/\\/g, '/') : entry.sourcePath);
453
+ return {
454
+ scope: entry.scope,
455
+ label,
456
+ sourcePath: entry.sourcePath,
457
+ bytes: entry.bytes,
458
+ truncated: entry.truncated,
459
+ ...(entry.globs && entry.globs.length > 0 ? { globs: entry.globs } : {})
460
+ };
461
+ });
462
+
463
+ return {
464
+ workspaceRoot: resolvedWs,
465
+ project: projectDoc,
466
+ global: globalDoc,
467
+ memory: resolveEffectiveMemoryPolicy(resolvedWs),
468
+ memoryStats: collectMemoryStats(resolvedWs),
469
+ activeRules
470
+ };
471
+ }
@@ -1,11 +1,12 @@
1
1
  /**
2
- * Causyne Agent — Hierarchical Project Instructions Loader (Phase C-Core)
2
+ * Causyne Agent — Hierarchical Project Instructions & Personalization Loader
3
3
  *
4
- * Discovers and merges repository instruction files in deterministic precedence:
5
- * 1. User global `~/.causyne/CAUSYNE.md` (if present)
4
+ * Discovers and merges instruction files in deterministic precedence:
5
+ * 1. User global `~/.causyne/CAUSYNE.md` (and `~/.causyne/AGENTS.md` if distinct)
6
6
  * 2. Repository/workspace root down to active subdirectory:
7
- * `CAUSYNE.md`, `AGENTS.md`, `CLAUDE.md`
7
+ * `CAUSYNE.md`, `AGENTS.override.md`, `AGENTS.md`, `CLAUDE.md`
8
8
  * 3. Scoped rule files under `.causyne/rules/*.md` (lexicographical order)
9
+ * 4. Per-project Personalization under `.causyne/personalization.md` (highest project authority)
9
10
  *
10
11
  * Security invariants:
11
12
  * - Refuses symlinks and non-regular files (`lstatSync`).
@@ -25,7 +26,7 @@ const MAX_TOTAL_INSTRUCTION_CHARS = 32_768;
25
26
  const MAX_RULE_FILES = 24;
26
27
  const MAX_INCLUDE_DEPTH = 3;
27
28
  const MAX_INCLUDES_PER_FILE = 8;
28
- const INSTRUCTION_FILENAMES = ['CAUSYNE.md', 'AGENTS.md', 'CLAUDE.md'];
29
+ const INSTRUCTION_FILENAMES = ['CAUSYNE.md', 'AGENTS.override.md', 'AGENTS.md', 'CLAUDE.md'];
29
30
  function parseRuleFrontmatter(raw) {
30
31
  const normalized = raw.replace(/\r\n/g, '\n');
31
32
  if (!normalized.startsWith('---\n')) {
@@ -254,7 +255,9 @@ export function loadProjectInstructions(workspaceDir = process.cwd(), env = proc
254
255
  const homeDir = env.CAUSYNE_HOME && String(env.CAUSYNE_HOME).trim()
255
256
  ? path.resolve(String(env.CAUSYNE_HOME).trim())
256
257
  : causyneHome();
257
- tryAdd(path.join(homeDir, 'CAUSYNE.md'), 'global', nativeRealpath(homeDir));
258
+ const realHomeDir = nativeRealpath(homeDir);
259
+ tryAdd(path.join(homeDir, 'CAUSYNE.md'), 'global', realHomeDir);
260
+ tryAdd(path.join(homeDir, 'AGENTS.md'), 'global', realHomeDir);
258
261
  // 2. Hierarchical repo root -> active workspace directory
259
262
  const dirs = repoRoot ? directoryChain(repoRoot, resolvedWs) : [resolvedWs];
260
263
  for (const dir of dirs) {
@@ -276,6 +279,15 @@ export function loadProjectInstructions(workspaceDir = process.cwd(), env = proc
276
279
  }
277
280
  }
278
281
  catch { /* directory absent */ }
282
+ // 4. Per-project Personalization (`.causyne/personalization.md`) — highest project priority
283
+ const causyneDir = path.join(dir, '.causyne');
284
+ try {
285
+ const dirStat = fs.lstatSync(causyneDir);
286
+ if (!dirStat.isSymbolicLink() && dirStat.isDirectory()) {
287
+ tryAdd(path.join(causyneDir, 'personalization.md'), 'personalization', boundaryRoot);
288
+ }
289
+ }
290
+ catch { /* directory absent */ }
279
291
  }
280
292
  return {
281
293
  workspaceRoot: resolvedWs,
@@ -292,10 +304,18 @@ export function formatProjectInstructionsPrompt(loaded) {
292
304
  const rel = path.relative(loaded.workspaceRoot, entry.sourcePath);
293
305
  const label = entry.scope === 'global'
294
306
  ? `~/.causyne/${path.basename(entry.sourcePath)}`
295
- : (rel && !rel.startsWith('..') ? rel : entry.sourcePath);
307
+ : (rel && !rel.startsWith('..') ? rel.replace(/\\/g, '/') : entry.sourcePath);
308
+ if (entry.scope === 'personalization') {
309
+ return `## PROJECT PERSONALIZATION — HIGH-PRIORITY BINDING CONTRACT (${safeDisplay(label)})\n${entry.content}`;
310
+ }
296
311
  return `## Project Rules (${entry.scope}: ${safeDisplay(label)})\n${entry.content}`;
297
312
  });
298
- return `\n\n# WORKSPACE PROJECT INSTRUCTIONS (loaded deterministically from repository rules — safety boundaries and sandbox rules still take precedence)\n\n${blocks.join('\n\n')}`;
313
+ return [
314
+ '\n\n# PROJECT PERSONALIZATION & WORKSPACE INSTRUCTIONS — TREAT AS HIGH-PRIORITY BINDING CONTRACT',
315
+ 'IMPORTANT: The developer explicitly authored these per-project Personalization and Workspace Instructions to define their project vision, mission, engineering standards, communication preferences, and non-negotiable conventions. Treat them as a BIG DEAL and strictly obey every directive below across all responses, edits, plans, and verifications—overriding generic habits whenever they do not conflict with Causyne\'s Absolute Ethical Safety Net or active permission/sandbox boundaries. Per-project Personalization (`.causyne/personalization.md`) takes highest precedence for this workspace.',
316
+ '',
317
+ blocks.join('\n\n')
318
+ ].join('\n');
299
319
  }
300
320
  export function formatProjectRulesReport(workspaceDir = process.cwd(), env = process.env) {
301
321
  const loaded = loadProjectInstructions(workspaceDir, env, { includeUnmatchedScoped: true });
@@ -303,8 +323,8 @@ export function formatProjectRulesReport(workspaceDir = process.cwd(), env = pro
303
323
  return [
304
324
  'Project Instructions & Rules',
305
325
  ' Status : none loaded',
306
- ` Lookup : CAUSYNE.md, AGENTS.md, CLAUDE.md, .causyne/rules/*.md`,
307
- ' Tip : Run /init or create CAUSYNE.md in your repository root.'
326
+ ` Lookup : .causyne/personalization.md, CAUSYNE.md, AGENTS.override.md, AGENTS.md, CLAUDE.md, .causyne/rules/*.md`,
327
+ ' Tip : Run /personalization set "<instructions>" or /init to create project rules.'
308
328
  ].join('\n');
309
329
  }
310
330
  const lines = [
@@ -1,11 +1,12 @@
1
1
  /**
2
- * Causyne Agent — Hierarchical Project Instructions Loader (Phase C-Core)
2
+ * Causyne Agent — Hierarchical Project Instructions & Personalization Loader
3
3
  *
4
- * Discovers and merges repository instruction files in deterministic precedence:
5
- * 1. User global `~/.causyne/CAUSYNE.md` (if present)
4
+ * Discovers and merges instruction files in deterministic precedence:
5
+ * 1. User global `~/.causyne/CAUSYNE.md` (and `~/.causyne/AGENTS.md` if distinct)
6
6
  * 2. Repository/workspace root down to active subdirectory:
7
- * `CAUSYNE.md`, `AGENTS.md`, `CLAUDE.md`
7
+ * `CAUSYNE.md`, `AGENTS.override.md`, `AGENTS.md`, `CLAUDE.md`
8
8
  * 3. Scoped rule files under `.causyne/rules/*.md` (lexicographical order)
9
+ * 4. Per-project Personalization under `.causyne/personalization.md` (highest project authority)
9
10
  *
10
11
  * Security invariants:
11
12
  * - Refuses symlinks and non-regular files (`lstatSync`).
@@ -24,7 +25,7 @@ import { createIgnoreMatcher, parseIgnoreContent } from './ignoreRules.js';
24
25
 
25
26
  export interface ProjectInstructionEntry {
26
27
  sourcePath: string;
27
- scope: 'global' | 'workspace' | 'rule';
28
+ scope: 'global' | 'workspace' | 'rule' | 'personalization';
28
29
  bytes: number;
29
30
  truncated: boolean;
30
31
  content: string;
@@ -49,7 +50,7 @@ const MAX_TOTAL_INSTRUCTION_CHARS = 32_768;
49
50
  const MAX_RULE_FILES = 24;
50
51
  const MAX_INCLUDE_DEPTH = 3;
51
52
  const MAX_INCLUDES_PER_FILE = 8;
52
- const INSTRUCTION_FILENAMES = ['CAUSYNE.md', 'AGENTS.md', 'CLAUDE.md'] as const;
53
+ const INSTRUCTION_FILENAMES = ['CAUSYNE.md', 'AGENTS.override.md', 'AGENTS.md', 'CLAUDE.md'] as const;
53
54
 
54
55
  function parseRuleFrontmatter(raw: string): { globs: string[]; body: string } {
55
56
  const normalized = raw.replace(/\r\n/g, '\n');
@@ -247,7 +248,7 @@ export function loadProjectInstructions(
247
248
 
248
249
  const tryAdd = (
249
250
  candidatePath: string,
250
- scope: 'global' | 'workspace' | 'rule',
251
+ scope: 'global' | 'workspace' | 'rule' | 'personalization',
251
252
  includeBoundary: string | null
252
253
  ): void => {
253
254
  const resolved = path.resolve(candidatePath);
@@ -294,7 +295,9 @@ export function loadProjectInstructions(
294
295
  const homeDir = env.CAUSYNE_HOME && String(env.CAUSYNE_HOME).trim()
295
296
  ? path.resolve(String(env.CAUSYNE_HOME).trim())
296
297
  : causyneHome();
297
- tryAdd(path.join(homeDir, 'CAUSYNE.md'), 'global', nativeRealpath(homeDir));
298
+ const realHomeDir = nativeRealpath(homeDir);
299
+ tryAdd(path.join(homeDir, 'CAUSYNE.md'), 'global', realHomeDir);
300
+ tryAdd(path.join(homeDir, 'AGENTS.md'), 'global', realHomeDir);
298
301
 
299
302
  // 2. Hierarchical repo root -> active workspace directory
300
303
  const dirs = repoRoot ? directoryChain(repoRoot, resolvedWs) : [resolvedWs];
@@ -316,6 +319,14 @@ export function loadProjectInstructions(
316
319
  }
317
320
  }
318
321
  } catch { /* directory absent */ }
322
+ // 4. Per-project Personalization (`.causyne/personalization.md`) — highest project priority
323
+ const causyneDir = path.join(dir, '.causyne');
324
+ try {
325
+ const dirStat = fs.lstatSync(causyneDir);
326
+ if (!dirStat.isSymbolicLink() && dirStat.isDirectory()) {
327
+ tryAdd(path.join(causyneDir, 'personalization.md'), 'personalization', boundaryRoot);
328
+ }
329
+ } catch { /* directory absent */ }
319
330
  }
320
331
 
321
332
  return {
@@ -333,10 +344,18 @@ export function formatProjectInstructionsPrompt(loaded: LoadedProjectInstruction
333
344
  const rel = path.relative(loaded.workspaceRoot, entry.sourcePath);
334
345
  const label = entry.scope === 'global'
335
346
  ? `~/.causyne/${path.basename(entry.sourcePath)}`
336
- : (rel && !rel.startsWith('..') ? rel : entry.sourcePath);
347
+ : (rel && !rel.startsWith('..') ? rel.replace(/\\/g, '/') : entry.sourcePath);
348
+ if (entry.scope === 'personalization') {
349
+ return `## PROJECT PERSONALIZATION — HIGH-PRIORITY BINDING CONTRACT (${safeDisplay(label)})\n${entry.content}`;
350
+ }
337
351
  return `## Project Rules (${entry.scope}: ${safeDisplay(label)})\n${entry.content}`;
338
352
  });
339
- return `\n\n# WORKSPACE PROJECT INSTRUCTIONS (loaded deterministically from repository rules — safety boundaries and sandbox rules still take precedence)\n\n${blocks.join('\n\n')}`;
353
+ return [
354
+ '\n\n# PROJECT PERSONALIZATION & WORKSPACE INSTRUCTIONS — TREAT AS HIGH-PRIORITY BINDING CONTRACT',
355
+ 'IMPORTANT: The developer explicitly authored these per-project Personalization and Workspace Instructions to define their project vision, mission, engineering standards, communication preferences, and non-negotiable conventions. Treat them as a BIG DEAL and strictly obey every directive below across all responses, edits, plans, and verifications—overriding generic habits whenever they do not conflict with Causyne\'s Absolute Ethical Safety Net or active permission/sandbox boundaries. Per-project Personalization (`.causyne/personalization.md`) takes highest precedence for this workspace.',
356
+ '',
357
+ blocks.join('\n\n')
358
+ ].join('\n');
340
359
  }
341
360
 
342
361
  export function formatProjectRulesReport(workspaceDir: string = process.cwd(), env: NodeJS.ProcessEnv = process.env): string {
@@ -345,8 +364,8 @@ export function formatProjectRulesReport(workspaceDir: string = process.cwd(), e
345
364
  return [
346
365
  'Project Instructions & Rules',
347
366
  ' Status : none loaded',
348
- ` Lookup : CAUSYNE.md, AGENTS.md, CLAUDE.md, .causyne/rules/*.md`,
349
- ' Tip : Run /init or create CAUSYNE.md in your repository root.'
367
+ ` Lookup : .causyne/personalization.md, CAUSYNE.md, AGENTS.override.md, AGENTS.md, CLAUDE.md, .causyne/rules/*.md`,
368
+ ' Tip : Run /personalization set "<instructions>" or /init to create project rules.'
350
369
  ].join('\n');
351
370
  }
352
371
  const lines = [
@@ -146,7 +146,7 @@ export class AcpProvider extends LLMProvider {
146
146
  ' - Bundled Causyne skills must be read via the host tool `fs_read_skill`. Do NOT call peer-native `skill` or functions for Causyne skills. To read a skill, write `<tool_call>{"name": "fs_read_skill", "arguments": {"skill_id": "domain/name"}}</tool_call>` directly in your assistant text response.\n' +
147
147
  ' - To invoke a Causyne host tool, write `<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>` directly in your assistant text response with NO native function call in that step; Causyne will execute the host tool and return the result on the next turn.\n' +
148
148
  '2. WORKSPACE PATH BOUNDARY (NO /tmp):\n' +
149
- ' - Keep ALL temporary files, server logs, and headless browser screenshots inside the active workspace directory (for example, `./.shots/preview.png` or `./server.log`). NEVER write to, read from, or `cp`/`mv` paths in `/tmp` or outside the workspace root, as the host sandbox rejects `/tmp` access.\n\n[Language & Communication Directive]\nDynamically reflect and match the exact language used by the user in their prompt. Respond naturally in that same language.');
149
+ ' - Keep ALL temporary files, server logs, and headless browser screenshots inside the active workspace directory (for example, `./.shots/preview.png` or `./server.log`). NEVER write to, read from, or `cp`/`mv` paths in `/tmp` or outside the workspace root, as the host sandbox rejects `/tmp` access.\n\n[Personalization Directive]\nStrictly honor any Project Personalization (`.causyne/personalization.md`) and workspace instructions included in system context as a high-priority binding contract for this project (subordinate only to safety and sandbox boundaries).\n\n[Language & Communication Directive]\nDynamically reflect and match the exact language used by the user in their prompt. Respond naturally in that same language.');
150
150
  if (tools && tools.length > 0) {
151
151
  const toolSummaries = formatToolContracts(tools);
152
152
  lines.push(`[Available Tools]\nYou may invoke tools when needed by outputting:\n<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>\n\n${toolSummaries}`);
@@ -214,7 +214,8 @@ export class AcpProvider extends LLMProvider {
214
214
  ' - Bundled Causyne skills must be read via the host tool `fs_read_skill`. Do NOT call peer-native `skill` or functions for Causyne skills. To read a skill, write `<tool_call>{"name": "fs_read_skill", "arguments": {"skill_id": "domain/name"}}</tool_call>` directly in your assistant text response.\n' +
215
215
  ' - To invoke a Causyne host tool, write `<tool_call>{"name": "tool_name", "arguments": { ... }}</tool_call>` directly in your assistant text response with NO native function call in that step; Causyne will execute the host tool and return the result on the next turn.\n' +
216
216
  '2. WORKSPACE PATH BOUNDARY (NO /tmp):\n' +
217
- ' - Keep ALL temporary files, server logs, and headless browser screenshots inside the active workspace directory (for example, `./.shots/preview.png` or `./server.log`). NEVER write to, read from, or `cp`/`mv` paths in `/tmp` or outside the workspace root, as the host sandbox rejects `/tmp` access.');
217
+ ' - Keep ALL temporary files, server logs, and headless browser screenshots inside the active workspace directory (for example, `./.shots/preview.png` or `./server.log`). NEVER write to, read from, or `cp`/`mv` paths in `/tmp` or outside the workspace root, as the host sandbox rejects `/tmp` access.\n\n' +
218
+ '[Personalization Directive]\nStrictly honor any Project Personalization (`.causyne/personalization.md`) and workspace instructions included in system context as a high-priority binding contract for this project (subordinate only to safety and sandbox boundaries).');
218
219
  }
219
220
  if (tools && tools.length > 0) {
220
221
  const toolSummaries = formatToolContracts(tools);