@causyne/agent 1.20.116 → 1.20.118

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 (59) hide show
  1. package/package.json +7 -2
  2. package/src/agentLoop.js +81 -31
  3. package/src/agentLoop.ts +82 -33
  4. package/src/browser/causyneBrowser.js +30 -7
  5. package/src/browser/causyneBrowser.ts +29 -7
  6. package/src/cliMode.js +24 -4
  7. package/src/commands.js +7 -1
  8. package/src/memory/scopedFacts.js +171 -0
  9. package/src/memory/scopedFacts.ts +214 -0
  10. package/src/memory.d.ts +13 -1
  11. package/src/memory.js +9 -12
  12. package/src/perception.js +124 -3
  13. package/src/perception.ts +128 -4
  14. package/src/planCache.js +17 -3
  15. package/src/planCache.ts +17 -3
  16. package/src/plugins/pluginManager.js +74 -0
  17. package/src/reporting.js +12 -4
  18. package/src/skillsManager.js +3 -2
  19. package/src/skillsManager.ts +3 -2
  20. package/src/smartToolsUse.js +4 -5
  21. package/src/smartToolsUse.ts +4 -6
  22. package/src/taskShape.js +49 -7
  23. package/src/taskShape.ts +55 -7
  24. package/src/toolPacks.js +27 -5
  25. package/src/toolPacks.ts +32 -5
  26. package/src/tools/memoryWrite.js +8 -10
  27. package/src/tools/memoryWrite.ts +13 -11
  28. package/src/tools/pluginManager.js +17 -2
  29. package/src/tui/chatRenderer.js +4 -1
  30. package/src/tui/codeProgress.js +3 -2
  31. package/src/tui/codeProgress.ts +3 -2
  32. package/src/tui/codeStreamRenderer.js +41 -15
  33. package/src/tui/codeStreamRenderer.ts +40 -15
  34. package/src/tui/composerControls.js +16 -3
  35. package/src/tui/composerControls.ts +14 -3
  36. package/src/tui/keys.js +3 -1
  37. package/src/tui/prompt.js +146 -16
  38. package/src/tui/scrollInteraction.js +2 -2
  39. package/src/tui/scrollInteraction.ts +2 -2
  40. package/src/tui/stageSurface.js +114 -4
  41. package/src/tui/turnRail.js +21 -14
  42. package/src/tui/turnRail.ts +19 -14
  43. package/src/tui/usageCard.js +164 -71
  44. package/src/tui/usageCard.ts +187 -96
  45. package/src/tui/workspaceSwitch.js +2 -0
  46. package/src/tui/workspaceSwitch.ts +1 -0
  47. package/src/types/contracts.ts +3 -0
  48. package/src/verification/boundedExplorer.js +119 -0
  49. package/src/verification/cliProbe.js +116 -0
  50. package/src/verification/featureMap.js +78 -0
  51. package/src/verification/interactivePty.js +188 -0
  52. package/src/verification/propertyProbe.js +121 -0
  53. package/src/verification/ptyProbe.js +125 -0
  54. package/src/verification/skillCatalog.d.ts +1 -0
  55. package/src/verification/skillCatalog.js +60 -0
  56. package/src/verification/statechart.js +143 -0
  57. package/src/verification/uiRuntime.js +57 -0
  58. package/src/verificationPlan.js +1 -1
  59. package/src/verificationPlan.ts +1 -1
@@ -0,0 +1,143 @@
1
+ const DEFAULT_MAX_STATES = 256;
2
+ const DEFAULT_MAX_DEPTH = 7;
3
+
4
+ function finiteBound(value, fallback, maximum, label) {
5
+ const bound = value === undefined ? fallback : value;
6
+ if (!Number.isSafeInteger(bound) || bound < 0 || bound > maximum) {
7
+ throw new RangeError('Invalid ' + label);
8
+ }
9
+ return bound;
10
+ }
11
+
12
+ function clone(value) {
13
+ try {
14
+ return structuredClone(value);
15
+ } catch {
16
+ throw new TypeError('State and actions must be structured-cloneable');
17
+ }
18
+ }
19
+
20
+ function textLabel(value, limit = 80) {
21
+ const cleaned = String(value ?? '')
22
+ .replace(/[\x00-\x1f\x7f<>"\x60\\|[\]{};#]/g, ' ')
23
+ .replace(/\s+/g, ' ')
24
+ .trim();
25
+ return (cleaned || 'unnamed').slice(0, limit);
26
+ }
27
+
28
+ function callSync(fn, value, label) {
29
+ const result = fn(clone(value));
30
+ if (result && typeof result.then === 'function') {
31
+ throw new TypeError('Async ' + label + ' is not supported');
32
+ }
33
+ return result;
34
+ }
35
+
36
+ function assertion(invariant, state) {
37
+ const value = callSync(invariant, state, 'invariant');
38
+ return value === true ? null : textLabel(
39
+ typeof value === 'string' ? value : 'Invariant returned false', 200
40
+ );
41
+ }
42
+
43
+ export function buildBoundedStatechart(options = {}) {
44
+ const { initial, actions, transition, invariant } = options;
45
+ const stateKey = options.stateKey || JSON.stringify;
46
+ const stateLabel = options.stateLabel || (value => JSON.stringify(value));
47
+ const actionLabel = options.actionLabel || (value => String(value));
48
+ const maxDepth = finiteBound(options.maxDepth, DEFAULT_MAX_DEPTH, 16, 'maxDepth');
49
+ const maxStates = finiteBound(options.maxStates, DEFAULT_MAX_STATES, 2000, 'maxStates');
50
+
51
+ if (!Array.isArray(actions) || actions.length < 1 || actions.length > 64) {
52
+ throw new RangeError('Action alphabet must contain 1..64 entries');
53
+ }
54
+ if (!maxStates) throw new RangeError('maxStates must be positive');
55
+ for (const fn of [transition, invariant, stateKey, stateLabel, actionLabel]) {
56
+ if (typeof fn !== 'function') throw new TypeError('Model callbacks must be functions');
57
+ }
58
+
59
+ const alphabet = actions.map(clone);
60
+ const root = clone(initial);
61
+ const nodes = [];
62
+ const edges = [];
63
+ const byKey = new Map();
64
+ const failures = [];
65
+ let incomplete = false;
66
+ let exploredDepth = 0;
67
+
68
+ function getKey(value) {
69
+ const key = callSync(stateKey, value, 'stateKey');
70
+ if (typeof key !== 'string') throw new TypeError('stateKey must return a string');
71
+ return key;
72
+ }
73
+
74
+ function addNode(state, trace) {
75
+ const id = 'S' + nodes.length;
76
+ const label = callSync(stateLabel, state, 'stateLabel');
77
+ const reason = assertion(invariant, state);
78
+ const node = { id, state: clone(state), trace, depth: trace.length,
79
+ label: textLabel(label), reason };
80
+ nodes.push(node);
81
+ byKey.set(getKey(state), node);
82
+ if (reason && failures.length < 32) {
83
+ failures.push({ state: id, trace: trace.map(item => item.label), reason });
84
+ }
85
+ return node;
86
+ }
87
+
88
+ addNode(root, []);
89
+ for (let head = 0; head < nodes.length && !incomplete; head++) {
90
+ const node = nodes[head];
91
+ exploredDepth = Math.max(exploredDepth, node.depth);
92
+ if (node.depth >= maxDepth) continue;
93
+
94
+ for (const action of alphabet) {
95
+ const label = textLabel(callSync(actionLabel, action, 'actionLabel'), 50);
96
+ const next = transition(clone(node.state), clone(action));
97
+ if (next && typeof next.then === 'function') {
98
+ throw new TypeError('Async transitions are not supported');
99
+ }
100
+ if (next === undefined || next === null) continue;
101
+ const stable = clone(next);
102
+ const nextKey = getKey(stable);
103
+ let target = byKey.get(nextKey);
104
+
105
+ if (target && !isEquivalent(target.state, stable)) {
106
+ throw new Error('stateKey collision: distinct states share a key');
107
+ }
108
+ if (!target && nodes.length >= maxStates) {
109
+ incomplete = true;
110
+ break;
111
+ }
112
+ if (!target) {
113
+ target = addNode(stable, node.trace.concat({ label }));
114
+ }
115
+ edges.push({ from: node.id, to: target.id, action: label });
116
+ }
117
+ }
118
+
119
+ const lines = ['stateDiagram-v2', ' [*] --> S0'];
120
+ for (const node of nodes) {
121
+ lines.push(' state "' + node.label + '" as ' + node.id);
122
+ }
123
+ for (const edge of edges) {
124
+ lines.push(' ' + edge.from + ' --> ' + edge.to + ': ' + edge.action);
125
+ }
126
+ for (const fail of failures) {
127
+ lines.push(' note right of ' + fail.state + ': ' + fail.reason);
128
+ }
129
+
130
+ return {
131
+ status: failures.length ? 'counterexample' : incomplete ? 'incomplete' : 'bounded-pass',
132
+ completeWithinBounds: !incomplete, maxDepth, maxStates,
133
+ stateCount: nodes.length, transitionCount: edges.length,
134
+ exploredDepth, counterexamples: failures, diagram: lines.join('\n') + '\n',
135
+ evidence: 'Bounded exploration of the supplied JavaScript transition function, not a TLA+ TLC run or an unbounded proof'
136
+ };
137
+ }
138
+
139
+ function isEquivalent(left, right) {
140
+ if (Object.is(left, right)) return true;
141
+ try { return JSON.stringify(left) === JSON.stringify(right); }
142
+ catch { return false; }
143
+ }
@@ -0,0 +1,57 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { runInteractivePty } from './interactivePty.js';
5
+
6
+ export async function verifyCausyneTui(options = {}) {
7
+ const workspace = options.workspace || process.cwd();
8
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'causyne-ui-verify-'));
9
+ try {
10
+ const result = await runInteractivePty({
11
+ workspace, script: 'tests/fixtures/liveTuiTarget.mjs',
12
+ timeoutMs: options.timeoutMs ?? 15000,
13
+ rows: options.rows ?? 42,
14
+ columns: options.columns ?? 126,
15
+ env: { CAUSYNE_HOME: home },
16
+ steps: [
17
+ { name: 'open-usage', waitFor: 'CAUSYNE_VERIFY_READY',
18
+ input: '/usage\r', contains: 'Usage & Context' },
19
+ { name: 'submit-while-pinned', waitFor: 'Usage & Context',
20
+ input: 'verification-message\r', contains: 'CAUSYNE_VERIFY_MESSAGE_OK' },
21
+ { name: 'switch-to-status', waitFor: 'CAUSYNE_VERIFY_MESSAGE_OK',
22
+ input: '/status\r', contains: 'Status' },
23
+ { name: 'submit-while-status-pinned', waitFor: 'Status',
24
+ input: 'verify-exit\r', contains: 'CAUSYNE_VERIFY_EXIT_OK' }
25
+ ]
26
+ });
27
+ return { ...result, feature: 'tui-usage',
28
+ evidence: 'Observed actual ChatPrompt and StageSurface terminal output at each input boundary' };
29
+ } finally {
30
+ fs.rmSync(home, { recursive: true, force: true });
31
+ }
32
+ }
33
+
34
+ export async function verifyCausyneChatMode(options = {}) {
35
+ const workspace = options.workspace || process.cwd();
36
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'causyne-chat-verify-'));
37
+ try {
38
+ const result = await runInteractivePty({
39
+ workspace, script: 'tests/fixtures/liveChatModeTarget.mjs',
40
+ timeoutMs: options.timeoutMs ?? 18000,
41
+ rows: options.rows ?? 42, columns: options.columns ?? 126,
42
+ env: { CAUSYNE_HOME: home },
43
+ steps: [
44
+ { name: 'open-real-chat', waitFor: 'enter send',
45
+ input: '/usage\r', contains: 'Usage & Context' },
46
+ { name: 'real-chat-status', waitFor: 'Usage & Context',
47
+ input: '/status\r', contains: 'Status' },
48
+ { name: 'real-chat-exit', waitFor: 'Status',
49
+ input: 'exit\r', contains: 'exit' }
50
+ ]
51
+ });
52
+ return { ...result, feature: 'tui-chat-mode',
53
+ evidence: 'Launched Causyne chatMode and observed command handling in real POSIX PTY' };
54
+ } finally {
55
+ fs.rmSync(home, { recursive: true, force: true });
56
+ }
57
+ }
@@ -91,7 +91,7 @@ function after(outcomes, domain) {
91
91
  return outcomes.slice(outcomes.findLastIndex(matches) + 1);
92
92
  }
93
93
  function satisfied(domain, evidence) {
94
- const ok = evidence.filter((outcome) => outcome.success);
94
+ const ok = evidence.filter((outcome) => outcome.success && (outcome.exitCode === null || outcome.exitCode === 0));
95
95
  switch (domain) {
96
96
  case 'code':
97
97
  return ok.some((outcome) => outcome.tool === 'code_verify_syntax'
@@ -114,7 +114,7 @@ function after(outcomes: readonly ToolOutcome[], domain: VerificationDomain): re
114
114
  }
115
115
 
116
116
  function satisfied(domain: VerificationDomain, evidence: readonly ToolOutcome[]): boolean {
117
- const ok = evidence.filter((outcome) => outcome.success);
117
+ const ok = evidence.filter((outcome) => outcome.success && (outcome.exitCode === null || outcome.exitCode === 0));
118
118
  switch (domain) {
119
119
  case 'code':
120
120
  return ok.some((outcome) => outcome.tool === 'code_verify_syntax'