@causyne/agent 1.20.29 → 1.20.31
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/package.json +1 -1
- package/src/acp/client.js +20 -6
- package/src/acp/client.ts +20 -6
- package/src/appChannel.js +52 -74
- package/src/appChannel.ts +106 -0
- package/src/creative/apps.js +206 -11
- package/src/creative/apps.ts +198 -6
- package/src/creative/liveBridge.js +1481 -0
- package/src/creative/liveBridge.ts +1829 -0
- package/src/creative/pipeline.js +31 -3
- package/src/creative/pipeline.ts +36 -7
- package/src/decideTools.js +3 -1
- package/src/decideTools.ts +3 -1
- package/src/decisionPolicy.js +5 -2
- package/src/decisionPolicy.ts +7 -1
- package/src/historyPruner.js +4 -1
- package/src/historyPruner.ts +4 -1
- package/src/memory/episodicStore.js +17 -5
- package/src/memory/episodicStore.ts +16 -5
- package/src/memory/symbolFolder.js +146 -22
- package/src/memory/symbolFolder.ts +144 -22
- package/src/sandbox.js +5 -1
- package/src/smartToolsUse.js +2 -1
- package/src/smartToolsUse.ts +2 -1
- package/src/tool-scripts/resolve_automator.py +167 -34
- package/src/toolPacks.js +5 -3
- package/src/toolPacks.ts +5 -3
- package/src/tools/creativeApps.js +226 -7
- package/src/tools/creativeApps.ts +233 -7
- package/src/tools/memoryRecall.js +1 -1
- package/src/tools/memoryRecall.ts +1 -1
- package/src/tools/resolveAutomator.js +356 -89
- package/src/tools/resolveAutomator.ts +403 -0
- package/src/toolsList.js +1 -1
- package/src/toolsList.ts +1 -1
package/src/creative/pipeline.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { runBlenderBatch } from './blenderBatch.js';
|
|
2
2
|
import { runStudioEdit } from './studioScripts.js';
|
|
3
|
+
import { runAdobeLiveBridge, runGameEngineBridge } from './liveBridge.js';
|
|
4
|
+
const VALID_STAGE_TYPES = ['3d_batch', 'studio_batch', 'live_bridge', 'engine_bridge'];
|
|
3
5
|
export function validatePipeline(value) {
|
|
4
6
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
5
7
|
throw new Error('Pipeline must be an object');
|
|
@@ -14,8 +16,8 @@ export function validatePipeline(value) {
|
|
|
14
16
|
}
|
|
15
17
|
const s = raw;
|
|
16
18
|
const id = typeof s.id === 'string' && s.id.trim() ? s.id.trim() : `stage_${index + 1}`;
|
|
17
|
-
if (
|
|
18
|
-
throw new Error(`Stage "${id}" must have type "3d_batch" or "
|
|
19
|
+
if (!VALID_STAGE_TYPES.includes(s.type)) {
|
|
20
|
+
throw new Error(`Stage "${id}" must have type "3d_batch", "studio_batch", "live_bridge", or "engine_bridge"`);
|
|
19
21
|
}
|
|
20
22
|
const type = s.type;
|
|
21
23
|
if (!s.config || typeof s.config !== 'object' || Array.isArray(s.config)) {
|
|
@@ -37,7 +39,7 @@ export async function runStudioPipeline(value, workspace = process.cwd(), signal
|
|
|
37
39
|
const res = await runBlenderBatch(stage.config, workspace, signal);
|
|
38
40
|
stageResults.push({ id: stage.id, success: true, output: res.output });
|
|
39
41
|
}
|
|
40
|
-
else {
|
|
42
|
+
else if (stage.type === 'studio_batch') {
|
|
41
43
|
const res = await runStudioEdit(stage.config, workspace, signal);
|
|
42
44
|
if (!res.success) {
|
|
43
45
|
stageResults.push({ id: stage.id, success: false, error: res.error });
|
|
@@ -45,6 +47,32 @@ export async function runStudioPipeline(value, workspace = process.cwd(), signal
|
|
|
45
47
|
}
|
|
46
48
|
stageResults.push({ id: stage.id, success: true, output: res.output });
|
|
47
49
|
}
|
|
50
|
+
else if (stage.type === 'live_bridge') {
|
|
51
|
+
const res = await runAdobeLiveBridge(stage.config, workspace, signal);
|
|
52
|
+
if (!res.success) {
|
|
53
|
+
const errStr = String(res.error ?? 'Adobe live bridge failed');
|
|
54
|
+
stageResults.push({ id: stage.id, success: false, error: errStr });
|
|
55
|
+
return { success: false, stagesCompleted: i, stageResults, error: `Stage "${stage.id}" failed: ${errStr}` };
|
|
56
|
+
}
|
|
57
|
+
stageResults.push({
|
|
58
|
+
id: stage.id,
|
|
59
|
+
success: true,
|
|
60
|
+
output: typeof res.output === 'string' ? res.output : typeof res.scriptPath === 'string' ? res.scriptPath : 'live_bridge_ok'
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const res = await runGameEngineBridge(stage.config, workspace, signal);
|
|
65
|
+
if (!res.success) {
|
|
66
|
+
const errStr = String(res.error ?? 'Game engine bridge failed');
|
|
67
|
+
stageResults.push({ id: stage.id, success: false, error: errStr });
|
|
68
|
+
return { success: false, stagesCompleted: i, stageResults, error: `Stage "${stage.id}" failed: ${errStr}` };
|
|
69
|
+
}
|
|
70
|
+
stageResults.push({
|
|
71
|
+
id: stage.id,
|
|
72
|
+
success: true,
|
|
73
|
+
output: typeof res.scriptPath === 'string' ? res.scriptPath : typeof res.editorScriptPath === 'string' ? res.editorScriptPath : 'engine_bridge_ok'
|
|
74
|
+
});
|
|
75
|
+
}
|
|
48
76
|
}
|
|
49
77
|
catch (err) {
|
|
50
78
|
const errMsg = err instanceof Error ? err.message : String(err);
|
package/src/creative/pipeline.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { runBlenderBatch
|
|
2
|
-
import { runStudioEdit
|
|
1
|
+
import { runBlenderBatch } from './blenderBatch.js';
|
|
2
|
+
import { runStudioEdit } from './studioScripts.js';
|
|
3
|
+
import { runAdobeLiveBridge, runGameEngineBridge } from './liveBridge.js';
|
|
4
|
+
|
|
5
|
+
export type PipelineStageType = '3d_batch' | 'studio_batch' | 'live_bridge' | 'engine_bridge';
|
|
3
6
|
|
|
4
7
|
export interface PipelineStage {
|
|
5
8
|
id: string;
|
|
6
|
-
type:
|
|
9
|
+
type: PipelineStageType;
|
|
7
10
|
config: Record<string, unknown>;
|
|
8
11
|
}
|
|
9
12
|
|
|
@@ -18,6 +21,8 @@ export interface PipelineResult {
|
|
|
18
21
|
error?: string | undefined;
|
|
19
22
|
}
|
|
20
23
|
|
|
24
|
+
const VALID_STAGE_TYPES: readonly PipelineStageType[] = ['3d_batch', 'studio_batch', 'live_bridge', 'engine_bridge'];
|
|
25
|
+
|
|
21
26
|
export function validatePipeline(value: unknown): StudioPipeline {
|
|
22
27
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
23
28
|
throw new Error('Pipeline must be an object');
|
|
@@ -33,10 +38,10 @@ export function validatePipeline(value: unknown): StudioPipeline {
|
|
|
33
38
|
}
|
|
34
39
|
const s = raw as Record<string, unknown>;
|
|
35
40
|
const id = typeof s.id === 'string' && s.id.trim() ? s.id.trim() : `stage_${index + 1}`;
|
|
36
|
-
if (
|
|
37
|
-
throw new Error(`Stage "${id}" must have type "3d_batch" or "
|
|
41
|
+
if (!VALID_STAGE_TYPES.includes(s.type as PipelineStageType)) {
|
|
42
|
+
throw new Error(`Stage "${id}" must have type "3d_batch", "studio_batch", "live_bridge", or "engine_bridge"`);
|
|
38
43
|
}
|
|
39
|
-
const type
|
|
44
|
+
const type = s.type as PipelineStageType;
|
|
40
45
|
if (!s.config || typeof s.config !== 'object' || Array.isArray(s.config)) {
|
|
41
46
|
throw new Error(`Stage "${id}" requires a configuration object`);
|
|
42
47
|
}
|
|
@@ -63,13 +68,37 @@ export async function runStudioPipeline(
|
|
|
63
68
|
if (stage.type === '3d_batch') {
|
|
64
69
|
const res = await runBlenderBatch(stage.config, workspace, signal);
|
|
65
70
|
stageResults.push({ id: stage.id, success: true, output: res.output });
|
|
66
|
-
} else {
|
|
71
|
+
} else if (stage.type === 'studio_batch') {
|
|
67
72
|
const res = await runStudioEdit(stage.config, workspace, signal);
|
|
68
73
|
if (!res.success) {
|
|
69
74
|
stageResults.push({ id: stage.id, success: false, error: res.error });
|
|
70
75
|
return { success: false, stagesCompleted: i, stageResults, error: `Stage "${stage.id}" failed: ${res.error}` };
|
|
71
76
|
}
|
|
72
77
|
stageResults.push({ id: stage.id, success: true, output: res.output });
|
|
78
|
+
} else if (stage.type === 'live_bridge') {
|
|
79
|
+
const res = await runAdobeLiveBridge(stage.config, workspace, signal);
|
|
80
|
+
if (!res.success) {
|
|
81
|
+
const errStr = String(res.error ?? 'Adobe live bridge failed');
|
|
82
|
+
stageResults.push({ id: stage.id, success: false, error: errStr });
|
|
83
|
+
return { success: false, stagesCompleted: i, stageResults, error: `Stage "${stage.id}" failed: ${errStr}` };
|
|
84
|
+
}
|
|
85
|
+
stageResults.push({
|
|
86
|
+
id: stage.id,
|
|
87
|
+
success: true,
|
|
88
|
+
output: typeof res.output === 'string' ? res.output : typeof res.scriptPath === 'string' ? res.scriptPath : 'live_bridge_ok'
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
const res = await runGameEngineBridge(stage.config, workspace, signal);
|
|
92
|
+
if (!res.success) {
|
|
93
|
+
const errStr = String(res.error ?? 'Game engine bridge failed');
|
|
94
|
+
stageResults.push({ id: stage.id, success: false, error: errStr });
|
|
95
|
+
return { success: false, stagesCompleted: i, stageResults, error: `Stage "${stage.id}" failed: ${errStr}` };
|
|
96
|
+
}
|
|
97
|
+
stageResults.push({
|
|
98
|
+
id: stage.id,
|
|
99
|
+
success: true,
|
|
100
|
+
output: typeof res.scriptPath === 'string' ? res.scriptPath : typeof res.editorScriptPath === 'string' ? res.editorScriptPath : 'engine_bridge_ok'
|
|
101
|
+
});
|
|
73
102
|
}
|
|
74
103
|
} catch (err) {
|
|
75
104
|
const errMsg = err instanceof Error ? err.message : String(err);
|
package/src/decideTools.js
CHANGED
|
@@ -43,7 +43,9 @@ const TRIGGERS = [
|
|
|
43
43
|
{ pattern: /\b(symbols?|definitions?|ast|outline|fold)\b/i, tools: ['code_list_symbols', 'code_search_ast', 'memory_recall'], why: 'structural code search' },
|
|
44
44
|
{ pattern: /\b(past session|previous session|episodic|remember|recall|history|earlier fix|memory_recall|memory_write)\b/i, tools: ['memory_recall', 'memory_write'], why: 'episodic memory recall' },
|
|
45
45
|
{ pattern: /\b(syntax|compile|typecheck|lint)\b/i, tools: ['code_verify_syntax'], why: 'static check' },
|
|
46
|
-
{ pattern: /\b(godot|\.tscn|gdscript)\b/i, tools: ['godot_act', 'game_scene_build'], why: 'Godot work' },
|
|
46
|
+
{ pattern: /\b(godot|\.tscn|gdscript)\b/i, tools: ['godot_act', 'game_scene_build', 'creative_apps'], why: 'Godot work' },
|
|
47
|
+
{ pattern: /\b(photoshop|premiere|after[- ]?effects|illustrator|indesign|media[- ]?encoder|uxp|unreal|ue5|unity|\.psd\b|\.prproj\b|\.aep\b|\.uproject\b)\b/i,
|
|
48
|
+
tools: ['creative_apps'], why: 'native Adobe & game engine bridge' },
|
|
47
49
|
{ pattern: /\b(clipboard)\b/i, tools: ['clipboard'], why: 'clipboard' },
|
|
48
50
|
{ pattern: /\b(gui|desktop app|accessibility|click (?:the )?button)\b/i, tools: ['ax_snapshot', 'desktop_act'], why: 'GUI control' },
|
|
49
51
|
{ pattern: /\b(commit|branch|merge|rebase)\b/i, tools: ['gitOp'], why: 'version control' },
|
package/src/decideTools.ts
CHANGED
|
@@ -90,7 +90,9 @@ const TRIGGERS: readonly Trigger[] = [
|
|
|
90
90
|
{ pattern: /\b(symbols?|definitions?|ast|outline|fold)\b/i, tools: ['code_list_symbols', 'code_search_ast', 'memory_recall'], why: 'structural code search' },
|
|
91
91
|
{ pattern: /\b(past session|previous session|episodic|remember|recall|history|earlier fix|memory_recall|memory_write)\b/i, tools: ['memory_recall', 'memory_write'], why: 'episodic memory recall' },
|
|
92
92
|
{ pattern: /\b(syntax|compile|typecheck|lint)\b/i, tools: ['code_verify_syntax'], why: 'static check' },
|
|
93
|
-
{ pattern: /\b(godot|\.tscn|gdscript)\b/i, tools: ['godot_act', 'game_scene_build'], why: 'Godot work' },
|
|
93
|
+
{ pattern: /\b(godot|\.tscn|gdscript)\b/i, tools: ['godot_act', 'game_scene_build', 'creative_apps'], why: 'Godot work' },
|
|
94
|
+
{ pattern: /\b(photoshop|premiere|after[- ]?effects|illustrator|indesign|media[- ]?encoder|uxp|unreal|ue5|unity|\.psd\b|\.prproj\b|\.aep\b|\.uproject\b)\b/i,
|
|
95
|
+
tools: ['creative_apps'], why: 'native Adobe & game engine bridge' },
|
|
94
96
|
{ pattern: /\b(clipboard)\b/i, tools: ['clipboard'], why: 'clipboard' },
|
|
95
97
|
{ pattern: /\b(gui|desktop app|accessibility|click (?:the )?button)\b/i, tools: ['ax_snapshot', 'desktop_act'], why: 'GUI control' },
|
|
96
98
|
{ pattern: /\b(commit|branch|merge|rebase)\b/i, tools: ['gitOp'], why: 'version control' },
|
package/src/decisionPolicy.js
CHANGED
|
@@ -60,8 +60,11 @@ export function requiresImplementationPlan(prompt, archetype = '', confidence =
|
|
|
60
60
|
return containsAny(text, ARCHITECTURE_TERMS) && containsAny(text, CHANGE_TERMS);
|
|
61
61
|
}
|
|
62
62
|
export function isMutatingToolCall(toolName, args = {}) {
|
|
63
|
-
if (toolName === 'creative_apps')
|
|
64
|
-
return args.action !== 'status'
|
|
63
|
+
if (toolName === 'creative_apps') {
|
|
64
|
+
return (args.action !== 'status' &&
|
|
65
|
+
args.action !== 'verify_bridge' &&
|
|
66
|
+
!(args.action === 'live_bridge' && args.liveOperation === 'inspect_active'));
|
|
67
|
+
}
|
|
65
68
|
if (toolName === 'native_engine')
|
|
66
69
|
return !['status', 'catalog', 'describe', 'inspect', 'probe'].includes(String(args.action ?? ''));
|
|
67
70
|
if (MUTATING_TOOLS.has(toolName)) {
|
package/src/decisionPolicy.ts
CHANGED
|
@@ -98,7 +98,13 @@ export function requiresImplementationPlan(prompt: string, archetype = '', confi
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
export function isMutatingToolCall(toolName: string, args: Record<string, unknown> = {}): boolean {
|
|
101
|
-
if (toolName === 'creative_apps')
|
|
101
|
+
if (toolName === 'creative_apps') {
|
|
102
|
+
return (
|
|
103
|
+
args.action !== 'status' &&
|
|
104
|
+
args.action !== 'verify_bridge' &&
|
|
105
|
+
!(args.action === 'live_bridge' && args.liveOperation === 'inspect_active')
|
|
106
|
+
);
|
|
107
|
+
}
|
|
102
108
|
if (toolName === 'native_engine') return !['status', 'catalog', 'describe', 'inspect', 'probe'].includes(String(args.action ?? ''));
|
|
103
109
|
if (MUTATING_TOOLS.has(toolName)) {
|
|
104
110
|
if (['sysRun', 'sysRunBg', 'bash', 'terminal', 'execute', 'sh', 'zsh'].includes(toolName)) {
|
package/src/historyPruner.js
CHANGED
|
@@ -218,7 +218,10 @@ export function pruneStaleToolObservations(messages, options = {}) {
|
|
|
218
218
|
}
|
|
219
219
|
if (seen <= keepRecent && !isDuplicateInspection)
|
|
220
220
|
continue;
|
|
221
|
-
|
|
221
|
+
const effectiveMinChars = message.name === 'memory_recall'
|
|
222
|
+
? Math.max(minChars, 4000)
|
|
223
|
+
: minChars;
|
|
224
|
+
if (original.length < effectiveMinChars)
|
|
222
225
|
continue;
|
|
223
226
|
let spillPath = message.spillPath;
|
|
224
227
|
if (!spillPath) {
|
package/src/historyPruner.ts
CHANGED
|
@@ -228,7 +228,10 @@ export function pruneStaleToolObservations(
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
if (seen <= keepRecent && !isDuplicateInspection) continue;
|
|
231
|
-
|
|
231
|
+
const effectiveMinChars = message.name === 'memory_recall'
|
|
232
|
+
? Math.max(minChars, 4000)
|
|
233
|
+
: minChars;
|
|
234
|
+
if (original.length < effectiveMinChars) continue;
|
|
232
235
|
|
|
233
236
|
let spillPath = message.spillPath;
|
|
234
237
|
if (!spillPath) {
|
|
@@ -185,8 +185,15 @@ export class EpisodicMemoryStore {
|
|
|
185
185
|
externalBridgeImported = false;
|
|
186
186
|
static defaultInstance = null;
|
|
187
187
|
constructor(customStorePath) {
|
|
188
|
-
|
|
189
|
-
|
|
188
|
+
if (customStorePath) {
|
|
189
|
+
this.storePath = path.resolve(customStorePath);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const isTestRunner = Boolean(process.env.NODE_TEST_CONTEXT) ||
|
|
193
|
+
process.execArgv.includes('--test') ||
|
|
194
|
+
process.argv.includes('--test');
|
|
195
|
+
this.storePath = isTestRunner
|
|
196
|
+
? path.join(os.tmpdir(), `causyne-test-episodic-${process.pid}.json`)
|
|
190
197
|
: path.join(causyneHome(), 'episodic-memory.json');
|
|
191
198
|
}
|
|
192
199
|
static getInstance() {
|
|
@@ -203,6 +210,10 @@ export class EpisodicMemoryStore {
|
|
|
203
210
|
const raw = JSON.parse(fs.readFileSync(this.storePath, 'utf8'));
|
|
204
211
|
if (raw && Array.isArray(raw.observations) && Array.isArray(raw.summaries)) {
|
|
205
212
|
const cleanedObservations = raw.observations.filter((obs) => {
|
|
213
|
+
if (obs.taskId === 'native-recovery-false')
|
|
214
|
+
return false;
|
|
215
|
+
if (obs.title.includes('.causyne_verify_placeholder'))
|
|
216
|
+
return false;
|
|
206
217
|
if (obs.type !== 'discovery')
|
|
207
218
|
return true;
|
|
208
219
|
return !/^(?:Succeeded|Failed):\s*(?:find|wc|grep|egrep|fgrep|rg|sed|awk|jq|stat|file|ls|cat|head|tail|node\s+-e|python3?\s+-c)\b/i.test(obs.title);
|
|
@@ -524,14 +535,15 @@ export class EpisodicMemoryStore {
|
|
|
524
535
|
continue;
|
|
525
536
|
}
|
|
526
537
|
totalBytes += byteLen;
|
|
527
|
-
|
|
528
|
-
// Reinforce retrieved memory in ACT-R
|
|
538
|
+
// Reinforce retrieved memory in ACT-R and return the updated observation
|
|
529
539
|
const reinforced = [...obs.reinforcedAtEpochsMs, nowMs].slice(-MAX_REINFORCEMENT_TIMESTAMPS);
|
|
530
|
-
|
|
540
|
+
const updatedObs = {
|
|
531
541
|
...obs,
|
|
532
542
|
reinforcedAtEpochsMs: reinforced,
|
|
533
543
|
reinforcementCount: obs.reinforcementCount + 1
|
|
534
544
|
};
|
|
545
|
+
store.observations[idx] = updatedObs;
|
|
546
|
+
observations.push(updatedObs);
|
|
535
547
|
dirty = true;
|
|
536
548
|
}
|
|
537
549
|
if (dirty) {
|
|
@@ -262,8 +262,16 @@ export class EpisodicMemoryStore {
|
|
|
262
262
|
private static defaultInstance: EpisodicMemoryStore | null = null;
|
|
263
263
|
|
|
264
264
|
constructor(customStorePath?: string) {
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
if (customStorePath) {
|
|
266
|
+
this.storePath = path.resolve(customStorePath);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const isTestRunner =
|
|
270
|
+
Boolean(process.env.NODE_TEST_CONTEXT) ||
|
|
271
|
+
process.execArgv.includes('--test') ||
|
|
272
|
+
process.argv.includes('--test');
|
|
273
|
+
this.storePath = isTestRunner
|
|
274
|
+
? path.join(os.tmpdir(), `causyne-test-episodic-${process.pid}.json`)
|
|
267
275
|
: path.join(causyneHome(), 'episodic-memory.json');
|
|
268
276
|
}
|
|
269
277
|
|
|
@@ -281,6 +289,8 @@ export class EpisodicMemoryStore {
|
|
|
281
289
|
const raw = JSON.parse(fs.readFileSync(this.storePath, 'utf8')) as Partial<PersistedEpisodicData>;
|
|
282
290
|
if (raw && Array.isArray(raw.observations) && Array.isArray(raw.summaries)) {
|
|
283
291
|
const cleanedObservations = raw.observations.filter((obs) => {
|
|
292
|
+
if (obs.taskId === 'native-recovery-false') return false;
|
|
293
|
+
if (obs.title.includes('.causyne_verify_placeholder')) return false;
|
|
284
294
|
if (obs.type !== 'discovery') return true;
|
|
285
295
|
return !/^(?:Succeeded|Failed):\s*(?:find|wc|grep|egrep|fgrep|rg|sed|awk|jq|stat|file|ls|cat|head|tail|node\s+-e|python3?\s+-c)\b/i.test(obs.title);
|
|
286
296
|
});
|
|
@@ -641,15 +651,16 @@ export class EpisodicMemoryStore {
|
|
|
641
651
|
}
|
|
642
652
|
|
|
643
653
|
totalBytes += byteLen;
|
|
644
|
-
observations.push(obs);
|
|
645
654
|
|
|
646
|
-
// Reinforce retrieved memory in ACT-R
|
|
655
|
+
// Reinforce retrieved memory in ACT-R and return the updated observation
|
|
647
656
|
const reinforced = [...obs.reinforcedAtEpochsMs, nowMs].slice(-MAX_REINFORCEMENT_TIMESTAMPS);
|
|
648
|
-
|
|
657
|
+
const updatedObs: EpisodicObservation = {
|
|
649
658
|
...obs,
|
|
650
659
|
reinforcedAtEpochsMs: reinforced,
|
|
651
660
|
reinforcementCount: obs.reinforcementCount + 1
|
|
652
661
|
};
|
|
662
|
+
store.observations[idx] = updatedObs;
|
|
663
|
+
observations.push(updatedObs);
|
|
653
664
|
dirty = true;
|
|
654
665
|
}
|
|
655
666
|
|
|
@@ -115,11 +115,11 @@ function extractPrecedingDocComment(lines, lineIndex) {
|
|
|
115
115
|
idx--;
|
|
116
116
|
}
|
|
117
117
|
const summary = docLines.join(' ').trim();
|
|
118
|
-
return summary ? summary.slice(0,
|
|
118
|
+
return summary ? summary.slice(0, 65) : undefined;
|
|
119
119
|
}
|
|
120
120
|
if (line.startsWith('//') || line.startsWith('#')) {
|
|
121
121
|
const cleaned = line.replace(/^(?:\/\/+|#+)\s*/, '').trim();
|
|
122
|
-
return cleaned ? cleaned.slice(0,
|
|
122
|
+
return cleaned ? cleaned.slice(0, 65) : undefined;
|
|
123
123
|
}
|
|
124
124
|
return undefined;
|
|
125
125
|
}
|
|
@@ -158,26 +158,147 @@ function extractCollapsedSignature(lines, startIndex, kind) {
|
|
|
158
158
|
.trim()
|
|
159
159
|
.slice(0, 110);
|
|
160
160
|
}
|
|
161
|
-
function findBraceBlockEnd(lines, startIndex) {
|
|
162
|
-
|
|
163
|
-
let
|
|
161
|
+
function findBraceBlockEnd(lines, startIndex, kind) {
|
|
162
|
+
const isCallable = kind === 'function' || kind === 'method';
|
|
163
|
+
let inBlockComment = false;
|
|
164
|
+
let parenDepth = 0;
|
|
165
|
+
let seenParamsOpen = false;
|
|
166
|
+
let seenParamsClose = !isCallable;
|
|
167
|
+
let typeBraceDepth = 0;
|
|
168
|
+
let bodyDepth = 0;
|
|
169
|
+
let bodyOpened = false;
|
|
170
|
+
let lastNonWs = '';
|
|
164
171
|
for (let i = startIndex; i < lines.length; i++) {
|
|
165
172
|
const line = lines[i] ?? '';
|
|
173
|
+
let inSingleQuote = false;
|
|
174
|
+
let inDoubleQuote = false;
|
|
175
|
+
let inTemplate = false;
|
|
166
176
|
for (let c = 0; c < line.length; c++) {
|
|
167
|
-
const ch = line[c];
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
const ch = line[c] ?? '';
|
|
178
|
+
const next = line[c + 1] ?? '';
|
|
179
|
+
if (inBlockComment) {
|
|
180
|
+
if (ch === '*' && next === '/') {
|
|
181
|
+
inBlockComment = false;
|
|
182
|
+
c += 1;
|
|
183
|
+
}
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (ch === '\\') {
|
|
187
|
+
c += 1;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (inSingleQuote) {
|
|
191
|
+
if (ch === '\'')
|
|
192
|
+
inSingleQuote = false;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (inDoubleQuote) {
|
|
196
|
+
if (ch === '"')
|
|
197
|
+
inDoubleQuote = false;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (inTemplate) {
|
|
201
|
+
if (ch === '`')
|
|
202
|
+
inTemplate = false;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (ch === '/' && next === '/') {
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
if (ch === '/' && next === '*') {
|
|
209
|
+
inBlockComment = true;
|
|
210
|
+
c += 1;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (ch === '\'') {
|
|
214
|
+
inSingleQuote = true;
|
|
215
|
+
if (seenParamsClose && !bodyOpened && typeBraceDepth === 0)
|
|
216
|
+
lastNonWs = ch;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (ch === '"') {
|
|
220
|
+
inDoubleQuote = true;
|
|
221
|
+
if (seenParamsClose && !bodyOpened && typeBraceDepth === 0)
|
|
222
|
+
lastNonWs = ch;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (ch === '`') {
|
|
226
|
+
inTemplate = true;
|
|
227
|
+
if (seenParamsClose && !bodyOpened && typeBraceDepth === 0)
|
|
228
|
+
lastNonWs = ch;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (!seenParamsClose) {
|
|
232
|
+
if (ch === '(') {
|
|
233
|
+
parenDepth += 1;
|
|
234
|
+
seenParamsOpen = true;
|
|
235
|
+
}
|
|
236
|
+
else if (ch === ')') {
|
|
237
|
+
parenDepth -= 1;
|
|
238
|
+
if (seenParamsOpen && parenDepth <= 0) {
|
|
239
|
+
seenParamsClose = true;
|
|
240
|
+
parenDepth = 0;
|
|
241
|
+
lastNonWs = ')';
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
continue;
|
|
171
245
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
246
|
+
if (!bodyOpened) {
|
|
247
|
+
if (typeBraceDepth > 0) {
|
|
248
|
+
if (ch === '{') {
|
|
249
|
+
typeBraceDepth += 1;
|
|
250
|
+
}
|
|
251
|
+
else if (ch === '}') {
|
|
252
|
+
typeBraceDepth -= 1;
|
|
253
|
+
if (typeBraceDepth <= 0) {
|
|
254
|
+
typeBraceDepth = 0;
|
|
255
|
+
lastNonWs = '}';
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (ch === '(') {
|
|
261
|
+
parenDepth += 1;
|
|
262
|
+
lastNonWs = '(';
|
|
263
|
+
}
|
|
264
|
+
else if (ch === ')') {
|
|
265
|
+
parenDepth = Math.max(0, parenDepth - 1);
|
|
266
|
+
lastNonWs = ')';
|
|
267
|
+
}
|
|
268
|
+
else if (ch === '{') {
|
|
269
|
+
if (isCallable &&
|
|
270
|
+
(parenDepth > 0 ||
|
|
271
|
+
lastNonWs === ':' ||
|
|
272
|
+
lastNonWs === '|' ||
|
|
273
|
+
lastNonWs === '&' ||
|
|
274
|
+
lastNonWs === '<' ||
|
|
275
|
+
lastNonWs === ',' ||
|
|
276
|
+
lastNonWs === '=')) {
|
|
277
|
+
typeBraceDepth = 1;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
bodyOpened = true;
|
|
281
|
+
bodyDepth = 1;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else if (ch === ';' && parenDepth === 0) {
|
|
175
285
|
return i + 1;
|
|
176
286
|
}
|
|
287
|
+
else if (!/\s/.test(ch)) {
|
|
288
|
+
lastNonWs = ch;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
if (ch === '{') {
|
|
293
|
+
bodyDepth += 1;
|
|
294
|
+
}
|
|
295
|
+
else if (ch === '}') {
|
|
296
|
+
bodyDepth -= 1;
|
|
297
|
+
if (bodyDepth <= 0) {
|
|
298
|
+
return i + 1;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
177
301
|
}
|
|
178
|
-
}
|
|
179
|
-
if (!opened && line.trim().endsWith(';')) {
|
|
180
|
-
return i + 1;
|
|
181
302
|
}
|
|
182
303
|
}
|
|
183
304
|
return Math.min(lines.length, startIndex + 1);
|
|
@@ -206,6 +327,9 @@ export function foldSourceContentOutline(content, filePath, queryFilter) {
|
|
|
206
327
|
const ext = path.extname(filePath).toLowerCase();
|
|
207
328
|
const language = LANGUAGE_BY_EXT[ext] ?? 'text';
|
|
208
329
|
const lines = content.split(/\r?\n/);
|
|
330
|
+
if (lines.length > 1 && lines[lines.length - 1] === '') {
|
|
331
|
+
lines.pop();
|
|
332
|
+
}
|
|
209
333
|
const totalLines = lines.length;
|
|
210
334
|
let importCount = 0;
|
|
211
335
|
for (const line of lines) {
|
|
@@ -234,19 +358,23 @@ export function foldSourceContentOutline(content, filePath, queryFilter) {
|
|
|
234
358
|
const rawName = m[pat.nameGroup] || m[3] || '';
|
|
235
359
|
if (!rawName || RESERVED_METHOD_NAMES.has(rawName))
|
|
236
360
|
continue;
|
|
237
|
-
// For class method pattern, ensure it is
|
|
361
|
+
// For class method pattern, ensure it is not a bodyless call ending in `;`
|
|
238
362
|
if (pat.kind === 'method') {
|
|
239
363
|
const sigCheck = extractCollapsedSignature(lines, i, 'method');
|
|
240
|
-
if (sigCheck.endsWith(';')
|
|
364
|
+
if (sigCheck.endsWith(';'))
|
|
241
365
|
continue;
|
|
242
366
|
}
|
|
243
367
|
const exported = /\bexport\b|\bpub\b/.test(line);
|
|
244
368
|
const lineStart = i + 1;
|
|
245
369
|
const lineEnd = language === 'python'
|
|
246
370
|
? findIndentBlockEnd(lines, i)
|
|
247
|
-
: findBraceBlockEnd(lines, i);
|
|
371
|
+
: findBraceBlockEnd(lines, i, pat.kind);
|
|
248
372
|
const signature = extractCollapsedSignature(lines, i, pat.kind);
|
|
249
373
|
const docComment = extractPrecedingDocComment(lines, i);
|
|
374
|
+
// Advance past non-class symbol bodies so statements inside functions/methods aren't misread as methods
|
|
375
|
+
if (pat.kind !== 'class') {
|
|
376
|
+
i = Math.max(i, lineEnd - 1);
|
|
377
|
+
}
|
|
250
378
|
if (lowerQuery) {
|
|
251
379
|
const hay = `${rawName} ${signature} ${docComment ?? ''}`.toLowerCase();
|
|
252
380
|
if (!hay.includes(lowerQuery))
|
|
@@ -261,10 +389,6 @@ export function foldSourceContentOutline(content, filePath, queryFilter) {
|
|
|
261
389
|
exported,
|
|
262
390
|
...(docComment ? { docComment } : {})
|
|
263
391
|
});
|
|
264
|
-
// Advance past multi-line parameter list header if applicable so inner lines aren't misread as methods
|
|
265
|
-
if (pat.kind === 'function') {
|
|
266
|
-
i = Math.max(i, lineEnd - 1);
|
|
267
|
-
}
|
|
268
392
|
break;
|
|
269
393
|
}
|
|
270
394
|
}
|