@causyne/agent 1.20.12 → 1.20.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +1 -1
  2. package/package.json +1 -1
  3. package/src/SmartTools.js +33 -0
  4. package/src/SmartTools.ts +37 -0
  5. package/src/acp/client.js +157 -4
  6. package/src/acp/client.ts +152 -5
  7. package/src/agentLoop.js +857 -178
  8. package/src/agentLoop.ts +865 -183
  9. package/src/browser/browserRuntime.js +8 -1
  10. package/src/browser/browserRuntime.ts +8 -1
  11. package/src/browser/causyneBrowser.js +20 -4
  12. package/src/browser/causyneBrowser.ts +20 -4
  13. package/src/browser/urlPolicy.js +35 -0
  14. package/src/browser/urlPolicy.ts +34 -0
  15. package/src/cliMode.js +6 -2
  16. package/src/commands.js +14 -0
  17. package/src/contextManager.d.ts +1 -0
  18. package/src/core/contextCompactor.js +277 -0
  19. package/src/core/contextCompactor.ts +353 -0
  20. package/src/decideTools.js +157 -0
  21. package/src/decideTools.ts +195 -0
  22. package/src/decisionPolicy.js +5 -3
  23. package/src/decisionPolicy.ts +5 -3
  24. package/src/implementationPlan.js +284 -0
  25. package/src/implementationPlan.ts +275 -0
  26. package/src/observer/coldObserver.js +10 -4
  27. package/src/observer/coldObserver.ts +15 -7
  28. package/src/observer/evidence.js +11 -5
  29. package/src/observer/evidence.ts +13 -6
  30. package/src/observer.js +196 -0
  31. package/src/observer.ts +287 -0
  32. package/src/providers/acp.js +362 -109
  33. package/src/providers/acp.ts +359 -111
  34. package/src/providers/antigravity.js +133 -105
  35. package/src/providers/antigravity.ts +130 -109
  36. package/src/providers/base.d.ts +3 -0
  37. package/src/providers/budgetEnforcer.js +13 -0
  38. package/src/providers/budgetEnforcer.ts +13 -3
  39. package/src/provisioning/capabilityProvisioner.js +14 -10
  40. package/src/sandbox.js +4 -2
  41. package/src/saveTools.js +146 -0
  42. package/src/saveTools.ts +169 -0
  43. package/src/session/cachePressure.js +77 -0
  44. package/src/session/cachePressure.ts +122 -0
  45. package/src/smartToolsUse.js +69 -12
  46. package/src/smartToolsUse.ts +103 -12
  47. package/src/taskShape.js +7 -7
  48. package/src/taskShape.ts +7 -7
  49. package/src/timeMachine.js +55 -20
  50. package/src/timeMachine.ts +64 -20
  51. package/src/toolPacks.js +217 -310
  52. package/src/toolPacks.ts +505 -0
  53. package/src/tools/deferredMcpSearch.js +21 -13
  54. package/src/tools/deferredMcpSearch.ts +23 -15
  55. package/src/tools/updatePlan.js +2 -2
  56. package/src/tools/updatePlan.ts +2 -2
  57. package/src/toolsList.js +203 -0
  58. package/src/toolsList.ts +224 -0
  59. package/src/tui/chatRenderer.js +49 -14
  60. package/src/tui/codeStreamRenderer.js +16 -5
  61. package/src/tui/codeStreamRenderer.ts +14 -4
  62. package/src/tui/prompt.js +4 -2
  63. package/src/tui/sessionSidebar.js +10 -2
  64. package/src/tui/sessionSidebar.ts +10 -3
  65. package/src/tui/stageSurface.js +27 -1
  66. package/src/tui/text.d.ts +1 -0
  67. package/src/tui/turnRail.js +274 -0
  68. package/src/tui/turnRail.ts +334 -0
  69. package/src/types/contracts.ts +103 -0
  70. package/src/verificationPlan.js +141 -0
  71. package/src/verificationPlan.ts +166 -0
  72. package/src/toolPacks.d.ts +0 -10
@@ -0,0 +1,166 @@
1
+ /**
2
+ * @file src/verificationPlan.ts
3
+ * Verification stage of the pipeline.
4
+ *
5
+ * ... AgentLoop -> near completion -> verify -> Observer -> TimeMachine
6
+ *
7
+ * Work is not finished when the model says so; it is finished when evidence of
8
+ * the right KIND exists. What counts depends on what was produced: code is run
9
+ * or checked, a page is rendered and looked at, a render or image is viewed, a
10
+ * document is read back. File moves, deletes and the like are not here on
11
+ * purpose: the tool's own success result is already their evidence.
12
+ *
13
+ * Everything here reads the observer's journal — what actually ran — and never
14
+ * the model's account of it.
15
+ *
16
+ * Authorship: Strict TypeScript (Causyne Agent).
17
+ */
18
+
19
+ import type { ToolOutcome } from './observer/evidence.js';
20
+ import { isVerificationCommand } from './observer/evidence.js';
21
+
22
+ export type VerificationDomain = 'code' | 'web' | 'creative' | 'document';
23
+
24
+ export interface VerificationGap {
25
+ readonly domain: VerificationDomain;
26
+ /** What evidence is missing, in words a model can act on. */
27
+ readonly need: string;
28
+ /** Listed tools that can produce it; fed back through decideTools. */
29
+ readonly tools: readonly string[];
30
+ }
31
+
32
+ export interface VerificationAssessment {
33
+ readonly domains: readonly VerificationDomain[];
34
+ readonly gaps: readonly VerificationGap[];
35
+ /** Empty when nothing is missing. */
36
+ readonly directive: string;
37
+ }
38
+
39
+ export interface VerificationInput {
40
+ readonly archetype?: string | undefined;
41
+ readonly outcomes: readonly ToolOutcome[];
42
+ /** Domains another gate already enforces, so they are not nagged twice. */
43
+ readonly skip?: readonly VerificationDomain[];
44
+ }
45
+
46
+ const CODE_MUTATORS = new Set([
47
+ 'fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'write_to_file', 'edit_file',
48
+ 'replace_file_content', 'multi_replace_file_content', 'write', 'edit', 'multiedit'
49
+ ]);
50
+ const CREATIVE_MUTATORS = new Set([
51
+ 'blender_act', 'creative_apps', 'execute_procedural_media', 'generate_media_via_api',
52
+ 'native_engine', 'resolve_act', 'palmier_act', 'game_audio_synth'
53
+ ]);
54
+
55
+ const WEB_PATH = /\.(?:html?|css|scss|jsx|tsx|vue|svelte)$/i;
56
+ const CODE_PATH = /\.(?:[cm]?[jt]s|py|rb|php|go|rs|java|kt|kts|swift|c|cc|cpp|h|hpp|cs|sh|sql)$/i;
57
+ const DOCUMENT_PATH = /\.(?:pdf|docx?|pptx?|odt|rtf|epub)$/i;
58
+ const IMAGE_PATH = /\.(?:png|jpe?g|webp|gif|bmp)$/i;
59
+
60
+ const RUN_COMMAND = /^\s*(?:node|python3?|ruby|php|deno|bun|go\s+run|cargo\s+run|dotnet\s+run|swift\s+run|java|npm\s+(?:start|run\s+(?:dev|start)))\b/i;
61
+ const MEDIA_PROBE = /\b(?:ffprobe|afinfo|soxi|identify|mediainfo|exiftool)\b/i;
62
+
63
+ const READBACK_TOOLS = new Set(['pdf_read', 'fs_read', 'view_image', 'vision_inspect_ui', 'screenshot']);
64
+ const LOOK_TOOLS = new Set(['view_image', 'vision_inspect_ui', 'screenshot']);
65
+
66
+ function isMutation(outcome: ToolOutcome): boolean {
67
+ if (!outcome.success) return false;
68
+ const tool = outcome.tool;
69
+ if (CODE_MUTATORS.has(tool) || CREATIVE_MUTATORS.has(tool)) return true;
70
+ if (tool === 'document_forge') return true;
71
+ return false;
72
+ }
73
+
74
+ function domainsOf(input: VerificationInput, mutations: readonly ToolOutcome[]): VerificationDomain[] {
75
+ const found = new Set<VerificationDomain>();
76
+ for (const outcome of mutations) {
77
+ const tool = outcome.tool;
78
+ const target = outcome.path || '';
79
+ if (CREATIVE_MUTATORS.has(tool)) found.add('creative');
80
+ else if (tool === 'document_forge' || DOCUMENT_PATH.test(target)) found.add('document');
81
+ else if (CODE_MUTATORS.has(tool)) {
82
+ if (WEB_PATH.test(target)) found.add('web');
83
+ else if (CODE_PATH.test(target)) found.add('code');
84
+ }
85
+ }
86
+ if (input.archetype === 'web_engineering' && found.has('code')) found.add('web');
87
+ return [...found];
88
+ }
89
+
90
+ function after(outcomes: readonly ToolOutcome[], domain: VerificationDomain): readonly ToolOutcome[] {
91
+ const matches = (outcome: ToolOutcome): boolean => {
92
+ if (!isMutation(outcome)) return false;
93
+ const target = outcome.path || '';
94
+ switch (domain) {
95
+ case 'creative': return CREATIVE_MUTATORS.has(outcome.tool);
96
+ case 'document': return outcome.tool === 'document_forge' || DOCUMENT_PATH.test(target);
97
+ case 'web': return CODE_MUTATORS.has(outcome.tool) && WEB_PATH.test(target);
98
+ case 'code': return CODE_MUTATORS.has(outcome.tool) && CODE_PATH.test(target);
99
+ }
100
+ };
101
+ return outcomes.slice(outcomes.findLastIndex(matches) + 1);
102
+ }
103
+
104
+ function satisfied(domain: VerificationDomain, evidence: readonly ToolOutcome[]): boolean {
105
+ const ok = evidence.filter((outcome) => outcome.success);
106
+ switch (domain) {
107
+ case 'code':
108
+ return ok.some((outcome) => outcome.tool === 'code_verify_syntax'
109
+ || isVerificationCommand(outcome.command)
110
+ || (RUN_COMMAND.test(outcome.command) && outcome.exitCode === 0));
111
+ case 'web':
112
+ return ok.some((outcome) => outcome.rendered === true);
113
+ case 'creative':
114
+ return ok.some((outcome) => outcome.observedImage === true
115
+ || MEDIA_PROBE.test(outcome.command));
116
+ case 'document':
117
+ return ok.some((outcome) => outcome.observedImage === true
118
+ || (['pdf_read', 'fs_read'].includes(outcome.tool) && DOCUMENT_PATH.test(outcome.path)));
119
+ }
120
+ }
121
+
122
+ const NEEDS: Readonly<Record<VerificationDomain, { need: string; tools: readonly string[] }>> = {
123
+ code: {
124
+ need: 'run the code or its tests, build, or a syntax check (sysRun, code_verify_syntax)',
125
+ tools: ['sysRun', 'code_verify_syntax']
126
+ },
127
+ web: {
128
+ need: 'render the page (browser_act preview, then snapshot) and look at it (screenshot or vision_inspect_ui)',
129
+ tools: ['browser_act', 'screenshot']
130
+ },
131
+ creative: {
132
+ need: 'look at the produced image, render or frame (view_image or vision_inspect_ui) and probe audio or video output',
133
+ tools: ['view_image', 'vision_inspect_ui']
134
+ },
135
+ document: {
136
+ need: 'read the produced document back (pdf_read, fs_read or view_image) and confirm it matches the request',
137
+ tools: ['pdf_read', 'view_image']
138
+ }
139
+ };
140
+
141
+ /**
142
+ * What evidence is still missing for what this task actually produced. Nothing
143
+ * produced means nothing to verify: research and conversation are never nagged.
144
+ */
145
+ export function assessVerification(input: VerificationInput): VerificationAssessment {
146
+ const mutations = input.outcomes.filter(isMutation);
147
+ if (mutations.length === 0) return { domains: [], gaps: [], directive: '' };
148
+
149
+ const skip = new Set(input.skip ?? []);
150
+ const domains = domainsOf(input, mutations);
151
+ const gaps: VerificationGap[] = [];
152
+ for (const domain of domains) {
153
+ if (skip.has(domain)) continue;
154
+ if (satisfied(domain, after(input.outcomes, domain))) continue;
155
+ gaps.push({ domain, ...NEEDS[domain] });
156
+ }
157
+ if (gaps.length === 0) return { domains, gaps, directive: '' };
158
+
159
+ const needs = gaps.map((gap) => `${gap.domain}: ${gap.need}`).join('; ');
160
+ return {
161
+ domains,
162
+ gaps,
163
+ directive: `[VERIFY] You changed things but no evidence of the right kind exists yet. Before you finish — ${needs}. `
164
+ + 'If a check cannot be run, say so plainly instead of claiming success.'
165
+ };
166
+ }
@@ -1,10 +0,0 @@
1
- export function routePacks(...args: any[]): any;
2
- export function packForTool(...args: any[]): any;
3
- export function isCoreTool(...args: any[]): any;
4
- export function isGameIntent(...args: any[]): any;
5
- export function isWebIntent(...args: any[]): any;
6
- export function getPackCatalogue(...args: any[]): any;
7
- export const PACK_PLAYBOOKS: any;
8
- export const PACKS: any;
9
- export const PACK_NAMES: string[];
10
- export function isResidentTool(toolName: string): boolean;