@causyne/agent 1.20.85 → 1.20.86

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.20.85",
3
+ "version": "1.20.86",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
@@ -1,29 +1,35 @@
1
1
  /**
2
- * Keep the full execution trail, but collapse the second, visually redundant
3
- * success row once a long tool-heavy run is underway. A failure, a non-empty
4
- * output, a diagnostic, or any missing result stays expanded.
2
+ * Presentation-only compaction of completed, silent tool steps.
5
3
  *
6
- * Only the presentation changes. Original tool results still pass through
7
- * captureLastOutput() and the AgentLoop is not affected.
4
+ * Never drop errors, unknown diagnostics, structured results, or output. The
5
+ * AgentLoop's execution contract and underlying result object are unchanged.
6
+ * This TypeScript file is the single source of truth; `toolActivityPolicy.js`
7
+ * is the existing runtime compiler's emitted output.
8
8
  */
9
9
  export const TOOL_ACTIVITY_COMPACT_AFTER = 8;
10
-
10
+ const METADATA_ONLY = new Set([
11
+ 'success', 'exitCode', 'exit_code', 'durationMs', 'elapsedMs',
12
+ 'duration', 'statusCode', 'status_code'
13
+ ]);
14
+ /** Returns true only for a known silent success that can share its step row. */
11
15
  export function compactSuccessfulToolResult(stepCount, result, tail, toolName) {
12
- if (!Number.isFinite(stepCount) || stepCount < TOOL_ACTIVITY_COMPACT_AFTER) return false;
13
- if (!result || result.success !== true) return false;
14
- if (!tail || tail.kind !== 'step' || !tail.meta) return false;
15
- if (tail.meta.step !== stepCount || String(tail.meta.tool ?? '') !== String(toolName ?? '')) return false;
16
- // Only truly silent successes qualify. Unknown provider-specific result
17
- // fields must remain visible, rather than being hidden by an allowlist of
18
- // familiar output property names.
19
- const metadataOnly = new Set([
20
- 'success', 'exitCode', 'exit_code', 'durationMs', 'elapsedMs', 'duration',
21
- 'statusCode', 'status_code'
22
- ]);
23
- for (const [key, value] of Object.entries(result)) {
24
- if (metadataOnly.has(key)) continue;
25
- if (value == null || value === '' || (Array.isArray(value) && value.length === 0)) continue;
26
- return false;
27
- }
28
- return true;
16
+ if (!Number.isFinite(stepCount) || stepCount < TOOL_ACTIVITY_COMPACT_AFTER)
17
+ return false;
18
+ if (result === null || typeof result !== 'object' || Array.isArray(result))
19
+ return false;
20
+ const record = result;
21
+ if (record.success !== true)
22
+ return false;
23
+ if (!tail || tail.kind !== 'step' || !tail.meta)
24
+ return false;
25
+ if (tail.meta.step !== stepCount || String(tail.meta.tool ?? '') !== String(toolName ?? ''))
26
+ return false;
27
+ for (const [key, value] of Object.entries(record)) {
28
+ if (METADATA_ONLY.has(key))
29
+ continue;
30
+ if (value == null || value === '' || (Array.isArray(value) && value.length === 0))
31
+ continue;
32
+ return false;
33
+ }
34
+ return true;
29
35
  }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Presentation-only compaction of completed, silent tool steps.
3
+ *
4
+ * Never drop errors, unknown diagnostics, structured results, or output. The
5
+ * AgentLoop's execution contract and underlying result object are unchanged.
6
+ * This TypeScript file is the single source of truth; `toolActivityPolicy.js`
7
+ * is the existing runtime compiler's emitted output.
8
+ */
9
+
10
+ export const TOOL_ACTIVITY_COMPACT_AFTER = 8;
11
+
12
+ export interface ToolActivityFrame {
13
+ readonly kind?: string;
14
+ readonly meta?: Readonly<Record<string, unknown>> | null;
15
+ }
16
+
17
+ const METADATA_ONLY = new Set([
18
+ 'success', 'exitCode', 'exit_code', 'durationMs', 'elapsedMs',
19
+ 'duration', 'statusCode', 'status_code'
20
+ ]);
21
+
22
+ /** Returns true only for a known silent success that can share its step row. */
23
+ export function compactSuccessfulToolResult(
24
+ stepCount: number,
25
+ result: unknown,
26
+ tail: ToolActivityFrame | null | undefined,
27
+ toolName: unknown
28
+ ): boolean {
29
+ if (!Number.isFinite(stepCount) || stepCount < TOOL_ACTIVITY_COMPACT_AFTER) return false;
30
+ if (result === null || typeof result !== 'object' || Array.isArray(result)) return false;
31
+ const record = result as Readonly<Record<string, unknown>>;
32
+ if (record.success !== true) return false;
33
+ if (!tail || tail.kind !== 'step' || !tail.meta) return false;
34
+ if (tail.meta.step !== stepCount || String(tail.meta.tool ?? '') !== String(toolName ?? '')) return false;
35
+
36
+ for (const [key, value] of Object.entries(record)) {
37
+ if (METADATA_ONLY.has(key)) continue;
38
+ if (value == null || value === '' || (Array.isArray(value) && value.length === 0)) continue;
39
+ return false;
40
+ }
41
+ return true;
42
+ }
@@ -1,77 +1,80 @@
1
1
  /**
2
- * Preserve the reader's location while terminal geometry changes.
2
+ * Frame-anchored viewport reflow for Causyne's Stage/Transcript architecture.
3
3
  *
4
- * Row indices are screen-layout positions, not document positions. Re-wrapping a
5
- * transcript changes frame heights, so keeping the same numeric scrollTop can
6
- * jump to unrelated content. Frame identity + relative offset is stable across
7
- * width changes, without storing or duplicating any message content.
4
+ * Numeric scroll rows are layout coordinates. They change when a terminal is
5
+ * resized, whereas a transcript frame's ID remains stable. Preserve the frame
6
+ * identity and the approximate relative reading position within that frame.
8
7
  *
9
- * This module is deliberately independent of Stage, Transcript, and Node I/O.
8
+ * TypeScript is the authoritative source. Runtime JS is produced by the
9
+ * repository's existing `tsc -p tsconfig.runtime.json` build.
10
10
  */
11
-
12
11
  function finiteRow(value) {
13
- return Number.isFinite(value) ? Math.max(0, Math.floor(value)) : 0;
12
+ return Number.isFinite(value) ? Math.max(0, Math.floor(value)) : 0;
14
13
  }
15
-
16
14
  function safeMarkers(markers) {
17
- if (!Array.isArray(markers)) return [];
18
- return markers
19
- .filter(marker => marker && Number.isFinite(marker.row) && marker.row >= 0)
20
- .map((marker, index) => ({
21
- id: marker.id,
22
- row: finiteRow(marker.row),
23
- originalIndex: index
24
- }));
15
+ if (!Array.isArray(markers))
16
+ return [];
17
+ return markers.flatMap((marker, originalIndex) => {
18
+ if (!marker || !Number.isFinite(marker.row) || marker.row < 0)
19
+ return [];
20
+ return [{ id: marker.id, row: finiteRow(marker.row), originalIndex }];
21
+ });
25
22
  }
26
-
27
- /** Capture an anchor at the first visible row, measured within its frame. */
23
+ /** Capture the first currently visible frame and relative position within it. */
28
24
  export function captureReadingAnchor(markers, top, totalHeight) {
29
- const entries = safeMarkers(markers);
30
- if (!entries.length) return null;
31
- const row = finiteRow(top);
32
- let selected = 0;
33
- for (let i = 0; i < entries.length; i++) {
34
- if (entries[i].row > row) break;
35
- selected = i;
36
- }
37
- const start = entries[selected].row;
38
- const next = entries[selected + 1]?.row ?? finiteRow(totalHeight);
39
- const frameLength = Math.max(1, next - start);
40
- return Object.freeze({
41
- id: entries[selected].id ?? null,
42
- index: entries[selected].originalIndex,
43
- offset: Math.max(0, row - start),
44
- fraction: Math.max(0, Math.min(1, (row - start) / frameLength)),
45
- originalTop: row
46
- });
25
+ const entries = safeMarkers(markers);
26
+ if (entries.length === 0)
27
+ return null;
28
+ const row = finiteRow(top);
29
+ let selected = 0;
30
+ for (let i = 0; i < entries.length; i++) {
31
+ if ((entries[i]?.row ?? Number.POSITIVE_INFINITY) > row)
32
+ break;
33
+ selected = i;
34
+ }
35
+ const entry = entries[selected];
36
+ if (!entry)
37
+ return null;
38
+ const start = entry.row;
39
+ const next = entries[selected + 1]?.row ?? finiteRow(totalHeight);
40
+ const frameLength = Math.max(1, next - start);
41
+ return Object.freeze({
42
+ id: entry.id ?? null,
43
+ index: entry.originalIndex,
44
+ offset: Math.max(0, row - start),
45
+ fraction: Math.max(0, Math.min(1, (row - start) / frameLength)),
46
+ originalTop: row
47
+ });
47
48
  }
48
-
49
- /** Restore to the corresponding frame and approximately the same content line. */
49
+ /** Restore the matching frame and a proportional content offset after reflow. */
50
50
  export function restoreReadingAnchor(anchor, markers, totalHeight, viewportHeight) {
51
- const total = finiteRow(totalHeight);
52
- const visible = Math.max(1, finiteRow(viewportHeight));
53
- const max = Math.max(0, total - visible);
54
- if (!anchor || !max) return 0;
55
- const entries = safeMarkers(markers);
56
- if (!entries.length) return Math.min(max, finiteRow(anchor.originalTop));
57
-
58
- let selected = anchor.id == null
59
- ? -1
60
- : entries.findIndex(marker => marker.id === anchor.id);
61
- if (selected < 0 && anchor.id == null && entries[anchor.index]?.originalIndex === anchor.index) {
62
- selected = anchor.index;
63
- }
64
- if (selected < 0) {
65
- // Frames may have been evicted while the user was reading. Use the first
66
- // surviving frame rather than silently jumping to an unrelated old row.
67
- selected = 0;
68
- }
69
- const start = entries[selected].row;
70
- const end = entries[selected + 1]?.row ?? total;
71
- const length = Math.max(1, end - start);
72
- const fraction = Number.isFinite(anchor.fraction) ? Math.max(0, Math.min(1, anchor.fraction)) : 0;
73
- // Relative position is more useful than raw offset after a long paragraph
74
- // wraps from 15 lines to 30, while staying inside the same frame.
75
- const offset = Math.min(length - 1, Math.round(fraction * length));
76
- return Math.max(0, Math.min(max, start + offset));
51
+ const total = finiteRow(totalHeight);
52
+ const visible = Math.max(1, finiteRow(viewportHeight));
53
+ const max = Math.max(0, total - visible);
54
+ if (!anchor || max === 0)
55
+ return 0;
56
+ const entries = safeMarkers(markers);
57
+ if (entries.length === 0)
58
+ return Math.min(max, finiteRow(anchor.originalTop));
59
+ let selected = anchor.id == null
60
+ ? -1
61
+ : entries.findIndex(marker => marker.id === anchor.id);
62
+ if (selected < 0 && anchor.id == null && entries[anchor.index]?.originalIndex === anchor.index) {
63
+ selected = anchor.index;
64
+ }
65
+ if (selected < 0) {
66
+ // When the anchored frame was evicted, recover in the surviving transcript.
67
+ selected = 0;
68
+ }
69
+ const entry = entries[selected];
70
+ if (!entry)
71
+ return Math.min(max, finiteRow(anchor.originalTop));
72
+ const start = entry.row;
73
+ const end = entries[selected + 1]?.row ?? total;
74
+ const length = Math.max(1, end - start);
75
+ const fraction = Number.isFinite(anchor.fraction)
76
+ ? Math.max(0, Math.min(1, anchor.fraction))
77
+ : 0;
78
+ const offset = Math.min(length - 1, Math.round(fraction * length));
79
+ return Math.max(0, Math.min(max, start + offset));
77
80
  }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Frame-anchored viewport reflow for Causyne's Stage/Transcript architecture.
3
+ *
4
+ * Numeric scroll rows are layout coordinates. They change when a terminal is
5
+ * resized, whereas a transcript frame's ID remains stable. Preserve the frame
6
+ * identity and the approximate relative reading position within that frame.
7
+ *
8
+ * TypeScript is the authoritative source. Runtime JS is produced by the
9
+ * repository's existing `tsc -p tsconfig.runtime.json` build.
10
+ */
11
+
12
+ export interface ReadingMarker {
13
+ readonly id?: number;
14
+ readonly row: number;
15
+ readonly kind?: string;
16
+ }
17
+
18
+ export interface ReadingAnchor {
19
+ readonly id: number | null;
20
+ readonly index: number;
21
+ readonly offset: number;
22
+ readonly fraction: number;
23
+ readonly originalTop: number;
24
+ }
25
+
26
+ interface SafeMarker {
27
+ readonly id: number | undefined;
28
+ readonly row: number;
29
+ readonly originalIndex: number;
30
+ }
31
+
32
+ function finiteRow(value: number): number {
33
+ return Number.isFinite(value) ? Math.max(0, Math.floor(value)) : 0;
34
+ }
35
+
36
+ function safeMarkers(markers: readonly ReadingMarker[] | null | undefined): SafeMarker[] {
37
+ if (!Array.isArray(markers)) return [];
38
+ return markers.flatMap((marker, originalIndex): SafeMarker[] => {
39
+ if (!marker || !Number.isFinite(marker.row) || marker.row < 0) return [];
40
+ return [{ id: marker.id, row: finiteRow(marker.row), originalIndex }];
41
+ });
42
+ }
43
+
44
+ /** Capture the first currently visible frame and relative position within it. */
45
+ export function captureReadingAnchor(
46
+ markers: readonly ReadingMarker[] | null | undefined,
47
+ top: number,
48
+ totalHeight: number
49
+ ): ReadingAnchor | null {
50
+ const entries = safeMarkers(markers);
51
+ if (entries.length === 0) return null;
52
+ const row = finiteRow(top);
53
+ let selected = 0;
54
+ for (let i = 0; i < entries.length; i++) {
55
+ if ((entries[i]?.row ?? Number.POSITIVE_INFINITY) > row) break;
56
+ selected = i;
57
+ }
58
+ const entry = entries[selected];
59
+ if (!entry) return null;
60
+ const start = entry.row;
61
+ const next = entries[selected + 1]?.row ?? finiteRow(totalHeight);
62
+ const frameLength = Math.max(1, next - start);
63
+ return Object.freeze({
64
+ id: entry.id ?? null,
65
+ index: entry.originalIndex,
66
+ offset: Math.max(0, row - start),
67
+ fraction: Math.max(0, Math.min(1, (row - start) / frameLength)),
68
+ originalTop: row
69
+ });
70
+ }
71
+
72
+ /** Restore the matching frame and a proportional content offset after reflow. */
73
+ export function restoreReadingAnchor(
74
+ anchor: ReadingAnchor | null,
75
+ markers: readonly ReadingMarker[] | null | undefined,
76
+ totalHeight: number,
77
+ viewportHeight: number
78
+ ): number {
79
+ const total = finiteRow(totalHeight);
80
+ const visible = Math.max(1, finiteRow(viewportHeight));
81
+ const max = Math.max(0, total - visible);
82
+ if (!anchor || max === 0) return 0;
83
+ const entries = safeMarkers(markers);
84
+ if (entries.length === 0) return Math.min(max, finiteRow(anchor.originalTop));
85
+
86
+ let selected = anchor.id == null
87
+ ? -1
88
+ : entries.findIndex(marker => marker.id === anchor.id);
89
+ if (selected < 0 && anchor.id == null && entries[anchor.index]?.originalIndex === anchor.index) {
90
+ selected = anchor.index;
91
+ }
92
+ if (selected < 0) {
93
+ // When the anchored frame was evicted, recover in the surviving transcript.
94
+ selected = 0;
95
+ }
96
+ const entry = entries[selected];
97
+ if (!entry) return Math.min(max, finiteRow(anchor.originalTop));
98
+ const start = entry.row;
99
+ const end = entries[selected + 1]?.row ?? total;
100
+ const length = Math.max(1, end - start);
101
+ const fraction = Number.isFinite(anchor.fraction)
102
+ ? Math.max(0, Math.min(1, anchor.fraction))
103
+ : 0;
104
+ const offset = Math.min(length - 1, Math.round(fraction * length));
105
+ return Math.max(0, Math.min(max, start + offset));
106
+ }
@@ -1,19 +0,0 @@
1
- export interface ReadingMarker { id?: number; row: number; kind?: string }
2
- export interface ReadingAnchor {
3
- readonly id: number | null;
4
- readonly index: number;
5
- readonly offset: number;
6
- readonly fraction: number;
7
- readonly originalTop: number;
8
- }
9
- export declare function captureReadingAnchor(
10
- markers: ReadingMarker[] | null | undefined,
11
- top: number,
12
- totalHeight: number
13
- ): ReadingAnchor | null;
14
- export declare function restoreReadingAnchor(
15
- anchor: ReadingAnchor | null,
16
- markers: ReadingMarker[] | null | undefined,
17
- totalHeight: number,
18
- viewportHeight: number
19
- ): number;