@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.
- package/bin/causyne.js +1 -1
- package/docs/THIRD_PARTY_NOTICES.md +36 -2
- package/package.json +6 -4
- package/src/acp/protocol.ts +19 -1
- package/src/acp/server.js +282 -8
- package/src/acp/server.ts +284 -8
- package/src/agent/abortableDelay.js +2 -2
- package/src/agent/abortableDelay.ts +2 -2
- package/src/agent/errorClassifier.js +9 -1
- package/src/agent/errorClassifier.ts +8 -1
- package/src/agentLoop.js +142 -53
- package/src/agentLoop.ts +151 -50
- package/src/approvalPolicy.js +34 -10
- package/src/approvalPolicy.ts +42 -11
- package/src/browser/causyneBrowser.js +61 -3
- package/src/browser/causyneBrowser.ts +65 -3
- package/src/browser/urlPolicy.js +14 -1
- package/src/browser/urlPolicy.ts +12 -1
- package/src/cliMode.js +21 -9
- package/src/cliMode.ts +20 -8
- package/src/commands.js +365 -45
- package/src/commands.ts +403 -45
- package/src/config.js +19 -4
- package/src/config.ts +18 -4
- package/src/core/contextCompactor.js +54 -7
- package/src/core/contextCompactor.ts +63 -7
- package/src/core/goalLoop.js +257 -0
- package/src/core/goalLoop.ts +310 -0
- package/src/entrypoint.js +135 -3
- package/src/entrypoint.ts +136 -3
- package/src/game/causyneCoreBridge.js +686 -0
- package/src/game/causyneCoreBridge.ts +702 -0
- package/src/game/gameLauncher.js +287 -0
- package/src/game/gameLauncher.ts +352 -0
- package/src/game/gameProvisioner.js +425 -0
- package/src/game/gameProvisioner.ts +488 -0
- package/src/headlessCli.js +19 -12
- package/src/headlessCli.ts +22 -8
- package/src/infra/atomicWriter.js +40 -4
- package/src/infra/atomicWriter.ts +36 -4
- package/src/launchIntent.js +73 -3
- package/src/launchIntent.ts +76 -3
- package/src/lsp/lspClient.js +83 -12
- package/src/lsp/lspClient.ts +75 -12
- package/src/mcp/mcpRegistry.js +75 -8
- package/src/mcp/mcpRegistry.ts +70 -7
- package/src/memory/contextBudget.js +2 -0
- package/src/memory/contextBudget.ts +1 -0
- package/src/memory/episodicStore.js +40 -0
- package/src/memory/episodicStore.ts +46 -0
- package/src/memory.js +67 -0
- package/src/memory.ts +65 -0
- package/src/modelVariants.js +45 -0
- package/src/modelVariants.ts +54 -0
- package/src/outputRecovery.js +3 -2
- package/src/outputRecovery.ts +4 -2
- package/src/permissionPresets.js +327 -0
- package/src/permissionPresets.ts +361 -0
- package/src/personalization.js +365 -0
- package/src/personalization.ts +471 -0
- package/src/projectInstructions.js +30 -10
- package/src/projectInstructions.ts +31 -12
- package/src/providers/acp.js +3 -2
- package/src/providers/acp.ts +3 -2
- package/src/providers/antigravity.js +64 -9
- package/src/providers/antigravity.ts +75 -9
- package/src/providers/byokHttp.js +7 -1
- package/src/providers/byokHttp.ts +6 -1
- package/src/providers/byokStream.js +21 -8
- package/src/providers/byokStream.ts +17 -7
- package/src/providers/dashscope-byok.js +21 -5
- package/src/providers/dashscope-byok.ts +29 -11
- package/src/providers/moonshot.js +26 -7
- package/src/providers/moonshot.ts +34 -13
- package/src/providers/muse.js +6 -0
- package/src/providers/muse.ts +8 -0
- package/src/providers/ollama.js +39 -7
- package/src/providers/ollama.ts +36 -7
- package/src/providers/openai-compatible.js +16 -3
- package/src/providers/openai-compatible.ts +13 -3
- package/src/providers/openai.js +62 -4
- package/src/providers/openai.ts +50 -4
- package/src/providers/openrouter.js +19 -4
- package/src/providers/openrouter.ts +21 -4
- package/src/providers/qwen-byok.js +21 -5
- package/src/providers/qwen-byok.ts +29 -11
- package/src/providers/xai.js +26 -10
- package/src/providers/xai.ts +34 -16
- package/src/reporting.js +4 -2
- package/src/reporting.ts +4 -2
- package/src/sandbox.js +34 -0
- package/src/sandbox.ts +43 -0
- package/src/scheduler/scheduler.js +372 -0
- package/src/scheduler/scheduler.ts +433 -0
- package/src/sessionSearchIndex.js +267 -0
- package/src/sessionSearchIndex.ts +311 -0
- package/src/skillsManager.js +2 -3
- package/src/skillsManager.ts +2 -3
- package/src/toolPacks.js +6 -0
- package/src/toolPacks.ts +6 -0
- package/src/tools/applyPatch.js +1 -1
- package/src/tools/applyPatch.ts +1 -1
- package/src/tools/generateMediaViaApi.js +4 -3
- package/src/tools/generateMediaViaApi.ts +4 -3
- package/src/tools/memoryWrite.js +15 -1
- package/src/tools/memoryWrite.ts +16 -1
- package/src/tools/nativeEngine.js +2 -2
- package/src/tools/nativeEngine.ts +2 -2
- package/src/tools/openSourceToolProvisioner.js +2 -2
- package/src/tools/openSourceToolProvisioner.ts +2 -2
- package/src/tools/osSandbox.js +1 -1
- package/src/tools/osSandbox.ts +1 -1
- package/src/tools/payloadSanitizer.js +0 -1
- package/src/tools/payloadSanitizer.ts +0 -1
- package/src/tools/pdfReader.js +122 -20
- package/src/tools/pdfReader.ts +111 -20
- package/src/tools/presentDeliverable.js +103 -0
- package/src/tools/presentDeliverable.ts +127 -0
- package/src/tools/ptcRuntime.js +444 -0
- package/src/tools/ptcRuntime.ts +490 -0
- package/src/tools/ptyTerminal.js +1108 -0
- package/src/tools/ptyTerminal.ts +1245 -0
- package/src/tools/registry.js +21 -12
- package/src/tools/registry.ts +21 -12
- package/src/tools/toolOutputStore.js +26 -4
- package/src/tools/toolOutputStore.ts +22 -4
- package/src/tools/webFetch.js +158 -11
- package/src/tools/webFetch.ts +145 -11
- package/src/tools/webSearch.js +123 -36
- package/src/tools/webSearch.ts +124 -33
- package/src/tui/banner.js +5 -1
- package/src/tui/banner.ts +6 -1
- package/src/tui/chatRenderer.js +1 -2
- package/src/tui/chatRenderer.ts +1 -2
- package/src/tui/completion.js +1 -0
- package/src/tui/completion.ts +1 -0
- package/src/tui/composerControls.js +111 -27
- package/src/tui/composerControls.ts +124 -28
- package/src/tui/dialogs.js +3 -16
- package/src/tui/dialogs.ts +3 -16
- package/src/tui/home.js +1 -0
- package/src/tui/home.ts +1 -0
- package/src/tui/invocation.js +1 -2
- package/src/tui/invocation.ts +1 -2
- package/src/tui/modelPicker.js +22 -12
- package/src/tui/modelPicker.ts +22 -12
- package/src/tui/overlay.js +2 -5
- package/src/tui/overlay.ts +2 -5
- package/src/tui/prompt.js +6 -4
- package/src/tui/prompt.ts +6 -4
- package/src/tui/selectList.js +4 -12
- package/src/tui/selectList.ts +4 -12
- package/src/tui/setup.js +22 -9
- package/src/tui/setup.ts +26 -9
- package/src/tui/statusLine.ts +2 -0
- package/src/web/client/browserPanel.js +905 -0
- package/src/web/client/browserPanel.ts +872 -0
- package/src/web/client/chatStream.js +321 -0
- package/src/web/client/chatStream.ts +297 -0
- package/src/web/client/cliPanel.js +165 -0
- package/src/web/client/cliPanel.ts +171 -0
- package/src/web/client/composer.js +204 -0
- package/src/web/client/composer.ts +209 -0
- package/src/web/client/diffPanel.js +176 -0
- package/src/web/client/diffPanel.ts +203 -0
- package/src/web/client/dom.js +271 -0
- package/src/web/client/dom.ts +272 -0
- package/src/web/client/filesAndCanvas.js +233 -0
- package/src/web/client/filesAndCanvas.ts +240 -0
- package/src/web/client/gameLauncherUi.js +78 -0
- package/src/web/client/gameLauncherUi.ts +78 -0
- package/src/web/client/main.js +316 -0
- package/src/web/client/main.ts +391 -0
- package/src/web/client/markdown.js +364 -0
- package/src/web/client/markdown.ts +373 -0
- package/src/web/client/modelPicker.js +455 -0
- package/src/web/client/modelPicker.ts +451 -0
- package/src/web/client/permissionPresetsUi.js +307 -0
- package/src/web/client/permissionPresetsUi.ts +333 -0
- package/src/web/client/sessions.js +353 -0
- package/src/web/client/sessions.ts +372 -0
- package/src/web/client/settingsModal.js +824 -0
- package/src/web/client/settingsModal.ts +959 -0
- package/src/web/client/state.js +280 -0
- package/src/web/client/state.ts +259 -0
- package/src/web/client/streamSmoother.js +127 -0
- package/src/web/client/streamSmoother.ts +119 -0
- package/src/web/client/studioLayout.js +89 -0
- package/src/web/client/studioLayout.ts +103 -0
- package/src/web/client/studioShell.js +660 -0
- package/src/web/client/studioShell.ts +672 -0
- package/src/web/client/studioStart.js +77 -0
- package/src/web/client/studioStart.ts +89 -0
- package/src/web/client/terminalPanel.js +606 -0
- package/src/web/client/terminalPanel.ts +632 -0
- package/src/web/client/terminalTheme.js +249 -0
- package/src/web/client/terminalTheme.ts +258 -0
- package/src/web/client/turnView.js +934 -0
- package/src/web/client/turnView.ts +981 -0
- package/src/web/client/types.js +1 -0
- package/src/web/client/types.ts +322 -0
- package/src/web/client/validators.js +147 -0
- package/src/web/client/validators.ts +140 -0
- package/src/web/server/activeRuns.js +152 -0
- package/src/web/server/activeRuns.ts +171 -0
- package/src/web/server/routesBrowser.js +409 -0
- package/src/web/server/routesBrowser.ts +435 -0
- package/src/web/server/routesChat.js +304 -0
- package/src/web/server/routesChat.ts +347 -0
- package/src/web/server/routesCore.js +472 -0
- package/src/web/server/routesCore.ts +522 -0
- package/src/web/server/routesSettings.js +344 -0
- package/src/web/server/routesSettings.ts +397 -0
- package/src/web/server/routesTerminal.js +162 -0
- package/src/web/server/routesTerminal.ts +182 -0
- package/src/web/server/routesWorkspace.js +510 -0
- package/src/web/server/routesWorkspace.ts +546 -0
- package/src/web/server/security.js +98 -0
- package/src/web/server/security.ts +108 -0
- package/src/web/server/sessionTranscript.js +586 -0
- package/src/web/server/sessionTranscript.ts +566 -0
- package/src/web/server/staticAssets.js +104 -0
- package/src/web/server/staticAssets.ts +116 -0
- package/src/web/server/types.js +1 -0
- package/src/web/server/types.ts +135 -0
- package/src/web/server/workspaceFiles.js +368 -0
- package/src/web/server/workspaceFiles.ts +363 -0
- package/src/web/skybridgeServer.js +78 -2448
- package/src/web/skybridgeServer.ts +120 -2600
- package/src/web/skybridgeUi.js +20 -450
- package/src/web/skybridgeUi.ts +24 -455
- package/src/web/styles/agent.css +380 -0
- package/src/web/styles/composer.css +193 -0
- package/src/web/styles/overlays.css +935 -0
- package/src/web/styles/shell.css +387 -0
- package/src/web/styles/studio.css +951 -0
- package/src/web/styles/thread.css +221 -0
- package/src/web/styles/tokens.css +94 -0
- package/src/web/ui/brandMark.js +73 -0
- package/src/web/ui/brandMark.ts +82 -0
- package/src/web/ui/modalsTemplate.js +388 -0
- package/src/web/ui/modalsTemplate.ts +388 -0
- package/src/web/ui/sidebarTemplate.js +63 -0
- package/src/web/ui/sidebarTemplate.ts +64 -0
- package/src/web/ui/studioTemplate.js +256 -0
- package/src/web/ui/studioTemplate.ts +256 -0
- package/src/web/ui/workspaceTemplate.js +72 -0
- package/src/web/ui/workspaceTemplate.ts +73 -0
- package/src/worktreeManager.js +16 -1
- package/src/worktreeManager.ts +22 -1
- package/src/web/skybridgeClientScript.js +0 -3951
- package/src/web/skybridgeClientScript.ts +0 -3952
- package/src/web/skybridgeStyles.js +0 -827
- 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
|
|
2
|
+
* Causyne Agent — Hierarchical Project Instructions & Personalization Loader
|
|
3
3
|
*
|
|
4
|
-
* Discovers and merges
|
|
5
|
-
* 1. User global `~/.causyne/CAUSYNE.md` (if
|
|
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
|
-
|
|
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
|
|
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 /
|
|
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
|
|
2
|
+
* Causyne Agent — Hierarchical Project Instructions & Personalization Loader
|
|
3
3
|
*
|
|
4
|
-
* Discovers and merges
|
|
5
|
-
* 1. User global `~/.causyne/CAUSYNE.md` (if
|
|
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
|
-
|
|
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
|
|
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 /
|
|
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 = [
|
package/src/providers/acp.js
CHANGED
|
@@ -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);
|