@causyne/agent 1.20.121 → 1.20.122
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/README.md +3 -3
- package/package.json +1 -1
- package/src/acp/agentCatalog.js +81 -26
- package/src/acp/agentCatalog.ts +73 -29
- package/src/acp/client.js +210 -53
- package/src/acp/client.ts +202 -52
- package/src/acp/peerProfiles.js +55 -22
- package/src/acp/peerProfiles.ts +51 -22
- package/src/acp/protocol.js +37 -8
- package/src/acp/protocol.ts +30 -8
- package/src/acp/server.js +123 -25
- package/src/acp/server.ts +124 -24
- package/src/agent/errorClassifier.js +6 -2
- package/src/agent/errorClassifier.ts +6 -2
- package/src/agentLoop.js +11 -5
- package/src/agentLoop.ts +11 -5
- package/src/approvalGrants.js +19 -7
- package/src/approvalGrants.ts +20 -7
- package/src/approvalPolicy.js +48 -15
- package/src/approvalPolicy.ts +46 -15
- package/src/autoUpdate.js +5 -2
- package/src/autoUpdate.ts +5 -2
- package/src/browser/causyneBrowser.js +3 -2
- package/src/browser/causyneBrowser.ts +3 -2
- package/src/browser/searchProviders.js +1 -1
- package/src/browser/searchProviders.ts +1 -1
- package/src/config.js +287 -250
- package/src/config.ts +342 -0
- package/src/configVault.js +84 -17
- package/src/configVault.ts +77 -17
- package/src/continuum/compactor.js +2 -1
- package/src/continuum/compactor.ts +2 -1
- package/src/continuum/sanitizer.js +10 -3
- package/src/continuum/sanitizer.ts +9 -3
- package/src/continuum/ui/continuumPickerView.js +3 -2
- package/src/continuum/ui/continuumPickerView.ts +3 -2
- package/src/cortex/vectorDb.js +26 -15
- package/src/cortex/vectorDb.ts +26 -16
- package/src/creative/liveBridge.js +7 -5
- package/src/creative/liveBridge.ts +7 -5
- package/src/creative/studioScripts.js +16 -5
- package/src/creative/studioScripts.ts +14 -5
- package/src/decisionPolicy.js +16 -4
- package/src/decisionPolicy.ts +14 -4
- package/src/documentEngine/antiSlopAuditor.js +10 -5
- package/src/documentEngine/antiSlopAuditor.ts +11 -5
- package/src/documentEngine/documentForge.js +47 -15
- package/src/documentEngine/documentForge.ts +43 -14
- package/src/engines/design.js +2 -1
- package/src/engines/design.ts +2 -1
- package/src/engines/film.js +4 -4
- package/src/engines/film.ts +2 -2
- package/src/engines/light.js +2 -1
- package/src/engines/light.ts +2 -1
- package/src/engines/registry.js +1 -1
- package/src/engines/registry.ts +1 -1
- package/src/engines/reverseHarness.js +4 -3
- package/src/engines/reverseHarness.ts +4 -3
- package/src/headlessCli.js +2 -1
- package/src/headlessCli.ts +2 -1
- package/src/historyPruner.js +3 -2
- package/src/historyPruner.ts +3 -2
- package/src/hooks.js +3 -0
- package/src/hooks.ts +3 -0
- package/src/implementationPlan.js +21 -11
- package/src/implementationPlan.ts +21 -11
- package/src/infra/atomicWriter.js +4 -1
- package/src/infra/atomicWriter.ts +4 -1
- package/src/launchIntent.js +1 -1
- package/src/launchIntent.ts +1 -1
- package/src/memory/scopedFacts.js +1 -1
- package/src/memory/scopedFacts.ts +1 -1
- package/src/memory/symbolFolder.js +1 -1
- package/src/memory/symbolFolder.ts +1 -1
- package/src/modelRouter.js +1 -1
- package/src/modelRouter.ts +1 -1
- package/src/observer/evidence.js +10 -4
- package/src/observer/evidence.ts +10 -4
- package/src/osKeychain.js +62 -8
- package/src/osKeychain.ts +50 -8
- package/src/perception.js +3 -2
- package/src/perception.ts +3 -2
- package/src/planCache.js +2 -2
- package/src/planCache.ts +2 -2
- package/src/pluginsFactory/pluginsFactory.js +19 -11
- package/src/pluginsFactory/pluginsFactory.ts +18 -11
- package/src/promptMentions.js +2 -2
- package/src/promptMentions.ts +2 -2
- package/src/providers/acp.js +1 -1
- package/src/providers/acp.ts +1 -1
- package/src/providers/anthropic.js +327 -401
- package/src/providers/anthropic.ts +386 -0
- package/src/providers/antigravity.js +10 -4
- package/src/providers/antigravity.ts +10 -4
- package/src/providers/base.js +221 -319
- package/src/providers/base.ts +340 -0
- package/src/providers/byokHttp.js +58 -15
- package/src/providers/byokHttp.ts +59 -16
- package/src/providers/byokStream.js +142 -51
- package/src/providers/byokStream.ts +146 -42
- package/src/providers/dashscope-byok.js +97 -89
- package/src/providers/dashscope-byok.ts +114 -0
- package/src/providers/deepseek.js +73 -72
- package/src/providers/deepseek.ts +99 -0
- package/src/providers/factory.js +35 -28
- package/src/providers/factory.ts +40 -0
- package/src/providers/gemini.js +227 -278
- package/src/providers/gemini.ts +261 -0
- package/src/providers/loopGuard.js +9 -5
- package/src/providers/loopGuard.ts +10 -5
- package/src/providers/moonshot.js +70 -72
- package/src/providers/moonshot.ts +93 -0
- package/src/providers/muse.js +82 -152
- package/src/providers/muse.ts +122 -0
- package/src/providers/ollama.js +114 -106
- package/src/providers/ollama.ts +135 -0
- package/src/providers/openai-compatible.js +113 -96
- package/src/providers/openai-compatible.ts +139 -0
- package/src/providers/openai.js +22 -15
- package/src/providers/openai.ts +30 -0
- package/src/providers/openrouter.js +136 -74
- package/src/providers/openrouter.ts +133 -72
- package/src/providers/pi.js +6 -0
- package/src/providers/pi.ts +6 -0
- package/src/providers/qwen-byok.js +96 -87
- package/src/providers/qwen-byok.ts +113 -0
- package/src/providers/toolContracts.js +40 -14
- package/src/providers/toolContracts.ts +35 -14
- package/src/providers/wireNormalizer.js +78 -11
- package/src/providers/wireNormalizer.ts +68 -12
- package/src/providers/xai.js +73 -72
- package/src/providers/xai.ts +97 -0
- package/src/reliability/assetEvidence.js +4 -2
- package/src/reliability/assetEvidence.ts +4 -2
- package/src/sandbox.js +489 -554
- package/src/sandbox.ts +552 -0
- package/src/sandboxPolicy.js +95 -16
- package/src/sandboxPolicy.ts +97 -16
- package/src/sessionJournal.js +8 -3
- package/src/sessionJournal.ts +9 -3
- package/src/skills/skillResourceSafety.js +19 -8
- package/src/skills/skillResourceSafety.ts +16 -7
- package/src/skillsManager.js +3 -3
- package/src/skillsManager.ts +3 -3
- package/src/smartToolsUse.js +28 -4
- package/src/smartToolsUse.ts +29 -7
- package/src/stallGuard.js +45 -22
- package/src/stallGuard.ts +46 -22
- package/src/subagentJournal.js +6 -4
- package/src/subagentJournal.ts +6 -4
- package/src/textDiff.js +6 -1
- package/src/textDiff.ts +6 -1
- package/src/timeMachine.js +7 -1
- package/src/timeMachine.ts +7 -1
- package/src/tokenTracker.js +43 -28
- package/src/tokenTracker.ts +44 -30
- package/src/toolPacks.js +3 -1
- package/src/toolPacks.ts +3 -1
- package/src/tools/archive.js +245 -35
- package/src/tools/archive.ts +244 -35
- package/src/tools/computerUse.js +7 -3
- package/src/tools/computerUse.ts +7 -3
- package/src/tools/creativeApps.js +13 -8
- package/src/tools/creativeApps.ts +22 -9
- package/src/tools/deferredMcpSearch.js +26 -14
- package/src/tools/deferredMcpSearch.ts +26 -14
- package/src/tools/desktopOpen.js +69 -10
- package/src/tools/desktopOpen.ts +70 -11
- package/src/tools/documentForge.js +167 -82
- package/src/tools/documentForge.ts +169 -84
- package/src/tools/fsEdit.js +101 -30
- package/src/tools/fsEdit.ts +105 -32
- package/src/tools/fsFind.js +8 -5
- package/src/tools/fsFind.ts +7 -4
- package/src/tools/fsRead.js +119 -13
- package/src/tools/fsRead.ts +124 -13
- package/src/tools/fsWrite.js +17 -5
- package/src/tools/fsWrite.ts +17 -7
- package/src/tools/generateMediaViaApi.js +82 -19
- package/src/tools/generateMediaViaApi.ts +80 -19
- package/src/tools/memoryRecall.js +62 -11
- package/src/tools/memoryRecall.ts +70 -13
- package/src/tools/memoryWrite.js +27 -14
- package/src/tools/memoryWrite.ts +30 -14
- package/src/tools/multiEdit.js +100 -30
- package/src/tools/multiEdit.ts +104 -32
- package/src/tools/nativeEngine.js +33 -18
- package/src/tools/nativeEngine.ts +31 -18
- package/src/tools/openSourceToolProvisioner.js +49 -14
- package/src/tools/openSourceToolProvisioner.ts +54 -15
- package/src/tools/osSandbox.js +54 -14
- package/src/tools/osSandbox.ts +48 -14
- package/src/tools/payloadSanitizer.js +40 -8
- package/src/tools/payloadSanitizer.ts +39 -8
- package/src/tools/peerAgent.js +96 -34
- package/src/tools/peerAgent.ts +114 -37
- package/src/tools/pluginsFactory.js +38 -6
- package/src/tools/pluginsFactory.ts +42 -6
- package/src/tools/readNativeSkill.js +10 -8
- package/src/tools/readNativeSkill.ts +10 -8
- package/src/tools/requestDecision.js +10 -3
- package/src/tools/requestDecision.ts +10 -3
- package/src/tools/resolveAutomator.js +91 -17
- package/src/tools/resolveAutomator.ts +102 -17
- package/src/tools/reverseEngineering.js +168 -41
- package/src/tools/reverseEngineering.ts +161 -41
- package/src/tools/sysRun.js +69 -29
- package/src/tools/sysRun.ts +66 -24
- package/src/tools/toolDispatch.js +24 -1
- package/src/tools/toolDispatch.ts +21 -1
- package/src/tools/toolOutputStore.js +62 -23
- package/src/tools/toolOutputStore.ts +56 -23
- package/src/tools/toolScanner.js +13 -10
- package/src/tools/toolScanner.ts +13 -10
- package/src/tools/toolSelfRepair.js +94 -28
- package/src/tools/toolSelfRepair.ts +96 -28
- package/src/tools/uiForge.js +71 -6
- package/src/tools/uiForge.ts +74 -6
- package/src/tools/viewImage.js +62 -17
- package/src/tools/viewImage.ts +57 -12
- package/src/tools/visionInspector.js +15 -3
- package/src/tools/visionInspector.ts +15 -3
- package/src/tools/walkerSafety.js +2 -0
- package/src/tools/walkerSafety.ts +1 -0
- package/src/tools/webFetch.js +105 -10
- package/src/tools/webFetch.ts +105 -11
- package/src/tui/banner.js +3 -2
- package/src/tui/banner.ts +3 -2
- package/src/tui/consoleGuard.js +12 -4
- package/src/tui/consoleGuard.ts +9 -4
- package/src/tui/messageInteraction.js +2 -3
- package/src/tui/messageInteraction.ts +2 -3
- package/src/tui/modelPicker.js +1 -0
- package/src/tui/modelPicker.ts +1 -0
- package/src/tui/overlay.js +3 -1
- package/src/tui/overlay.ts +3 -1
- package/src/tui/sessionPicker.js +3 -2
- package/src/tui/sessionPicker.ts +3 -2
- package/src/tui/sessionPickerView.js +7 -1
- package/src/tui/sessionPickerView.ts +6 -1
- package/src/tui/toolOutputNormalizer.js +2 -3
- package/src/tui/toolOutputNormalizer.ts +4 -3
- package/src/tui/viewport.js +4 -4
- package/src/tui/viewport.ts +5 -5
- package/src/tui/workspaceIdentity.js +2 -1
- package/src/tui/workspaceIdentity.ts +2 -1
- package/src/uncertainty.js +8 -3
- package/src/uncertainty.ts +8 -3
- package/src/utils/paths.js +8 -5
- package/src/utils/paths.ts +9 -7
- package/src/vfeTracker.js +9 -3
- package/src/vfeTracker.ts +9 -3
- package/src/config.d.ts +0 -2
- package/src/providers/base.d.ts +0 -94
- package/src/providers/factory.d.ts +0 -1
- package/src/sandbox.d.ts +0 -1
package/src/configVault.ts
CHANGED
|
@@ -24,15 +24,25 @@ export const VAULT_GCM_IV_BYTES = 12;
|
|
|
24
24
|
export const VAULT_LEGACY_GCM_IV_BYTES = 16;
|
|
25
25
|
export const VAULT_GCM_AUTH_TAG_BYTES = 16;
|
|
26
26
|
export const VAULT_ENC_PREFIX = 'ENC:';
|
|
27
|
+
const MAX_SECRET_HEX_CHARS = 1_048_576;
|
|
28
|
+
const STRICT_HEX_PATTERN = /^[0-9a-fA-F]+$/;
|
|
27
29
|
|
|
28
30
|
export function isEncryptedVaultSecret(value: unknown): value is string {
|
|
29
31
|
return typeof value === 'string' && value.startsWith(VAULT_ENC_PREFIX);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export function ensureVaultDir(dir: string): void {
|
|
35
|
+
if (typeof dir !== 'string' || !dir.trim() || dir.includes('\0')) {
|
|
36
|
+
throw new Error('Invalid vault directory path');
|
|
37
|
+
}
|
|
33
38
|
const resolved = path.resolve(dir);
|
|
34
39
|
if (!fs.existsSync(resolved)) {
|
|
35
40
|
fs.mkdirSync(resolved, { recursive: true, mode: 0o700 });
|
|
41
|
+
} else {
|
|
42
|
+
const stat = fs.lstatSync(resolved);
|
|
43
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
44
|
+
throw new Error('Refusing to use symlink or non-directory as vault directory');
|
|
45
|
+
}
|
|
36
46
|
}
|
|
37
47
|
if (process.platform !== 'win32') {
|
|
38
48
|
try {
|
|
@@ -48,18 +58,33 @@ export function ensureVaultDir(dir: string): void {
|
|
|
48
58
|
* a unique sibling temporary file with mode `0o600` followed by atomic rename.
|
|
49
59
|
*/
|
|
50
60
|
export function atomicWriteSecretFileSync(targetPath: string, content: string | Buffer): void {
|
|
61
|
+
if (typeof targetPath !== 'string' || !targetPath.trim() || targetPath.includes('\0')) {
|
|
62
|
+
throw new Error('Invalid secret target file path');
|
|
63
|
+
}
|
|
51
64
|
const resolved = path.resolve(targetPath);
|
|
52
65
|
const dir = path.dirname(resolved);
|
|
53
66
|
ensureVaultDir(dir);
|
|
67
|
+
try {
|
|
68
|
+
const existing = fs.lstatSync(resolved);
|
|
69
|
+
if (existing.isSymbolicLink() || !existing.isFile()) {
|
|
70
|
+
throw new Error('Refusing to overwrite symlink or non-regular secret file');
|
|
71
|
+
}
|
|
72
|
+
} catch (err: unknown) {
|
|
73
|
+
const code = typeof err === 'object' && err !== null && 'code' in err ? String(err.code) : '';
|
|
74
|
+
if (code !== 'ENOENT') throw err;
|
|
75
|
+
}
|
|
54
76
|
|
|
55
77
|
const suffix = `${process.pid}.${crypto.randomBytes(6).toString('hex')}`;
|
|
56
78
|
const tempPath = path.join(dir, `.${path.basename(resolved)}.${suffix}.tmp`);
|
|
57
79
|
|
|
58
80
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
fs.
|
|
81
|
+
const payload = typeof content === 'string' ? Buffer.from(content, 'utf8') : content;
|
|
82
|
+
const fd = fs.openSync(tempPath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY, 0o600);
|
|
83
|
+
try {
|
|
84
|
+
fs.writeSync(fd, payload, 0, payload.length);
|
|
85
|
+
fs.fsyncSync(fd);
|
|
86
|
+
} finally {
|
|
87
|
+
fs.closeSync(fd);
|
|
63
88
|
}
|
|
64
89
|
if (process.platform !== 'win32') {
|
|
65
90
|
try {
|
|
@@ -108,6 +133,10 @@ export function getOrCreateVaultKey(
|
|
|
108
133
|
|
|
109
134
|
// If a file key already exists, migrate it cleanly into the OS Keychain
|
|
110
135
|
if (fs.existsSync(resolved)) {
|
|
136
|
+
const stat = fs.lstatSync(resolved);
|
|
137
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
138
|
+
throw new Error('Refusing to read symlink or non-regular vault key file.');
|
|
139
|
+
}
|
|
111
140
|
const existingFileKey = fs.readFileSync(resolved);
|
|
112
141
|
if (existingFileKey.length === VAULT_KEY_BYTES) {
|
|
113
142
|
const stored = saveVaultKeyToKeychain(vaultDir, existingFileKey, keychainOptions);
|
|
@@ -130,6 +159,10 @@ export function getOrCreateVaultKey(
|
|
|
130
159
|
}
|
|
131
160
|
|
|
132
161
|
if (fs.existsSync(resolved)) {
|
|
162
|
+
const stat = fs.lstatSync(resolved);
|
|
163
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
164
|
+
throw new Error('Refusing to read symlink or non-regular vault key file.');
|
|
165
|
+
}
|
|
133
166
|
if (process.platform !== 'win32') {
|
|
134
167
|
try {
|
|
135
168
|
fs.chmodSync(resolved, 0o600);
|
|
@@ -159,6 +192,17 @@ export function getOrCreateVaultKey(
|
|
|
159
192
|
} catch (err: unknown) {
|
|
160
193
|
const code = typeof err === 'object' && err !== null && 'code' in err ? String(err.code) : '';
|
|
161
194
|
if (code === 'EEXIST') {
|
|
195
|
+
const stat = fs.lstatSync(resolved);
|
|
196
|
+
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
197
|
+
throw new Error('Refusing to read symlink or non-regular vault key file.');
|
|
198
|
+
}
|
|
199
|
+
if (process.platform !== 'win32') {
|
|
200
|
+
try {
|
|
201
|
+
fs.chmodSync(resolved, 0o600);
|
|
202
|
+
} catch {
|
|
203
|
+
// Ignore chmod errors
|
|
204
|
+
}
|
|
205
|
+
}
|
|
162
206
|
const raced = fs.readFileSync(resolved);
|
|
163
207
|
if (raced.length === VAULT_KEY_BYTES) return raced;
|
|
164
208
|
}
|
|
@@ -170,15 +214,19 @@ export function getOrCreateVaultKey(
|
|
|
170
214
|
* Encrypts a plaintext secret using AES-256-GCM with a NIST-standard 12-byte IV.
|
|
171
215
|
*/
|
|
172
216
|
export function encryptVaultSecret(text: string, keyFilePath: string): string {
|
|
173
|
-
if (!text) return text;
|
|
217
|
+
if (typeof text !== 'string' || !text) return text;
|
|
174
218
|
if (isEncryptedVaultSecret(text)) return text;
|
|
175
219
|
const key = getOrCreateVaultKey(keyFilePath);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
220
|
+
try {
|
|
221
|
+
const iv = crypto.randomBytes(VAULT_GCM_IV_BYTES);
|
|
222
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
|
|
223
|
+
let encrypted = cipher.update(text, 'utf8', 'hex');
|
|
224
|
+
encrypted += cipher.final('hex');
|
|
225
|
+
const authTag = cipher.getAuthTag().toString('hex');
|
|
226
|
+
return `${VAULT_ENC_PREFIX}${iv.toString('hex')}:${authTag}:${encrypted}`;
|
|
227
|
+
} finally {
|
|
228
|
+
key.fill(0);
|
|
229
|
+
}
|
|
182
230
|
}
|
|
183
231
|
|
|
184
232
|
/**
|
|
@@ -186,22 +234,32 @@ export function encryptVaultSecret(text: string, keyFilePath: string): string {
|
|
|
186
234
|
* or legacy 16-byte GCM IV. Returns empty string on authentication failure.
|
|
187
235
|
*/
|
|
188
236
|
export function decryptVaultSecret(encryptedText: string, keyFilePath: string): string {
|
|
189
|
-
if (
|
|
237
|
+
if (typeof encryptedText !== 'string' || !encryptedText) return '';
|
|
238
|
+
if (!isEncryptedVaultSecret(encryptedText)) return encryptedText;
|
|
239
|
+
if (encryptedText.length > MAX_SECRET_HEX_CHARS) return '';
|
|
240
|
+
let key: Buffer | null = null;
|
|
190
241
|
try {
|
|
191
242
|
const parts = encryptedText.split(':');
|
|
192
243
|
if (parts.length !== 4) return '';
|
|
193
244
|
const ivHex = parts[1] ?? '';
|
|
194
245
|
const authTagHex = parts[2] ?? '';
|
|
195
246
|
const ciphertextHex = parts[3] ?? '';
|
|
196
|
-
const iv = Buffer.from(ivHex, 'hex');
|
|
197
|
-
const authTag = Buffer.from(authTagHex, 'hex');
|
|
198
247
|
if (
|
|
199
|
-
(
|
|
200
|
-
|
|
248
|
+
!STRICT_HEX_PATTERN.test(ivHex) ||
|
|
249
|
+
!STRICT_HEX_PATTERN.test(authTagHex) ||
|
|
250
|
+
(ciphertextHex.length > 0 && (ciphertextHex.length % 2 !== 0 || !STRICT_HEX_PATTERN.test(ciphertextHex)))
|
|
201
251
|
) {
|
|
202
252
|
return '';
|
|
203
253
|
}
|
|
204
|
-
|
|
254
|
+
if (
|
|
255
|
+
(ivHex.length !== VAULT_GCM_IV_BYTES * 2 && ivHex.length !== VAULT_LEGACY_GCM_IV_BYTES * 2) ||
|
|
256
|
+
authTagHex.length !== VAULT_GCM_AUTH_TAG_BYTES * 2
|
|
257
|
+
) {
|
|
258
|
+
return '';
|
|
259
|
+
}
|
|
260
|
+
const iv = Buffer.from(ivHex, 'hex');
|
|
261
|
+
const authTag = Buffer.from(authTagHex, 'hex');
|
|
262
|
+
key = getOrCreateVaultKey(keyFilePath);
|
|
205
263
|
const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv);
|
|
206
264
|
decipher.setAuthTag(authTag);
|
|
207
265
|
let decrypted = decipher.update(ciphertextHex, 'hex', 'utf8');
|
|
@@ -209,5 +267,7 @@ export function decryptVaultSecret(encryptedText: string, keyFilePath: string):
|
|
|
209
267
|
return decrypted;
|
|
210
268
|
} catch {
|
|
211
269
|
return '';
|
|
270
|
+
} finally {
|
|
271
|
+
if (key) key.fill(0);
|
|
212
272
|
}
|
|
213
273
|
}
|
|
@@ -15,7 +15,8 @@ export function compactContinuumMessages(messages, options = {}) {
|
|
|
15
15
|
const rootMessage = rootIndex !== -1
|
|
16
16
|
? messages[rootIndex]
|
|
17
17
|
: { role: 'user', content: 'Initial user turn' };
|
|
18
|
-
const
|
|
18
|
+
const safeRecent = Number.isFinite(recentTurns) ? Math.max(0, Math.min(messages.length, Math.floor(recentTurns))) : 12;
|
|
19
|
+
const recentStart = Math.max(0, messages.length - safeRecent);
|
|
19
20
|
const recent = messages.slice(recentStart);
|
|
20
21
|
// If the root intent is already within the recent window, simply return recent
|
|
21
22
|
if (rootIndex !== -1 && rootIndex >= recentStart) {
|
|
@@ -32,7 +32,8 @@ export function compactContinuumMessages(
|
|
|
32
32
|
? messages[rootIndex]!
|
|
33
33
|
: { role: 'user', content: 'Initial user turn' };
|
|
34
34
|
|
|
35
|
-
const
|
|
35
|
+
const safeRecent = Number.isFinite(recentTurns) ? Math.max(0, Math.min(messages.length, Math.floor(recentTurns))) : 12;
|
|
36
|
+
const recentStart = Math.max(0, messages.length - safeRecent);
|
|
36
37
|
const recent = messages.slice(recentStart);
|
|
37
38
|
|
|
38
39
|
// If the root intent is already within the recent window, simply return recent
|
|
@@ -39,12 +39,19 @@ export function cleanUserText(text) {
|
|
|
39
39
|
export function cleanAssistantText(text, maxChars = 2000) {
|
|
40
40
|
if (!text)
|
|
41
41
|
return '';
|
|
42
|
+
const limit = Number.isFinite(maxChars) ? Math.max(0, Math.floor(maxChars)) : 2000;
|
|
43
|
+
if (limit === 0)
|
|
44
|
+
return '';
|
|
42
45
|
const str = String(text).trim();
|
|
43
|
-
|
|
46
|
+
const chars = Array.from(str);
|
|
47
|
+
if (chars.length <= limit) {
|
|
44
48
|
return str;
|
|
45
49
|
}
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
if (limit === 1) {
|
|
51
|
+
return chars[0] ?? '';
|
|
52
|
+
}
|
|
53
|
+
const half = Math.floor(limit / 2);
|
|
54
|
+
return `${chars.slice(0, half).join('')}\n\n... [output condensed for context efficiency] ...\n\n${chars.slice(-half).join('')}`;
|
|
48
55
|
}
|
|
49
56
|
/** Extract a clean, meaningful title from the first user request. */
|
|
50
57
|
export function deriveSessionTitle(firstPrompt, fallback = 'Untitled Session') {
|
|
@@ -43,12 +43,18 @@ export function cleanUserText(text: unknown): string {
|
|
|
43
43
|
/** Summarize and truncate excessive tool dump text while preserving answer & rationale. */
|
|
44
44
|
export function cleanAssistantText(text: unknown, maxChars = 2000): string {
|
|
45
45
|
if (!text) return '';
|
|
46
|
+
const limit = Number.isFinite(maxChars) ? Math.max(0, Math.floor(maxChars)) : 2000;
|
|
47
|
+
if (limit === 0) return '';
|
|
46
48
|
const str = String(text).trim();
|
|
47
|
-
|
|
49
|
+
const chars = Array.from(str);
|
|
50
|
+
if (chars.length <= limit) {
|
|
48
51
|
return str;
|
|
49
52
|
}
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
if (limit === 1) {
|
|
54
|
+
return chars[0] ?? '';
|
|
55
|
+
}
|
|
56
|
+
const half = Math.floor(limit / 2);
|
|
57
|
+
return `${chars.slice(0, half).join('')}\n\n... [output condensed for context efficiency] ...\n\n${chars.slice(-half).join('')}`;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
/** Extract a clean, meaningful title from the first user request. */
|
|
@@ -62,7 +62,8 @@ function pairedRow(left, right, columns) {
|
|
|
62
62
|
return title + ' '.repeat(Math.max(1, width - visibleWidth(title) - rightWidth)) + right;
|
|
63
63
|
}
|
|
64
64
|
function sourceName(value) {
|
|
65
|
-
|
|
65
|
+
const platformName = Object.hasOwn(PLATFORM_NAMES, value.sourcePlatform) ? PLATFORM_NAMES[value.sourcePlatform] : undefined;
|
|
66
|
+
return clean(value.sourceLabel) || platformName || 'Other';
|
|
66
67
|
}
|
|
67
68
|
/**
|
|
68
69
|
* Group by agent with recency inside each source. A stable tie-breaker means
|
|
@@ -201,7 +202,7 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
201
202
|
const h = Number.isFinite(height) ? Math.max(1, Math.min(200, Math.floor(height))) : 1;
|
|
202
203
|
const rows = [];
|
|
203
204
|
const scope = this.scope;
|
|
204
|
-
const label = scope === 'all' ? 'ALL SOURCES' : PLATFORM_NAMES[scope];
|
|
205
|
+
const label = scope === 'all' ? 'ALL SOURCES' : (Object.hasOwn(PLATFORM_NAMES, scope) ? PLATFORM_NAMES[scope] : 'Other');
|
|
205
206
|
const filtered = this.list.filtered;
|
|
206
207
|
const count = filtered.length;
|
|
207
208
|
const total = this.items.length;
|
|
@@ -96,7 +96,8 @@ function pairedRow(left: string, right: string, columns: number): string {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
function sourceName(value: ContinuumSessionSummary): string {
|
|
99
|
-
|
|
99
|
+
const platformName = Object.hasOwn(PLATFORM_NAMES, value.sourcePlatform) ? PLATFORM_NAMES[value.sourcePlatform] : undefined;
|
|
100
|
+
return clean(value.sourceLabel) || platformName || 'Other';
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
/**
|
|
@@ -262,7 +263,7 @@ export class ContinuumPickerLayer extends SelectLayer {
|
|
|
262
263
|
const h = Number.isFinite(height) ? Math.max(1, Math.min(200, Math.floor(height))) : 1;
|
|
263
264
|
const rows: string[] = [];
|
|
264
265
|
const scope = this.scope;
|
|
265
|
-
const label = scope === 'all' ? 'ALL SOURCES' : PLATFORM_NAMES[scope];
|
|
266
|
+
const label = scope === 'all' ? 'ALL SOURCES' : (Object.hasOwn(PLATFORM_NAMES, scope) ? PLATFORM_NAMES[scope] : 'Other');
|
|
266
267
|
const filtered = this.list.filtered;
|
|
267
268
|
const count = filtered.length;
|
|
268
269
|
const total = this.items.length;
|
package/src/cortex/vectorDb.js
CHANGED
|
@@ -75,24 +75,35 @@ export class VectorDB {
|
|
|
75
75
|
isInitialized = false;
|
|
76
76
|
isNeural = false;
|
|
77
77
|
db = null;
|
|
78
|
+
ensureDbPromise = null;
|
|
78
79
|
async ensureDb() {
|
|
79
80
|
if (this.db)
|
|
80
81
|
return;
|
|
81
|
-
if (
|
|
82
|
-
|
|
82
|
+
if (this.ensureDbPromise)
|
|
83
|
+
return this.ensureDbPromise;
|
|
84
|
+
this.ensureDbPromise = (async () => {
|
|
85
|
+
if (!fs.existsSync(CORTEX_DIR)) {
|
|
86
|
+
fs.mkdirSync(CORTEX_DIR, { recursive: true, mode: 0o700 });
|
|
87
|
+
}
|
|
88
|
+
this.db = await openCortexDatabase(CORTEX_DB_FILE);
|
|
89
|
+
// Create the task_memories table if it doesn't exist
|
|
90
|
+
// embedding_vector is stored as a JSON string array of floats
|
|
91
|
+
this.db.exec(`
|
|
92
|
+
CREATE TABLE IF NOT EXISTS task_memories (
|
|
93
|
+
id TEXT PRIMARY KEY,
|
|
94
|
+
text TEXT NOT NULL,
|
|
95
|
+
embedding_vector TEXT NOT NULL,
|
|
96
|
+
timestamp INTEGER NOT NULL
|
|
97
|
+
)
|
|
98
|
+
`);
|
|
99
|
+
this.migrateSchema();
|
|
100
|
+
})();
|
|
101
|
+
try {
|
|
102
|
+
await this.ensureDbPromise;
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
this.ensureDbPromise = null;
|
|
83
106
|
}
|
|
84
|
-
this.db = await openCortexDatabase(CORTEX_DB_FILE);
|
|
85
|
-
// Create the task_memories table if it doesn't exist
|
|
86
|
-
// embedding_vector is stored as a JSON string array of floats
|
|
87
|
-
this.db.exec(`
|
|
88
|
-
CREATE TABLE IF NOT EXISTS task_memories (
|
|
89
|
-
id TEXT PRIMARY KEY,
|
|
90
|
-
text TEXT NOT NULL,
|
|
91
|
-
embedding_vector TEXT NOT NULL,
|
|
92
|
-
timestamp INTEGER NOT NULL
|
|
93
|
-
)
|
|
94
|
-
`);
|
|
95
|
-
this.migrateSchema();
|
|
96
107
|
}
|
|
97
108
|
/**
|
|
98
109
|
* Bring an existing store up to the current schema, additively.
|
|
@@ -224,7 +235,7 @@ export class VectorDB {
|
|
|
224
235
|
const ageMs = Math.max(0, now - (memory.timestamp || 0));
|
|
225
236
|
// OBLIVION: S = BASE_HALF_LIFE * (1 + hits * REINFORCEMENT_ALPHA) * tierMultiplier
|
|
226
237
|
// R = e^(-t/S) — adaptive retention that rewards reinforced memories with slower decay
|
|
227
|
-
const tierMult = TIER_MULTIPLIERS[memory.kind]
|
|
238
|
+
const tierMult = Object.hasOwn(TIER_MULTIPLIERS, memory.kind) ? TIER_MULTIPLIERS[memory.kind] : 1.0;
|
|
228
239
|
const stability = Math.max(1, RECENCY_HALF_LIFE_MS * (1 + (memory.hits || 0) * REINFORCEMENT_ALPHA) * tierMult);
|
|
229
240
|
const retention = Math.exp(-ageMs / stability);
|
|
230
241
|
scored.push({
|
package/src/cortex/vectorDb.ts
CHANGED
|
@@ -123,28 +123,38 @@ export class VectorDB {
|
|
|
123
123
|
public isInitialized: boolean = false;
|
|
124
124
|
public isNeural: boolean = false;
|
|
125
125
|
public db: CortexDatabase | null = null;
|
|
126
|
+
private ensureDbPromise: Promise<void> | null = null;
|
|
126
127
|
|
|
127
128
|
async ensureDb(): Promise<void> {
|
|
128
129
|
if (this.db) return;
|
|
130
|
+
if (this.ensureDbPromise) return this.ensureDbPromise;
|
|
129
131
|
|
|
130
|
-
|
|
131
|
-
fs.
|
|
132
|
-
|
|
132
|
+
this.ensureDbPromise = (async () => {
|
|
133
|
+
if (!fs.existsSync(CORTEX_DIR)) {
|
|
134
|
+
fs.mkdirSync(CORTEX_DIR, { recursive: true, mode: 0o700 });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
this.db = await openCortexDatabase(CORTEX_DB_FILE);
|
|
133
138
|
|
|
134
|
-
|
|
139
|
+
// Create the task_memories table if it doesn't exist
|
|
140
|
+
// embedding_vector is stored as a JSON string array of floats
|
|
141
|
+
this.db.exec(`
|
|
142
|
+
CREATE TABLE IF NOT EXISTS task_memories (
|
|
143
|
+
id TEXT PRIMARY KEY,
|
|
144
|
+
text TEXT NOT NULL,
|
|
145
|
+
embedding_vector TEXT NOT NULL,
|
|
146
|
+
timestamp INTEGER NOT NULL
|
|
147
|
+
)
|
|
148
|
+
`);
|
|
135
149
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this.db.exec(`
|
|
139
|
-
CREATE TABLE IF NOT EXISTS task_memories (
|
|
140
|
-
id TEXT PRIMARY KEY,
|
|
141
|
-
text TEXT NOT NULL,
|
|
142
|
-
embedding_vector TEXT NOT NULL,
|
|
143
|
-
timestamp INTEGER NOT NULL
|
|
144
|
-
)
|
|
145
|
-
`);
|
|
150
|
+
this.migrateSchema();
|
|
151
|
+
})();
|
|
146
152
|
|
|
147
|
-
|
|
153
|
+
try {
|
|
154
|
+
await this.ensureDbPromise;
|
|
155
|
+
} finally {
|
|
156
|
+
this.ensureDbPromise = null;
|
|
157
|
+
}
|
|
148
158
|
}
|
|
149
159
|
|
|
150
160
|
/**
|
|
@@ -299,7 +309,7 @@ export class VectorDB {
|
|
|
299
309
|
const ageMs = Math.max(0, now - (memory.timestamp || 0));
|
|
300
310
|
// OBLIVION: S = BASE_HALF_LIFE * (1 + hits * REINFORCEMENT_ALPHA) * tierMultiplier
|
|
301
311
|
// R = e^(-t/S) — adaptive retention that rewards reinforced memories with slower decay
|
|
302
|
-
const tierMult = TIER_MULTIPLIERS[memory.kind]
|
|
312
|
+
const tierMult = Object.hasOwn(TIER_MULTIPLIERS, memory.kind) ? TIER_MULTIPLIERS[memory.kind]! : 1.0;
|
|
303
313
|
const stability = Math.max(1, RECENCY_HALF_LIFE_MS * (1 + (memory.hits || 0) * REINFORCEMENT_ALPHA) * tierMult);
|
|
304
314
|
const retention = Math.exp(-ageMs / stability);
|
|
305
315
|
scored.push({
|
|
@@ -124,7 +124,7 @@ export function validateAdobeLiveJob(value) {
|
|
|
124
124
|
}
|
|
125
125
|
const raw = value;
|
|
126
126
|
const hostInput = String(raw.host ?? 'photoshop').trim().toLowerCase();
|
|
127
|
-
const canonicalHost = ADOBE_HOST_ALIASES[hostInput];
|
|
127
|
+
const canonicalHost = Object.hasOwn(ADOBE_HOST_ALIASES, hostInput) ? ADOBE_HOST_ALIASES[hostInput] : undefined;
|
|
128
128
|
if (!canonicalHost) {
|
|
129
129
|
throw new Error(`Unsupported Adobe host "${String(raw.host)}". Supported hosts: photoshop, premiere, after-effects, illustrator, indesign, media-encoder.`);
|
|
130
130
|
}
|
|
@@ -669,7 +669,7 @@ export function validateGameEngineJob(value) {
|
|
|
669
669
|
}
|
|
670
670
|
const raw = value;
|
|
671
671
|
const engineInput = String(raw.engine ?? raw.host ?? 'unreal').trim().toLowerCase();
|
|
672
|
-
const canonicalEngine = GAME_ENGINE_ALIASES[engineInput];
|
|
672
|
+
const canonicalEngine = Object.hasOwn(GAME_ENGINE_ALIASES, engineInput) ? GAME_ENGINE_ALIASES[engineInput] : undefined;
|
|
673
673
|
if (!canonicalEngine) {
|
|
674
674
|
throw new Error(`Unsupported game engine "${String(raw.engine ?? raw.host)}". Supported engines: unreal, unity, godot.`);
|
|
675
675
|
}
|
|
@@ -1013,8 +1013,10 @@ export async function runGameEngineBridge(value, workspace = process.cwd(), sign
|
|
|
1013
1013
|
}
|
|
1014
1014
|
if (job.canonicalEngine === 'unity') {
|
|
1015
1015
|
const destRel = (job.destinationFolder || 'Assets/CausyneAssets').replace(/^\/+|\/+$/g, '');
|
|
1016
|
-
const normalizedDestRel = destRel.startsWith('Assets')
|
|
1017
|
-
|
|
1016
|
+
const normalizedDestRel = (destRel === 'Assets' || destRel.startsWith('Assets/') || destRel.startsWith('Assets\\'))
|
|
1017
|
+
? destRel
|
|
1018
|
+
: path.join('Assets', destRel);
|
|
1019
|
+
const destAbs = await resolveWorkspacePath(normalizedDestRel, projectRoot, false);
|
|
1018
1020
|
const editorDir = path.join(projectRoot, 'Assets', 'Editor');
|
|
1019
1021
|
await fs.mkdir(destAbs, { recursive: true });
|
|
1020
1022
|
await fs.mkdir(editorDir, { recursive: true });
|
|
@@ -1066,7 +1068,7 @@ export async function runGameEngineBridge(value, workspace = process.cwd(), sign
|
|
|
1066
1068
|
}
|
|
1067
1069
|
// Godot 4 Engine Bridge
|
|
1068
1070
|
const destRel = (job.destinationFolder || 'assets/causyne').replace(/^res:\/\/|^\/+|\/+$/g, '');
|
|
1069
|
-
const destAbs =
|
|
1071
|
+
const destAbs = await resolveWorkspacePath(destRel || 'assets/causyne', projectRoot, false);
|
|
1070
1072
|
await fs.mkdir(destAbs, { recursive: true });
|
|
1071
1073
|
const resPaths = [];
|
|
1072
1074
|
for (const srcFile of resolvedAssets) {
|
|
@@ -218,7 +218,7 @@ export function validateAdobeLiveJob(value: unknown): AdobeLiveJob {
|
|
|
218
218
|
}
|
|
219
219
|
const raw = value as Record<string, unknown>;
|
|
220
220
|
const hostInput = String(raw.host ?? 'photoshop').trim().toLowerCase();
|
|
221
|
-
const canonicalHost = ADOBE_HOST_ALIASES[hostInput];
|
|
221
|
+
const canonicalHost = Object.hasOwn(ADOBE_HOST_ALIASES, hostInput) ? ADOBE_HOST_ALIASES[hostInput] : undefined;
|
|
222
222
|
if (!canonicalHost) {
|
|
223
223
|
throw new Error(
|
|
224
224
|
`Unsupported Adobe host "${String(raw.host)}". Supported hosts: photoshop, premiere, after-effects, illustrator, indesign, media-encoder.`
|
|
@@ -903,7 +903,7 @@ export function validateGameEngineJob(value: unknown): GameEngineJob {
|
|
|
903
903
|
}
|
|
904
904
|
const raw = value as Record<string, unknown>;
|
|
905
905
|
const engineInput = String(raw.engine ?? raw.host ?? 'unreal').trim().toLowerCase();
|
|
906
|
-
const canonicalEngine = GAME_ENGINE_ALIASES[engineInput];
|
|
906
|
+
const canonicalEngine = Object.hasOwn(GAME_ENGINE_ALIASES, engineInput) ? GAME_ENGINE_ALIASES[engineInput] : undefined;
|
|
907
907
|
if (!canonicalEngine) {
|
|
908
908
|
throw new Error(
|
|
909
909
|
`Unsupported game engine "${String(raw.engine ?? raw.host)}". Supported engines: unreal, unity, godot.`
|
|
@@ -1273,8 +1273,10 @@ export async function runGameEngineBridge(
|
|
|
1273
1273
|
|
|
1274
1274
|
if (job.canonicalEngine === 'unity') {
|
|
1275
1275
|
const destRel = (job.destinationFolder || 'Assets/CausyneAssets').replace(/^\/+|\/+$/g, '');
|
|
1276
|
-
const normalizedDestRel = destRel.startsWith('Assets')
|
|
1277
|
-
|
|
1276
|
+
const normalizedDestRel = (destRel === 'Assets' || destRel.startsWith('Assets/') || destRel.startsWith('Assets\\'))
|
|
1277
|
+
? destRel
|
|
1278
|
+
: path.join('Assets', destRel);
|
|
1279
|
+
const destAbs = await resolveWorkspacePath(normalizedDestRel, projectRoot, false);
|
|
1278
1280
|
const editorDir = path.join(projectRoot, 'Assets', 'Editor');
|
|
1279
1281
|
await fs.mkdir(destAbs, { recursive: true });
|
|
1280
1282
|
await fs.mkdir(editorDir, { recursive: true });
|
|
@@ -1335,7 +1337,7 @@ export async function runGameEngineBridge(
|
|
|
1335
1337
|
|
|
1336
1338
|
// Godot 4 Engine Bridge
|
|
1337
1339
|
const destRel = (job.destinationFolder || 'assets/causyne').replace(/^res:\/\/|^\/+|\/+$/g, '');
|
|
1338
|
-
const destAbs =
|
|
1340
|
+
const destAbs = await resolveWorkspacePath(destRel || 'assets/causyne', projectRoot, false);
|
|
1339
1341
|
await fs.mkdir(destAbs, { recursive: true });
|
|
1340
1342
|
|
|
1341
1343
|
const resPaths: string[] = [];
|
|
@@ -301,19 +301,30 @@ export async function findHostApplication(host) {
|
|
|
301
301
|
const programFiles = process.env.ProgramFiles || 'C:\\Program Files';
|
|
302
302
|
const folderPattern = host === 'photoshop' ? /Photoshop/i : host === 'premiere' ? /Premiere/i : /After Effects/i;
|
|
303
303
|
const exePattern = host === 'photoshop' ? /Photoshop\.exe$/i : host === 'premiere' ? /Premiere\.exe$/i : /AfterFX\.exe$/i;
|
|
304
|
-
|
|
305
|
-
|
|
304
|
+
const searchRoots = [path.join(programFiles, 'Adobe'), programFiles];
|
|
305
|
+
for (const rootDir of searchRoots) {
|
|
306
|
+
let topDirs;
|
|
307
|
+
try {
|
|
308
|
+
topDirs = await fs.readdir(rootDir);
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
306
313
|
for (const dir of topDirs) {
|
|
307
|
-
|
|
308
|
-
|
|
314
|
+
if (!folderPattern.test(dir))
|
|
315
|
+
continue;
|
|
316
|
+
const fullDir = path.join(rootDir, dir);
|
|
317
|
+
try {
|
|
309
318
|
const files = await fs.readdir(fullDir);
|
|
310
319
|
const foundExe = files.find(f => exePattern.test(f));
|
|
311
320
|
if (foundExe)
|
|
312
321
|
return path.join(fullDir, foundExe);
|
|
313
322
|
}
|
|
323
|
+
catch {
|
|
324
|
+
// Ignore non-directory entries or unreadable subdirs
|
|
325
|
+
}
|
|
314
326
|
}
|
|
315
327
|
}
|
|
316
|
-
catch { /* Ignore filesystem search failures */ }
|
|
317
328
|
}
|
|
318
329
|
return null;
|
|
319
330
|
}
|
|
@@ -304,17 +304,26 @@ export async function findHostApplication(host: CanonicalHost): Promise<string |
|
|
|
304
304
|
const programFiles = process.env.ProgramFiles || 'C:\\Program Files';
|
|
305
305
|
const folderPattern = host === 'photoshop' ? /Photoshop/i : host === 'premiere' ? /Premiere/i : /After Effects/i;
|
|
306
306
|
const exePattern = host === 'photoshop' ? /Photoshop\.exe$/i : host === 'premiere' ? /Premiere\.exe$/i : /AfterFX\.exe$/i;
|
|
307
|
-
|
|
308
|
-
|
|
307
|
+
const searchRoots = [path.join(programFiles, 'Adobe'), programFiles];
|
|
308
|
+
for (const rootDir of searchRoots) {
|
|
309
|
+
let topDirs: string[];
|
|
310
|
+
try {
|
|
311
|
+
topDirs = await fs.readdir(rootDir);
|
|
312
|
+
} catch {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
309
315
|
for (const dir of topDirs) {
|
|
310
|
-
|
|
311
|
-
|
|
316
|
+
if (!folderPattern.test(dir)) continue;
|
|
317
|
+
const fullDir = path.join(rootDir, dir);
|
|
318
|
+
try {
|
|
312
319
|
const files = await fs.readdir(fullDir);
|
|
313
320
|
const foundExe = files.find(f => exePattern.test(f));
|
|
314
321
|
if (foundExe) return path.join(fullDir, foundExe);
|
|
322
|
+
} catch {
|
|
323
|
+
// Ignore non-directory entries or unreadable subdirs
|
|
315
324
|
}
|
|
316
325
|
}
|
|
317
|
-
}
|
|
326
|
+
}
|
|
318
327
|
}
|
|
319
328
|
|
|
320
329
|
return null;
|
package/src/decisionPolicy.js
CHANGED
|
@@ -49,7 +49,7 @@ function splitCommandSegments(command) {
|
|
|
49
49
|
continue;
|
|
50
50
|
}
|
|
51
51
|
if (!inSingle && !inDouble) {
|
|
52
|
-
if (ch === ';') {
|
|
52
|
+
if (ch === ';' || ch === '\n' || ch === '\r') {
|
|
53
53
|
if (current.trim())
|
|
54
54
|
segments.push(current.trim());
|
|
55
55
|
current = '';
|
|
@@ -62,13 +62,25 @@ function splitCommandSegments(command) {
|
|
|
62
62
|
i++;
|
|
63
63
|
continue;
|
|
64
64
|
}
|
|
65
|
-
if (ch === '
|
|
65
|
+
if (ch === '&' && command[i - 1] !== '>' && command[i + 1] !== '>') {
|
|
66
|
+
if (current.trim())
|
|
67
|
+
segments.push(current.trim());
|
|
68
|
+
current = '';
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (ch === '|' && (command[i + 1] === '|' || command[i + 1] === '&')) {
|
|
66
72
|
if (current.trim())
|
|
67
73
|
segments.push(current.trim());
|
|
68
74
|
current = '';
|
|
69
75
|
i++;
|
|
70
76
|
continue;
|
|
71
77
|
}
|
|
78
|
+
if (ch === '|') {
|
|
79
|
+
if (current.trim())
|
|
80
|
+
segments.push(current.trim());
|
|
81
|
+
current = '';
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
72
84
|
}
|
|
73
85
|
current += ch;
|
|
74
86
|
}
|
|
@@ -77,7 +89,7 @@ function splitCommandSegments(command) {
|
|
|
77
89
|
return segments;
|
|
78
90
|
}
|
|
79
91
|
const READ_ONLY_CMD_PATTERNS = [
|
|
80
|
-
String.raw
|
|
92
|
+
String.raw `(?:pwd|ls|find|rg|grep|cat|sed|awk|head|tail|wc|diff|file|stat|which|whereis|type|du|df|pdfinfo|pdftotext|identify|mediainfo|ffprobe|otool|readelf|nm|ps|lsof|top|uptime|whoami|id|uname|env|printenv|echo|printf|pytest)\b`,
|
|
81
93
|
String.raw `(?:\.\/)?gradlew?\s+(?:test\S*|check\S*|lint\S*)\b`,
|
|
82
94
|
String.raw `mvn\s+(?:test\S*|verify\S*)\b`,
|
|
83
95
|
String.raw `git\s+(?:status|diff|log|show|branch|tag|remote|rev-parse|describe)\b`,
|
|
@@ -93,7 +105,7 @@ const READ_ONLY_CMD_PATTERNS = [
|
|
|
93
105
|
String.raw `go\s+test\b`,
|
|
94
106
|
String.raw `curl\s+(?:-I|-sI|-s\b|--head)\b`
|
|
95
107
|
];
|
|
96
|
-
const READ_ONLY_CMD_REGEX = new RegExp(READ_ONLY_CMD_PATTERNS.join('|')
|
|
108
|
+
const READ_ONLY_CMD_REGEX = new RegExp(`^\\s*(?:${READ_ONLY_CMD_PATTERNS.join('|')})`, 'i');
|
|
97
109
|
export function isReadOnlyShellCommand(command) {
|
|
98
110
|
const trimmed = command.trim();
|
|
99
111
|
if (!trimmed)
|