@causyne/agent 1.20.11 → 1.20.12
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/LICENSE +1 -1
- package/docs/ARCHITECTURE.md +24 -1
- package/package.json +1 -1
- package/src/acp/client.js +9 -2
- package/src/acp/client.ts +11 -2
- package/src/acp/protocol.ts +9 -0
- package/src/agentLoop.js +504 -119
- package/src/agentLoop.ts +477 -121
- package/src/browser/browserRuntime.js +47 -0
- package/src/browser/browserRuntime.ts +45 -0
- package/src/browser/causyneBrowser.js +60 -31
- package/src/browser/causyneBrowser.ts +37 -12
- package/src/browser/workspacePreview.js +52 -0
- package/src/browser/workspacePreview.ts +49 -0
- package/src/core/planCache.js +5 -0
- package/src/core/planCache.ts +5 -0
- package/src/decisionPolicy.js +9 -0
- package/src/decisionPolicy.ts +8 -0
- package/src/historyPruner.js +251 -0
- package/src/historyPruner.ts +263 -0
- package/src/infra/atomicWriter.js +49 -0
- package/src/infra/atomicWriter.ts +63 -0
- package/src/infra/telemetry.js +38 -0
- package/src/infra/telemetry.ts +68 -0
- package/src/observer/coldObserver.js +12 -7
- package/src/observer/coldObserver.ts +12 -7
- package/src/observer/evidence.js +8 -2
- package/src/observer/evidence.ts +9 -2
- package/src/outputRecovery.js +36 -0
- package/src/outputRecovery.ts +33 -0
- package/src/providers/acp.js +114 -46
- package/src/providers/acp.ts +129 -46
- package/src/providers/antigravity.js +264 -82
- package/src/providers/antigravity.ts +273 -87
- package/src/providers/antigravityBridge.js +58 -0
- package/src/providers/antigravityBridge.ts +51 -0
- package/src/providers/base.d.ts +9 -0
- package/src/providers/budgetEnforcer.js +110 -0
- package/src/providers/budgetEnforcer.ts +122 -0
- package/src/providers/collaborationPolicy.js +6 -0
- package/src/providers/collaborationPolicy.ts +7 -0
- package/src/providers/loopGuard.js +84 -0
- package/src/providers/loopGuard.ts +105 -0
- package/src/providers/pi.js +19 -6
- package/src/providers/pi.ts +19 -7
- package/src/providers/toolContracts.js +36 -0
- package/src/providers/toolContracts.ts +48 -0
- package/src/session/sidechainEvents.js +49 -0
- package/src/session/sidechainEvents.ts +98 -0
- package/src/skillsManager.d.ts +1 -0
- package/src/smartToolsUse.js +123 -4
- package/src/smartToolsUse.ts +136 -4
- package/src/subagent/sidechainHarness.js +66 -0
- package/src/subagent/sidechainHarness.ts +91 -0
- package/src/taskContinuation.js +12 -0
- package/src/taskContinuation.ts +13 -0
- package/src/tokenTracker.js +406 -539
- package/src/tokenTracker.ts +569 -0
- package/src/toolPacks.d.ts +2 -0
- package/src/toolPacks.js +1 -1
- package/src/tools/argumentValidation.js +56 -0
- package/src/tools/argumentValidation.ts +50 -0
- package/src/tools/browserAutomator.js +2 -2
- package/src/tools/browserAutomator.ts +3 -2
- package/src/tools/deferredMcpSearch.js +188 -201
- package/src/tools/deferredMcpSearch.ts +250 -0
- package/src/tools/generateMediaViaApi.js +305 -331
- package/src/tools/generateMediaViaApi.ts +330 -0
- package/src/tools/historyPruner.js +5 -0
- package/src/tools/historyPruner.ts +5 -0
- package/src/tools/payloadSanitizer.js +92 -0
- package/src/tools/payloadSanitizer.ts +113 -0
- package/src/tools/registry.d.ts +1 -0
- package/src/tools/sysRun.js +47 -18
- package/src/tools/sysRun.ts +52 -20
- package/src/tools/toolOutputStore.js +180 -0
- package/src/tools/toolOutputStore.ts +209 -0
- package/src/tools/toolSelfRepair.js +26 -1
- package/src/tools/toolSelfRepair.ts +25 -1
- package/src/tui/chatRenderer.d.ts +1 -0
- package/src/tui/chatRenderer.js +4 -2
- package/src/tui/codeStreamRenderer.js +36 -8
- package/src/tui/codeStreamRenderer.ts +38 -8
- package/src/tui/stageSurface.js +1 -0
- package/src/tui/text.js +4 -1
- package/src/tokenTracker.d.ts +0 -1
package/src/providers/pi.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { AcpProvider } from './acp.js';
|
|
3
|
-
import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse } from './base.js';
|
|
3
|
+
import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse, type ChatResponseAction } from './base.js';
|
|
4
4
|
|
|
5
5
|
export function isPiProvider(provider?: string | null): boolean {
|
|
6
6
|
return typeof provider === 'string' && provider.toLowerCase() === 'pi';
|
|
@@ -11,7 +11,7 @@ export const PI_SETUP_PROVIDER = {
|
|
|
11
11
|
category: 'Peer Agent', model: 'default'
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
/** Pi
|
|
14
|
+
/** Pi collaborates over RPC with its configured capabilities intact. */
|
|
15
15
|
export class PiProvider extends LLMProvider {
|
|
16
16
|
private readonly command: string;
|
|
17
17
|
private readonly formatter: AcpProvider;
|
|
@@ -26,8 +26,7 @@ export class PiProvider extends LLMProvider {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
override async chat(messages: unknown[], options: ChatOptions = {}): Promise<ChatResponse> {
|
|
29
|
-
const args = ['--mode', 'rpc', '--no-session'
|
|
30
|
-
'--no-mcp', '--no-context-files', '--no-skills', '--no-prompt-templates'];
|
|
29
|
+
const args = ['--mode', 'rpc', '--no-session'];
|
|
31
30
|
if (this.model !== 'default') args.push('--model', this.model);
|
|
32
31
|
const cwd = typeof options.workspaceRoot === 'string' && options.workspaceRoot
|
|
33
32
|
? options.workspaceRoot : process.cwd();
|
|
@@ -46,6 +45,7 @@ export class PiProvider extends LLMProvider {
|
|
|
46
45
|
let settled = false;
|
|
47
46
|
let finished = false;
|
|
48
47
|
let usage: ChatResponse['usage'] = { promptTokens: 0, completionTokens: 0, cachedPromptTokens: 0 };
|
|
48
|
+
const nativeActions = new Map<string, ChatResponseAction>();
|
|
49
49
|
|
|
50
50
|
const cleanup = (): void => {
|
|
51
51
|
options.signal?.removeEventListener('abort', abort);
|
|
@@ -70,6 +70,7 @@ export class PiProvider extends LLMProvider {
|
|
|
70
70
|
resolve({
|
|
71
71
|
content: raw.replace(/<tool_call>[\s\S]*?<\/tool_call>/g, '').trim(),
|
|
72
72
|
usage,
|
|
73
|
+
externalActions: [...nativeActions.values()].filter(action => action.status !== 'running'),
|
|
73
74
|
toolCalls: this.formatter.extractToolCalls(raw)
|
|
74
75
|
});
|
|
75
76
|
};
|
|
@@ -105,6 +106,16 @@ export class PiProvider extends LLMProvider {
|
|
|
105
106
|
} else if (update?.type === 'thinking_delta' && typeof update.delta === 'string') {
|
|
106
107
|
options.onReasoningChunk?.(update.delta);
|
|
107
108
|
}
|
|
109
|
+
} else if (record.type === 'tool_execution_start' || record.type === 'tool_execution_end') {
|
|
110
|
+
const id = String(record.toolCallId || '');
|
|
111
|
+
const earlier = nativeActions.get(id);
|
|
112
|
+
const action: ChatResponseAction = {
|
|
113
|
+
id, name: String(record.toolName || earlier?.name || 'pi_tool'),
|
|
114
|
+
parameters: record.args || earlier?.parameters || {},
|
|
115
|
+
status: record.type === 'tool_execution_start' ? 'running' : record.isError ? 'failed' : 'completed'
|
|
116
|
+
};
|
|
117
|
+
nativeActions.set(id, action);
|
|
118
|
+
options.onNativeAction?.(action);
|
|
108
119
|
} else if (record.type === 'message_end' && record.message?.role === 'assistant') {
|
|
109
120
|
const message = record.message;
|
|
110
121
|
finalText = Array.isArray(message.content)
|
|
@@ -113,9 +124,10 @@ export class PiProvider extends LLMProvider {
|
|
|
113
124
|
stopReason = String(message.stopReason || '');
|
|
114
125
|
const data = message.usage || {};
|
|
115
126
|
usage = {
|
|
116
|
-
promptTokens: Number(data.input) || 0,
|
|
117
|
-
|
|
118
|
-
|
|
127
|
+
promptTokens: usage.promptTokens + (Number(data.input) || 0),
|
|
128
|
+
uncachedPromptTokens: (usage.uncachedPromptTokens || 0) + (Number(data.input) || 0),
|
|
129
|
+
completionTokens: usage.completionTokens + (Number(data.output) || 0),
|
|
130
|
+
cachedPromptTokens: (usage.cachedPromptTokens || 0) + (Number(data.cacheRead) || 0),
|
|
119
131
|
measurement: data.input != null && data.output != null ? 'provider_reported' : 'text_estimate',
|
|
120
132
|
cacheMeasurement: data.cacheRead != null ? 'provider_reported' : 'unavailable'
|
|
121
133
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
3
|
+
/** Preserve constraints and nested schemas; text peers need more than parameter names. */
|
|
4
|
+
export function normalizeToolContracts(tools) {
|
|
5
|
+
return tools.map(raw => {
|
|
6
|
+
const tool = object(raw);
|
|
7
|
+
const fn = object(tool.function);
|
|
8
|
+
return {
|
|
9
|
+
name: String(tool.name || fn.name || ''),
|
|
10
|
+
description: String(tool.description || fn.description || ''),
|
|
11
|
+
parameters: object(tool.parameters || tool.input_schema || fn.parameters)
|
|
12
|
+
};
|
|
13
|
+
}).filter(tool => tool.name).sort((a, b) => a.name.localeCompare(b.name));
|
|
14
|
+
}
|
|
15
|
+
export function contractFingerprint(value) {
|
|
16
|
+
const stable = (item) => Array.isArray(item) ? item.map(stable)
|
|
17
|
+
: item !== null && typeof item === 'object'
|
|
18
|
+
? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b)).map(([key, val]) => [key, stable(val)]))
|
|
19
|
+
: item;
|
|
20
|
+
return createHash('sha256').update(JSON.stringify(stable(value))).digest('hex');
|
|
21
|
+
}
|
|
22
|
+
export function formatToolContracts(tools) {
|
|
23
|
+
return normalizeToolContracts(tools).map(tool => JSON.stringify(tool)).join('\n');
|
|
24
|
+
}
|
|
25
|
+
/** Current allowlist plus only changed contracts, for peers retaining their own history. */
|
|
26
|
+
export function toolContractUpdate(tools, previous) {
|
|
27
|
+
const current = normalizeToolContracts(tools);
|
|
28
|
+
const before = new Map(normalizeToolContracts(previous).map(tool => [tool.name, contractFingerprint(tool)]));
|
|
29
|
+
if (contractFingerprint(current) === contractFingerprint(normalizeToolContracts(previous)))
|
|
30
|
+
return '';
|
|
31
|
+
const changed = current.filter(tool => before.get(tool.name) !== contractFingerprint(tool));
|
|
32
|
+
return '[Current Causyne tools — replaces the prior host allowlist only; peer-native tools remain available]\n'
|
|
33
|
+
+ JSON.stringify(current.map(tool => tool.name))
|
|
34
|
+
+ '\nUse retained schemas for unchanged tools. New or changed contracts (JSON Schema):\n'
|
|
35
|
+
+ changed.map(tool => JSON.stringify(tool)).join('\n');
|
|
36
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
type JsonObject = Record<string, unknown>;
|
|
4
|
+
export interface ToolContract {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
parameters: JsonObject;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const object = (value: unknown): JsonObject =>
|
|
11
|
+
value !== null && typeof value === 'object' && !Array.isArray(value) ? value as JsonObject : {};
|
|
12
|
+
|
|
13
|
+
/** Preserve constraints and nested schemas; text peers need more than parameter names. */
|
|
14
|
+
export function normalizeToolContracts(tools: readonly unknown[]): ToolContract[] {
|
|
15
|
+
return tools.map(raw => {
|
|
16
|
+
const tool = object(raw);
|
|
17
|
+
const fn = object(tool.function);
|
|
18
|
+
return {
|
|
19
|
+
name: String(tool.name || fn.name || ''),
|
|
20
|
+
description: String(tool.description || fn.description || ''),
|
|
21
|
+
parameters: object(tool.parameters || tool.input_schema || fn.parameters)
|
|
22
|
+
};
|
|
23
|
+
}).filter(tool => tool.name).sort((a, b) => a.name.localeCompare(b.name));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function contractFingerprint(value: unknown): string {
|
|
27
|
+
const stable = (item: unknown): unknown => Array.isArray(item) ? item.map(stable)
|
|
28
|
+
: item !== null && typeof item === 'object'
|
|
29
|
+
? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b)).map(([key, val]) => [key, stable(val)]))
|
|
30
|
+
: item;
|
|
31
|
+
return createHash('sha256').update(JSON.stringify(stable(value))).digest('hex');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function formatToolContracts(tools: readonly unknown[]): string {
|
|
35
|
+
return normalizeToolContracts(tools).map(tool => JSON.stringify(tool)).join('\n');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Current allowlist plus only changed contracts, for peers retaining their own history. */
|
|
39
|
+
export function toolContractUpdate(tools: readonly unknown[], previous: readonly unknown[]): string {
|
|
40
|
+
const current = normalizeToolContracts(tools);
|
|
41
|
+
const before = new Map(normalizeToolContracts(previous).map(tool => [tool.name, contractFingerprint(tool)]));
|
|
42
|
+
if (contractFingerprint(current) === contractFingerprint(normalizeToolContracts(previous))) return '';
|
|
43
|
+
const changed = current.filter(tool => before.get(tool.name) !== contractFingerprint(tool));
|
|
44
|
+
return '[Current Causyne tools — replaces the prior host allowlist only; peer-native tools remain available]\n'
|
|
45
|
+
+ JSON.stringify(current.map(tool => tool.name))
|
|
46
|
+
+ '\nUse retained schemas for unchanged tools. New or changed contracts (JSON Schema):\n'
|
|
47
|
+
+ changed.map(tool => JSON.stringify(tool)).join('\n');
|
|
48
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file src/session/sidechainEvents.ts
|
|
3
|
+
* Causyne Agent — Typed Condensation Events & Sidechain Auditing
|
|
4
|
+
*
|
|
5
|
+
* Ported & elevated from OpenHands (src/types/agent-server/core/events/condensation-event.ts).
|
|
6
|
+
* Models history compaction not as destructive deletion, but as an explicit,
|
|
7
|
+
* auditable event stream preserving forgotten_event_ids and recovery anchors.
|
|
8
|
+
*
|
|
9
|
+
* Authorship: Strict TypeScript (Causyne Agent).
|
|
10
|
+
*/
|
|
11
|
+
export class SidechainEventLog {
|
|
12
|
+
events = [];
|
|
13
|
+
append(event) {
|
|
14
|
+
this.events.push(event);
|
|
15
|
+
}
|
|
16
|
+
recordCondensation(forgottenIds, summary, reclaimedChars, finalChars, limitChars) {
|
|
17
|
+
const event = {
|
|
18
|
+
id: `cond_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
19
|
+
timestamp: Date.now(),
|
|
20
|
+
kind: 'Condensation',
|
|
21
|
+
source: 'environment',
|
|
22
|
+
forgotten_event_ids: [...forgottenIds],
|
|
23
|
+
summary,
|
|
24
|
+
summary_offset: this.events.length,
|
|
25
|
+
reclaimedChars,
|
|
26
|
+
finalChars,
|
|
27
|
+
limitChars
|
|
28
|
+
};
|
|
29
|
+
this.append(event);
|
|
30
|
+
return event;
|
|
31
|
+
}
|
|
32
|
+
getEvents() {
|
|
33
|
+
return this.events;
|
|
34
|
+
}
|
|
35
|
+
getForgottenIds() {
|
|
36
|
+
const set = new Set();
|
|
37
|
+
for (const event of this.events) {
|
|
38
|
+
if (event.kind === 'Condensation') {
|
|
39
|
+
for (const id of event.forgotten_event_ids) {
|
|
40
|
+
set.add(id);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return set;
|
|
45
|
+
}
|
|
46
|
+
serializeJsonl() {
|
|
47
|
+
return this.events.map(e => JSON.stringify(e)).join('\n') + '\n';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file src/session/sidechainEvents.ts
|
|
3
|
+
* Causyne Agent — Typed Condensation Events & Sidechain Auditing
|
|
4
|
+
*
|
|
5
|
+
* Ported & elevated from OpenHands (src/types/agent-server/core/events/condensation-event.ts).
|
|
6
|
+
* Models history compaction not as destructive deletion, but as an explicit,
|
|
7
|
+
* auditable event stream preserving forgotten_event_ids and recovery anchors.
|
|
8
|
+
*
|
|
9
|
+
* Authorship: Strict TypeScript (Causyne Agent).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export type EventSource = 'user' | 'agent' | 'environment';
|
|
13
|
+
|
|
14
|
+
export interface BaseSidechainEvent {
|
|
15
|
+
id: string;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
source: EventSource;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface CondensationEvent extends BaseSidechainEvent {
|
|
21
|
+
kind: 'Condensation';
|
|
22
|
+
source: 'environment';
|
|
23
|
+
forgotten_event_ids: string[];
|
|
24
|
+
summary: string;
|
|
25
|
+
summary_offset: number;
|
|
26
|
+
reclaimedChars: number;
|
|
27
|
+
finalChars: number;
|
|
28
|
+
limitChars: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ToolCallEvent extends BaseSidechainEvent {
|
|
32
|
+
kind: 'ToolCall';
|
|
33
|
+
tool: string;
|
|
34
|
+
callId: string;
|
|
35
|
+
arguments: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ToolObservationEvent extends BaseSidechainEvent {
|
|
39
|
+
kind: 'ToolObservation';
|
|
40
|
+
tool: string;
|
|
41
|
+
callId: string;
|
|
42
|
+
success: boolean;
|
|
43
|
+
outputLength: number;
|
|
44
|
+
spillPath?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type SidechainEvent = CondensationEvent | ToolCallEvent | ToolObservationEvent;
|
|
48
|
+
|
|
49
|
+
export class SidechainEventLog {
|
|
50
|
+
private events: SidechainEvent[] = [];
|
|
51
|
+
|
|
52
|
+
public append(event: SidechainEvent): void {
|
|
53
|
+
this.events.push(event);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public recordCondensation(
|
|
57
|
+
forgottenIds: string[],
|
|
58
|
+
summary: string,
|
|
59
|
+
reclaimedChars: number,
|
|
60
|
+
finalChars: number,
|
|
61
|
+
limitChars: number
|
|
62
|
+
): CondensationEvent {
|
|
63
|
+
const event: CondensationEvent = {
|
|
64
|
+
id: `cond_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
65
|
+
timestamp: Date.now(),
|
|
66
|
+
kind: 'Condensation',
|
|
67
|
+
source: 'environment',
|
|
68
|
+
forgotten_event_ids: [...forgottenIds],
|
|
69
|
+
summary,
|
|
70
|
+
summary_offset: this.events.length,
|
|
71
|
+
reclaimedChars,
|
|
72
|
+
finalChars,
|
|
73
|
+
limitChars
|
|
74
|
+
};
|
|
75
|
+
this.append(event);
|
|
76
|
+
return event;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public getEvents(): readonly SidechainEvent[] {
|
|
80
|
+
return this.events;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public getForgottenIds(): ReadonlySet<string> {
|
|
84
|
+
const set = new Set<string>();
|
|
85
|
+
for (const event of this.events) {
|
|
86
|
+
if (event.kind === 'Condensation') {
|
|
87
|
+
for (const id of event.forgotten_event_ids) {
|
|
88
|
+
set.add(id);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return set;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public serializeJsonl(): string {
|
|
96
|
+
return this.events.map(e => JSON.stringify(e)).join('\n') + '\n';
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/skillsManager.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export function detectWorkspaceDomains(...args: any[]): any;
|
|
2
2
|
export function ensureSkillRepo(...args: any[]): any;
|
|
3
3
|
export function getSkillDomainHeader(...args: any[]): any;
|
|
4
|
+
export function listCompiledSkills(): Array<{ id: string; name: string; domain: string; description?: string }>;
|
package/src/smartToolsUse.js
CHANGED
|
@@ -7,7 +7,105 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Authorship: Strict TypeScript (Causyne Agent).
|
|
9
9
|
*/
|
|
10
|
-
import { PACK_PLAYBOOKS } from './toolPacks.js';
|
|
10
|
+
import { PACK_PLAYBOOKS, isWebIntent } from './toolPacks.js';
|
|
11
|
+
import { isMutatingToolCall } from './decisionPolicy.js';
|
|
12
|
+
const INSPECTION_TOOLS = new Set([
|
|
13
|
+
'fs_read', 'fs_list', 'fs_find', 'fs_search', 'grep_search', 'code_searcher',
|
|
14
|
+
'codebase_search', 'web_search', 'web_fetch', 'browser_snapshot',
|
|
15
|
+
'browser_get_dom', 'view_image', 'pdf_read', 'dir_list'
|
|
16
|
+
]);
|
|
17
|
+
const VERIFICATION_TOOLS = new Set([
|
|
18
|
+
'screenshot', 'vision_inspect_ui', 'browser_console', 'ax_snapshot'
|
|
19
|
+
]);
|
|
20
|
+
function isInspection(toolName, args) {
|
|
21
|
+
if (INSPECTION_TOOLS.has(toolName))
|
|
22
|
+
return true;
|
|
23
|
+
if (toolName !== 'sysRun')
|
|
24
|
+
return false;
|
|
25
|
+
return /^\s*(?:pwd|ls|find|rg|grep|cat|sed|head|tail|git\s+(?:status|diff|log|show)|npm\s+(?:view|audit))\b/i
|
|
26
|
+
.test(String(args.command ?? ''));
|
|
27
|
+
}
|
|
28
|
+
function isVerification(toolName, args) {
|
|
29
|
+
if (VERIFICATION_TOOLS.has(toolName))
|
|
30
|
+
return true;
|
|
31
|
+
if (toolName !== 'sysRun')
|
|
32
|
+
return false;
|
|
33
|
+
return /^\s*(?:npm\s+(?:test|run\s+(?:test|typecheck|build))|node\s+--check|pytest|cargo\s+test|go\s+test)\b/i
|
|
34
|
+
.test(String(args.command ?? ''));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Bound each inspection batch to two calls, then yield to a synthesis step.
|
|
38
|
+
* Further evidence remains available after that planning boundary, so long
|
|
39
|
+
* research tasks do not deadlock. Exact repeated calls also use StallGuard.
|
|
40
|
+
*/
|
|
41
|
+
export class SmartToolsGovernor {
|
|
42
|
+
phase = 'inspection';
|
|
43
|
+
consecutiveInspections = 0;
|
|
44
|
+
mutationAttempted = false;
|
|
45
|
+
verificationObserved = false;
|
|
46
|
+
nudgeIssued = false;
|
|
47
|
+
get inspectionCapacity() { return Math.max(0, 2 - this.consecutiveInspections); }
|
|
48
|
+
beginModelStep() {
|
|
49
|
+
// A synthesis checkpoint yields to the planner; it does not prohibit
|
|
50
|
+
// additional evidence on research or long engineering tasks forever.
|
|
51
|
+
if (this.phase === 'synthesis') {
|
|
52
|
+
this.phase = 'inspection';
|
|
53
|
+
this.consecutiveInspections = 0;
|
|
54
|
+
this.nudgeIssued = false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
interceptAction(toolName, args) {
|
|
58
|
+
if (!isInspection(toolName, args) || isVerification(toolName, args))
|
|
59
|
+
return { allowed: true };
|
|
60
|
+
if (this.consecutiveInspections < 2)
|
|
61
|
+
return { allowed: true };
|
|
62
|
+
this.phase = 'synthesis';
|
|
63
|
+
return { allowed: false, reason: 'Inspection batch complete (2 actions). Synthesize the observations before another batch. '
|
|
64
|
+
+ 'Continue with a targeted edit or verification when evidence is sufficient; further research remains available in the next planning step.' };
|
|
65
|
+
}
|
|
66
|
+
reset() {
|
|
67
|
+
this.phase = 'inspection';
|
|
68
|
+
this.consecutiveInspections = 0;
|
|
69
|
+
this.mutationAttempted = false;
|
|
70
|
+
this.verificationObserved = false;
|
|
71
|
+
this.nudgeIssued = false;
|
|
72
|
+
}
|
|
73
|
+
snapshot() {
|
|
74
|
+
return {
|
|
75
|
+
phase: this.phase,
|
|
76
|
+
consecutiveInspections: this.consecutiveInspections,
|
|
77
|
+
mutationAttempted: this.mutationAttempted,
|
|
78
|
+
verificationObserved: this.verificationObserved
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
observe(toolName, args, result) {
|
|
82
|
+
if (isVerification(toolName, args)) {
|
|
83
|
+
this.phase = 'verification';
|
|
84
|
+
this.consecutiveInspections = 0;
|
|
85
|
+
if (result !== null && typeof result === 'object'
|
|
86
|
+
&& result.success === true) {
|
|
87
|
+
this.verificationObserved = true;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
if (isMutatingToolCall(toolName, args)) {
|
|
92
|
+
this.phase = 'execution';
|
|
93
|
+
this.mutationAttempted = true;
|
|
94
|
+
this.consecutiveInspections = 0;
|
|
95
|
+
this.nudgeIssued = false;
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (!isInspection(toolName, args))
|
|
99
|
+
return null;
|
|
100
|
+
this.consecutiveInspections++;
|
|
101
|
+
this.phase = this.consecutiveInspections >= 2 ? 'synthesis' : 'inspection';
|
|
102
|
+
if (this.consecutiveInspections === 2 && !this.nudgeIssued) {
|
|
103
|
+
this.nudgeIssued = true;
|
|
104
|
+
return 'Inspection batch complete. Synthesize what is known and choose the next useful step. Continue inspecting if the task still needs evidence; avoid repeating unchanged probes.';
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
11
109
|
// ---------------------------------------------------------------------------
|
|
12
110
|
// Intent Matchers & Negative Filters
|
|
13
111
|
// ---------------------------------------------------------------------------
|
|
@@ -21,9 +119,9 @@ const SYSTEM_ADMIN_PATTERN = /\b(kill process|kill port|check port|port \d+|lsof
|
|
|
21
119
|
// Simple file management operations
|
|
22
120
|
const SIMPLE_FILE_OP_PATTERN = /\b(list (the )?files|show files|count files|rename file(s)?|delete file(s)?|move file(s)?|clean (up )?folder)\b/i;
|
|
23
121
|
// Media generation intent (explicit creation of 3D, video, audio, or synthesized speech)
|
|
24
|
-
const EXPLICIT_MEDIA_GENERATION_PATTERN = /\b(blender|3d model|render 3d|render frame|render animation|da vinci|resolve|audio synth|synthesizer|text to speech|tts|voiceover|dubbing)\b/i;
|
|
122
|
+
const EXPLICIT_MEDIA_GENERATION_PATTERN = /\b(blender|3d model|render 3d|render frame|render animation|da vinci|resolve|audio synth|synthesizer|text to speech|tts|voiceover|dubbing)\b|\.blend\d*\b/i;
|
|
25
123
|
// Explicit web engineering intent
|
|
26
|
-
const EXPLICIT_WEB_ENGINEERING_PATTERN = /\b(build
|
|
124
|
+
const EXPLICIT_WEB_ENGINEERING_PATTERN = /\b(build|create|make|design|develop|implement|redesign|buat\w*)\b[\s\S]*\b(web|website|webpage|webapp|landing page|dashboard|ui|frontend|threejs|three\.js|3js)\b/i;
|
|
27
125
|
// Explicit game development intent
|
|
28
126
|
const EXPLICIT_GAME_DEV_PATTERN = /\b(build.*game|create.*game|develop.*game|godot|unity|unreal|platformer 2d|rpg game|arcade game)\b/i;
|
|
29
127
|
/**
|
|
@@ -110,6 +208,26 @@ export function determineToolScope(prompt, _taskShape) {
|
|
|
110
208
|
reason: 'Simple filesystem operation; suppresses external domain packs.'
|
|
111
209
|
};
|
|
112
210
|
}
|
|
211
|
+
if (EXPLICIT_WEB_ENGINEERING_PATTERN.test(text)) {
|
|
212
|
+
const tools = new Set([
|
|
213
|
+
'fs_write',
|
|
214
|
+
'fs_edit',
|
|
215
|
+
'fs_read',
|
|
216
|
+
'fs_list',
|
|
217
|
+
'sysRun',
|
|
218
|
+
'browser_act',
|
|
219
|
+
'screenshot',
|
|
220
|
+
'vision_inspect_ui',
|
|
221
|
+
'update_plan',
|
|
222
|
+
'tool_search'
|
|
223
|
+
]);
|
|
224
|
+
return {
|
|
225
|
+
toolScope: tools,
|
|
226
|
+
archetype: 'web_engineering',
|
|
227
|
+
suppressedPacks: ['media', 'game', 'advanced', 'system'],
|
|
228
|
+
reason: 'Web engineering intent focuses on filesystem authoring, terminal execution, and browser verification; suppresses unrelated media and game packs.'
|
|
229
|
+
};
|
|
230
|
+
}
|
|
113
231
|
// 5. Media / 3D generation & creative audio intent
|
|
114
232
|
if (EXPLICIT_MEDIA_GENERATION_PATTERN.test(text)) {
|
|
115
233
|
const tools = new Set([
|
|
@@ -170,7 +288,8 @@ export function resolveLazyPlaybooks(unlockedPacks, observedTools = [], prompt =
|
|
|
170
288
|
tools.has('vision_inspect_ui') ||
|
|
171
289
|
tools.has('screenshot') ||
|
|
172
290
|
tools.has('astryx_oracle');
|
|
173
|
-
const webExplicitDemand = EXPLICIT_WEB_ENGINEERING_PATTERN.test(text)
|
|
291
|
+
const webExplicitDemand = EXPLICIT_WEB_ENGINEERING_PATTERN.test(text)
|
|
292
|
+
|| (isWebIntent(text) && WEB_CONSTRUCTION_EXCLUSION.test(text));
|
|
174
293
|
if ((webToolInvoked || webExplicitDemand) && PACK_PLAYBOOKS.web) {
|
|
175
294
|
activePlaybooks.push(PACK_PLAYBOOKS.web);
|
|
176
295
|
activeDomains.push('web');
|
package/src/smartToolsUse.ts
CHANGED
|
@@ -8,7 +8,117 @@
|
|
|
8
8
|
* Authorship: Strict TypeScript (Causyne Agent).
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { PACK_PLAYBOOKS } from './toolPacks.js';
|
|
11
|
+
import { PACK_PLAYBOOKS, isWebIntent } from './toolPacks.js';
|
|
12
|
+
import { isMutatingToolCall } from './decisionPolicy.js';
|
|
13
|
+
|
|
14
|
+
export type ExecutionPhase = 'inspection' | 'synthesis' | 'execution' | 'verification';
|
|
15
|
+
|
|
16
|
+
export interface ToolPhaseSnapshot {
|
|
17
|
+
phase: ExecutionPhase;
|
|
18
|
+
consecutiveInspections: number;
|
|
19
|
+
mutationAttempted: boolean;
|
|
20
|
+
verificationObserved: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const INSPECTION_TOOLS = new Set([
|
|
24
|
+
'fs_read', 'fs_list', 'fs_find', 'fs_search', 'grep_search', 'code_searcher',
|
|
25
|
+
'codebase_search', 'web_search', 'web_fetch', 'browser_snapshot',
|
|
26
|
+
'browser_get_dom', 'view_image', 'pdf_read', 'dir_list'
|
|
27
|
+
]);
|
|
28
|
+
const VERIFICATION_TOOLS = new Set([
|
|
29
|
+
'screenshot', 'vision_inspect_ui', 'browser_console', 'ax_snapshot'
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
function isInspection(toolName: string, args: Record<string, unknown>): boolean {
|
|
33
|
+
if (INSPECTION_TOOLS.has(toolName)) return true;
|
|
34
|
+
if (toolName !== 'sysRun') return false;
|
|
35
|
+
return /^\s*(?:pwd|ls|find|rg|grep|cat|sed|head|tail|git\s+(?:status|diff|log|show)|npm\s+(?:view|audit))\b/i
|
|
36
|
+
.test(String(args.command ?? ''));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isVerification(toolName: string, args: Record<string, unknown>): boolean {
|
|
40
|
+
if (VERIFICATION_TOOLS.has(toolName)) return true;
|
|
41
|
+
if (toolName !== 'sysRun') return false;
|
|
42
|
+
return /^\s*(?:npm\s+(?:test|run\s+(?:test|typecheck|build))|node\s+--check|pytest|cargo\s+test|go\s+test)\b/i
|
|
43
|
+
.test(String(args.command ?? ''));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Bound each inspection batch to two calls, then yield to a synthesis step.
|
|
48
|
+
* Further evidence remains available after that planning boundary, so long
|
|
49
|
+
* research tasks do not deadlock. Exact repeated calls also use StallGuard.
|
|
50
|
+
*/
|
|
51
|
+
export class SmartToolsGovernor {
|
|
52
|
+
private phase: ExecutionPhase = 'inspection';
|
|
53
|
+
private consecutiveInspections = 0;
|
|
54
|
+
private mutationAttempted = false;
|
|
55
|
+
private verificationObserved = false;
|
|
56
|
+
private nudgeIssued = false;
|
|
57
|
+
|
|
58
|
+
get inspectionCapacity(): number { return Math.max(0, 2 - this.consecutiveInspections); }
|
|
59
|
+
|
|
60
|
+
beginModelStep(): void {
|
|
61
|
+
// A synthesis checkpoint yields to the planner; it does not prohibit
|
|
62
|
+
// additional evidence on research or long engineering tasks forever.
|
|
63
|
+
if (this.phase === 'synthesis') {
|
|
64
|
+
this.phase = 'inspection';
|
|
65
|
+
this.consecutiveInspections = 0;
|
|
66
|
+
this.nudgeIssued = false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interceptAction(toolName: string, args: Record<string, unknown>): { allowed: boolean; reason?: string } {
|
|
71
|
+
if (!isInspection(toolName, args) || isVerification(toolName, args)) return { allowed: true };
|
|
72
|
+
if (this.consecutiveInspections < 2) return { allowed: true };
|
|
73
|
+
this.phase = 'synthesis';
|
|
74
|
+
return { allowed: false, reason: 'Inspection batch complete (2 actions). Synthesize the observations before another batch. '
|
|
75
|
+
+ 'Continue with a targeted edit or verification when evidence is sufficient; further research remains available in the next planning step.' };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
reset(): void {
|
|
79
|
+
this.phase = 'inspection';
|
|
80
|
+
this.consecutiveInspections = 0;
|
|
81
|
+
this.mutationAttempted = false;
|
|
82
|
+
this.verificationObserved = false;
|
|
83
|
+
this.nudgeIssued = false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
snapshot(): ToolPhaseSnapshot {
|
|
87
|
+
return {
|
|
88
|
+
phase: this.phase,
|
|
89
|
+
consecutiveInspections: this.consecutiveInspections,
|
|
90
|
+
mutationAttempted: this.mutationAttempted,
|
|
91
|
+
verificationObserved: this.verificationObserved
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
observe(toolName: string, args: Record<string, unknown>, result: unknown): string | null {
|
|
96
|
+
if (isVerification(toolName, args)) {
|
|
97
|
+
this.phase = 'verification';
|
|
98
|
+
this.consecutiveInspections = 0;
|
|
99
|
+
if (result !== null && typeof result === 'object'
|
|
100
|
+
&& (result as Record<string, unknown>).success === true) {
|
|
101
|
+
this.verificationObserved = true;
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
if (isMutatingToolCall(toolName, args)) {
|
|
106
|
+
this.phase = 'execution';
|
|
107
|
+
this.mutationAttempted = true;
|
|
108
|
+
this.consecutiveInspections = 0;
|
|
109
|
+
this.nudgeIssued = false;
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
if (!isInspection(toolName, args)) return null;
|
|
113
|
+
this.consecutiveInspections++;
|
|
114
|
+
this.phase = this.consecutiveInspections >= 2 ? 'synthesis' : 'inspection';
|
|
115
|
+
if (this.consecutiveInspections === 2 && !this.nudgeIssued) {
|
|
116
|
+
this.nudgeIssued = true;
|
|
117
|
+
return 'Inspection batch complete. Synthesize what is known and choose the next useful step. Continue inspecting if the task still needs evidence; avoid repeating unchanged probes.';
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
12
122
|
|
|
13
123
|
export interface SmartToolsScopeResult {
|
|
14
124
|
readonly toolScope: Set<string> | null;
|
|
@@ -49,11 +159,11 @@ const SIMPLE_FILE_OP_PATTERN =
|
|
|
49
159
|
|
|
50
160
|
// Media generation intent (explicit creation of 3D, video, audio, or synthesized speech)
|
|
51
161
|
const EXPLICIT_MEDIA_GENERATION_PATTERN =
|
|
52
|
-
/\b(blender|3d model|render 3d|render frame|render animation|da vinci|resolve|audio synth|synthesizer|text to speech|tts|voiceover|dubbing)\b/i;
|
|
162
|
+
/\b(blender|3d model|render 3d|render frame|render animation|da vinci|resolve|audio synth|synthesizer|text to speech|tts|voiceover|dubbing)\b|\.blend\d*\b/i;
|
|
53
163
|
|
|
54
164
|
// Explicit web engineering intent
|
|
55
165
|
const EXPLICIT_WEB_ENGINEERING_PATTERN =
|
|
56
|
-
/\b(build
|
|
166
|
+
/\b(build|create|make|design|develop|implement|redesign|buat\w*)\b[\s\S]*\b(web|website|webpage|webapp|landing page|dashboard|ui|frontend|threejs|three\.js|3js)\b/i;
|
|
57
167
|
|
|
58
168
|
// Explicit game development intent
|
|
59
169
|
const EXPLICIT_GAME_DEV_PATTERN =
|
|
@@ -151,6 +261,27 @@ export function determineToolScope(
|
|
|
151
261
|
};
|
|
152
262
|
}
|
|
153
263
|
|
|
264
|
+
if (EXPLICIT_WEB_ENGINEERING_PATTERN.test(text)) {
|
|
265
|
+
const tools = new Set([
|
|
266
|
+
'fs_write',
|
|
267
|
+
'fs_edit',
|
|
268
|
+
'fs_read',
|
|
269
|
+
'fs_list',
|
|
270
|
+
'sysRun',
|
|
271
|
+
'browser_act',
|
|
272
|
+
'screenshot',
|
|
273
|
+
'vision_inspect_ui',
|
|
274
|
+
'update_plan',
|
|
275
|
+
'tool_search'
|
|
276
|
+
]);
|
|
277
|
+
return {
|
|
278
|
+
toolScope: tools,
|
|
279
|
+
archetype: 'web_engineering',
|
|
280
|
+
suppressedPacks: ['media', 'game', 'advanced', 'system'],
|
|
281
|
+
reason: 'Web engineering intent focuses on filesystem authoring, terminal execution, and browser verification; suppresses unrelated media and game packs.'
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
154
285
|
// 5. Media / 3D generation & creative audio intent
|
|
155
286
|
if (EXPLICIT_MEDIA_GENERATION_PATTERN.test(text)) {
|
|
156
287
|
const tools = new Set([
|
|
@@ -226,7 +357,8 @@ export function resolveLazyPlaybooks(
|
|
|
226
357
|
tools.has('vision_inspect_ui') ||
|
|
227
358
|
tools.has('screenshot') ||
|
|
228
359
|
tools.has('astryx_oracle');
|
|
229
|
-
const webExplicitDemand = EXPLICIT_WEB_ENGINEERING_PATTERN.test(text)
|
|
360
|
+
const webExplicitDemand = EXPLICIT_WEB_ENGINEERING_PATTERN.test(text)
|
|
361
|
+
|| (isWebIntent(text) && WEB_CONSTRUCTION_EXCLUSION.test(text));
|
|
230
362
|
|
|
231
363
|
if ((webToolInvoked || webExplicitDemand) && PACK_PLAYBOOKS.web) {
|
|
232
364
|
activePlaybooks.push(PACK_PLAYBOOKS.web);
|