@reticlehq/core 1.3.1 → 2.0.1
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/README.md +14 -88
- package/dist/brand.d.ts +21 -0
- package/dist/brand.d.ts.map +1 -0
- package/dist/brand.js +16 -0
- package/dist/brand.js.map +1 -0
- package/dist/constants.d.ts +378 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +352 -0
- package/dist/constants.js.map +1 -0
- package/dist/daemon-registry.d.ts +36 -0
- package/dist/daemon-registry.d.ts.map +1 -0
- package/dist/daemon-registry.js +48 -0
- package/dist/daemon-registry.js.map +1 -0
- package/dist/flow-constants.d.ts +175 -0
- package/dist/flow-constants.d.ts.map +1 -0
- package/dist/flow-constants.js +162 -0
- package/dist/flow-constants.js.map +1 -0
- package/dist/flow-types.d.ts +1204 -0
- package/dist/flow-types.d.ts.map +1 -0
- package/dist/flow-types.js +152 -0
- package/dist/flow-types.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -5563
- package/dist/index.js.map +1 -0
- package/dist/messages.d.ts +424 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +103 -0
- package/dist/messages.js.map +1 -0
- package/dist/notices.d.ts +60 -0
- package/dist/notices.d.ts.map +1 -0
- package/dist/notices.js +64 -0
- package/dist/notices.js.map +1 -0
- package/dist/schema/command-message.json +41 -0
- package/dist/schema/command-result.json +34 -0
- package/dist/schema/event-message.json +77 -0
- package/dist/schema/event-type.json +35 -0
- package/dist/schema/hello-message.json +59 -0
- package/dist/schema/reticle-event.json +63 -0
- package/dist/schema/reticle-message.json +193 -0
- package/dist/security.d.ts +5 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +22 -0
- package/dist/security.js.map +1 -0
- package/dist/session-constants.d.ts +116 -0
- package/dist/session-constants.d.ts.map +1 -0
- package/dist/session-constants.js +113 -0
- package/dist/session-constants.js.map +1 -0
- package/dist/state-select.d.ts +23 -0
- package/dist/state-select.d.ts.map +1 -0
- package/dist/state-select.js +60 -0
- package/dist/state-select.js.map +1 -0
- package/dist/toon.d.ts +44 -0
- package/dist/toon.d.ts.map +1 -0
- package/dist/toon.js +153 -0
- package/dist/toon.js.map +1 -0
- package/dist/types.d.ts +833 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +165 -0
- package/dist/types.js.map +1 -0
- package/dist/upgrade.d.ts +74 -0
- package/dist/upgrade.d.ts.map +1 -0
- package/dist/upgrade.js +87 -0
- package/dist/upgrade.js.map +1 -0
- package/dist/verification-run.d.ts +1195 -0
- package/dist/verification-run.d.ts.map +1 -0
- package/dist/verification-run.js +261 -0
- package/dist/verification-run.js.map +1 -0
- package/package.json +32 -79
- package/dist/babel.d.ts +0 -7
- package/dist/babel.js +0 -32
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -11273
- package/dist/eslint.d.ts +0 -1
- package/dist/eslint.js +0 -134
- package/dist/loader.cjs +0 -52
- package/dist/next.d.ts +0 -21
- package/dist/next.js +0 -24
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -9495
- package/dist/test.d.ts +0 -1
- package/dist/test.js +0 -9377
- package/dist/vite.d.ts +0 -1
- package/dist/vite.js +0 -196
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session lifecycle, health, control, and lease constants. Split out of constants.ts to keep each
|
|
3
|
+
* file under the cohesion cap; re-exported from the package index, so importers are unaffected.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Live-control: per-session lifecycle state (server-owned). The presenter panel mirrors it.
|
|
7
|
+
* `active → paused → active … → ended`; `ended` is terminal.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SessionState: {
|
|
10
|
+
readonly ACTIVE: "active";
|
|
11
|
+
readonly PAUSED: "paused";
|
|
12
|
+
readonly ENDED: "ended";
|
|
13
|
+
};
|
|
14
|
+
export type SessionState = (typeof SessionState)[keyof typeof SessionState];
|
|
15
|
+
/** Narrow an unknown wire value to a SessionState (no zod needed at this membership boundary). */
|
|
16
|
+
export declare function isSessionState(value: unknown): value is SessionState;
|
|
17
|
+
/**
|
|
18
|
+
* Sentinel session label meaning "give this tab its own unique id". The SDK maps it (and an absent
|
|
19
|
+
* label) to a per-tab id so several tabs — a human tab + an Reticle-driven tour, a Director-cut popup —
|
|
20
|
+
* never collide on one session id. Pass an explicit label only when tabs should intentionally share.
|
|
21
|
+
*/
|
|
22
|
+
export declare const SESSION_AUTO = "auto";
|
|
23
|
+
/** Live-control: kinds a human can emit from the panel (the `kind` of a HUMAN_CONTROL event). */
|
|
24
|
+
export declare const HumanControlKind: {
|
|
25
|
+
readonly PAUSE: "pause";
|
|
26
|
+
readonly RESUME: "resume";
|
|
27
|
+
readonly END: "end";
|
|
28
|
+
readonly MESSAGE: "message";
|
|
29
|
+
/** Human clicked ▶ on a saved flow in the panel — replay it (no agent). `text` carries the name. */
|
|
30
|
+
readonly REPLAY: "replay";
|
|
31
|
+
};
|
|
32
|
+
export type HumanControlKind = (typeof HumanControlKind)[keyof typeof HumanControlKind];
|
|
33
|
+
/**
|
|
34
|
+
* Human review marks: the durability tier of the anchor that pins a mark to an element. Mirrors the
|
|
35
|
+
* browser's auto-anchor AnchorStrategy values (testid > component@source > role > position) so the
|
|
36
|
+
* agent draining a mark knows how trustworthy the element address is. Wire-owned here because the
|
|
37
|
+
* mark crosses browser → bridge → agent; the browser maps its synthesized anchor onto these.
|
|
38
|
+
*/
|
|
39
|
+
export declare const MarkAnchorStrategy: {
|
|
40
|
+
readonly TESTID: "testid";
|
|
41
|
+
readonly COMPONENT: "component";
|
|
42
|
+
readonly ROLE: "role";
|
|
43
|
+
readonly POSITION: "position";
|
|
44
|
+
};
|
|
45
|
+
export type MarkAnchorStrategy = (typeof MarkAnchorStrategy)[keyof typeof MarkAnchorStrategy];
|
|
46
|
+
/** Human review marks: lifecycle of a mark in the server-side review store. */
|
|
47
|
+
export declare const MarkStatus: {
|
|
48
|
+
/** Flagged by the human, not yet addressed by the agent. */
|
|
49
|
+
readonly PENDING: "pending";
|
|
50
|
+
/** The agent claimed the mark as fixed (reticle_review resolve). Terminal. */
|
|
51
|
+
readonly RESOLVED: "resolved";
|
|
52
|
+
};
|
|
53
|
+
export type MarkStatus = (typeof MarkStatus)[keyof typeof MarkStatus];
|
|
54
|
+
/**
|
|
55
|
+
* SDK page-health heartbeat cadence (native timer) and the server's
|
|
56
|
+
* throttle threshold. Kept named so the server's staleness check can be reasoned about
|
|
57
|
+
* against the SDK's heartbeat (≈ 2 missed heartbeats ⇒ throttled).
|
|
58
|
+
*/
|
|
59
|
+
export declare const SESSION_HEALTH: {
|
|
60
|
+
readonly HEARTBEAT_MS: 5000;
|
|
61
|
+
/** lastSeenMs beyond this ⇒ throttled (≈ 2 missed heartbeats). */
|
|
62
|
+
readonly STALE_THRESHOLD_MS: 12000;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Server-authoritative session liveness. The browser-side idle timer is throttled in a backgrounded
|
|
66
|
+
* tab and dies entirely if the agent (MCP client) kills the bridge — so the Node server (immune to
|
|
67
|
+
* throttling) owns the decision: a session whose AGENT has been idle past `IDLE_END_MS` is reaped and
|
|
68
|
+
* ended via a PRESENTER push (which a throttled tab still receives). `BRIDGE_LOST_MS` is the browser's
|
|
69
|
+
* own fallback: when it cannot reach the bridge for this long (server/agent process gone), it ends the
|
|
70
|
+
* session itself so the HUD never sits "running" forever.
|
|
71
|
+
*/
|
|
72
|
+
export declare const SESSION_LIFECYCLE: {
|
|
73
|
+
/**
|
|
74
|
+
* Default agent-idle window before the panel hands back to the human as WAITING. The agent signals
|
|
75
|
+
* this IMMEDIATELY via reticle_yield; this reaper is only the slow backstop for a forgotten yield, so
|
|
76
|
+
* it's deliberately long (a short window would auto-end a session mid slow-step). reticle_session-tunable.
|
|
77
|
+
*/
|
|
78
|
+
readonly IDLE_END_MS: 300000;
|
|
79
|
+
/** Floor for a tuned idle window (so an agent can't disable the safety net). */
|
|
80
|
+
readonly IDLE_END_MIN_MS: 5000;
|
|
81
|
+
/** How often the server reaper sweeps sessions for idle/disconnected ones. */
|
|
82
|
+
readonly REAP_INTERVAL_MS: 5000;
|
|
83
|
+
/** Browser fallback: continuous failure to reach the bridge for this long ⇒ self-end the session. */
|
|
84
|
+
readonly BRIDGE_LOST_MS: 15000;
|
|
85
|
+
/**
|
|
86
|
+
* Daemon self-shutdown: after this long with NO agent connected, NO browser session, and NO pool
|
|
87
|
+
* lease, the detached daemon tears itself down (closes Chromium + bridge, frees the port, removes its
|
|
88
|
+
* pidfile, exits) so Reticle never lingers eating resources after the editor closes. Long enough to
|
|
89
|
+
* survive brief agent reconnects between turns; overridable via RETICLE_IDLE_SHUTDOWN_MS (0 = never).
|
|
90
|
+
*/
|
|
91
|
+
readonly DAEMON_IDLE_SHUTDOWN_MS: 300000;
|
|
92
|
+
/** How often the daemon checks whether it has gone idle. Unref'd, so it never keeps the process up. */
|
|
93
|
+
readonly DAEMON_IDLE_CHECK_MS: 30000;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Coding-agent session hygiene thresholds. Coding agents (Claude Code, Codex, Cursor) often
|
|
97
|
+
* complete their task and close their context without calling reticle_end_session. These constants
|
|
98
|
+
* drive two passive reminder layers: a one-time session_lease on first call, and recurring
|
|
99
|
+
* session_age_warning fields after WARN_AFTER_MS.
|
|
100
|
+
*/
|
|
101
|
+
export declare const SESSION_LEASE: {
|
|
102
|
+
/** ms after which age warnings appear on every session-bound tool result. */
|
|
103
|
+
readonly WARN_AFTER_MS: 600000;
|
|
104
|
+
/** ms after which reticle_sessions marks a session as stale. */
|
|
105
|
+
readonly STALE_AFTER_MS: 1800000;
|
|
106
|
+
};
|
|
107
|
+
/** Why the SDK emitted a PAGE_HEALTH event. */
|
|
108
|
+
export declare const HealthReason: {
|
|
109
|
+
readonly VISIBILITY: "visibilitychange";
|
|
110
|
+
readonly FOCUS: "focus";
|
|
111
|
+
readonly BLUR: "blur";
|
|
112
|
+
readonly HEARTBEAT: "heartbeat";
|
|
113
|
+
readonly INITIAL: "initial";
|
|
114
|
+
};
|
|
115
|
+
export type HealthReason = (typeof HealthReason)[keyof typeof HealthReason];
|
|
116
|
+
//# sourceMappingURL=session-constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-constants.d.ts","sourceRoot":"","sources":["../src/session-constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AACX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAE5E,kGAAkG;AAClG,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAIpE;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,SAAS,CAAC;AAEnC,iGAAiG;AACjG,eAAO,MAAM,gBAAgB;;;;;IAK3B,oGAAoG;;CAE5F,CAAC;AACX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,OAAO,gBAAgB,CAAC,CAAC;AAExF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;CAKrB,CAAC;AACX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAE9F,+EAA+E;AAC/E,eAAO,MAAM,UAAU;IACrB,4DAA4D;;IAE5D,8EAA8E;;CAEtE,CAAC;AACX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAEtE;;;;GAIG;AACH,eAAO,MAAM,cAAc;;IAEzB,kEAAkE;;CAE1D,CAAC;AAEX;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;IAC5B;;;;OAIG;;IAEH,gFAAgF;;IAEhF,8EAA8E;;IAE9E,qGAAqG;;IAErG;;;;;OAKG;;IAEH,uGAAuG;;CAE/F,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,aAAa;IACxB,6EAA6E;;IAE7E,gEAAgE;;CAExD,CAAC;AAEX,+CAA+C;AAC/C,eAAO,MAAM,YAAY;;;;;;CAMf,CAAC;AACX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session lifecycle, health, control, and lease constants. Split out of constants.ts to keep each
|
|
3
|
+
* file under the cohesion cap; re-exported from the package index, so importers are unaffected.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Live-control: per-session lifecycle state (server-owned). The presenter panel mirrors it.
|
|
7
|
+
* `active → paused → active … → ended`; `ended` is terminal.
|
|
8
|
+
*/
|
|
9
|
+
export const SessionState = {
|
|
10
|
+
ACTIVE: 'active',
|
|
11
|
+
PAUSED: 'paused',
|
|
12
|
+
ENDED: 'ended',
|
|
13
|
+
};
|
|
14
|
+
/** Narrow an unknown wire value to a SessionState (no zod needed at this membership boundary). */
|
|
15
|
+
export function isSessionState(value) {
|
|
16
|
+
return (value === SessionState.ACTIVE || value === SessionState.PAUSED || value === SessionState.ENDED);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Sentinel session label meaning "give this tab its own unique id". The SDK maps it (and an absent
|
|
20
|
+
* label) to a per-tab id so several tabs — a human tab + an Reticle-driven tour, a Director-cut popup —
|
|
21
|
+
* never collide on one session id. Pass an explicit label only when tabs should intentionally share.
|
|
22
|
+
*/
|
|
23
|
+
export const SESSION_AUTO = 'auto';
|
|
24
|
+
/** Live-control: kinds a human can emit from the panel (the `kind` of a HUMAN_CONTROL event). */
|
|
25
|
+
export const HumanControlKind = {
|
|
26
|
+
PAUSE: 'pause',
|
|
27
|
+
RESUME: 'resume',
|
|
28
|
+
END: 'end',
|
|
29
|
+
MESSAGE: 'message',
|
|
30
|
+
/** Human clicked ▶ on a saved flow in the panel — replay it (no agent). `text` carries the name. */
|
|
31
|
+
REPLAY: 'replay',
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Human review marks: the durability tier of the anchor that pins a mark to an element. Mirrors the
|
|
35
|
+
* browser's auto-anchor AnchorStrategy values (testid > component@source > role > position) so the
|
|
36
|
+
* agent draining a mark knows how trustworthy the element address is. Wire-owned here because the
|
|
37
|
+
* mark crosses browser → bridge → agent; the browser maps its synthesized anchor onto these.
|
|
38
|
+
*/
|
|
39
|
+
export const MarkAnchorStrategy = {
|
|
40
|
+
TESTID: 'testid',
|
|
41
|
+
COMPONENT: 'component',
|
|
42
|
+
ROLE: 'role',
|
|
43
|
+
POSITION: 'position',
|
|
44
|
+
};
|
|
45
|
+
/** Human review marks: lifecycle of a mark in the server-side review store. */
|
|
46
|
+
export const MarkStatus = {
|
|
47
|
+
/** Flagged by the human, not yet addressed by the agent. */
|
|
48
|
+
PENDING: 'pending',
|
|
49
|
+
/** The agent claimed the mark as fixed (reticle_review resolve). Terminal. */
|
|
50
|
+
RESOLVED: 'resolved',
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* SDK page-health heartbeat cadence (native timer) and the server's
|
|
54
|
+
* throttle threshold. Kept named so the server's staleness check can be reasoned about
|
|
55
|
+
* against the SDK's heartbeat (≈ 2 missed heartbeats ⇒ throttled).
|
|
56
|
+
*/
|
|
57
|
+
export const SESSION_HEALTH = {
|
|
58
|
+
HEARTBEAT_MS: 5_000,
|
|
59
|
+
/** lastSeenMs beyond this ⇒ throttled (≈ 2 missed heartbeats). */
|
|
60
|
+
STALE_THRESHOLD_MS: 12_000,
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Server-authoritative session liveness. The browser-side idle timer is throttled in a backgrounded
|
|
64
|
+
* tab and dies entirely if the agent (MCP client) kills the bridge — so the Node server (immune to
|
|
65
|
+
* throttling) owns the decision: a session whose AGENT has been idle past `IDLE_END_MS` is reaped and
|
|
66
|
+
* ended via a PRESENTER push (which a throttled tab still receives). `BRIDGE_LOST_MS` is the browser's
|
|
67
|
+
* own fallback: when it cannot reach the bridge for this long (server/agent process gone), it ends the
|
|
68
|
+
* session itself so the HUD never sits "running" forever.
|
|
69
|
+
*/
|
|
70
|
+
export const SESSION_LIFECYCLE = {
|
|
71
|
+
/**
|
|
72
|
+
* Default agent-idle window before the panel hands back to the human as WAITING. The agent signals
|
|
73
|
+
* this IMMEDIATELY via reticle_yield; this reaper is only the slow backstop for a forgotten yield, so
|
|
74
|
+
* it's deliberately long (a short window would auto-end a session mid slow-step). reticle_session-tunable.
|
|
75
|
+
*/
|
|
76
|
+
IDLE_END_MS: 300_000,
|
|
77
|
+
/** Floor for a tuned idle window (so an agent can't disable the safety net). */
|
|
78
|
+
IDLE_END_MIN_MS: 5_000,
|
|
79
|
+
/** How often the server reaper sweeps sessions for idle/disconnected ones. */
|
|
80
|
+
REAP_INTERVAL_MS: 5_000,
|
|
81
|
+
/** Browser fallback: continuous failure to reach the bridge for this long ⇒ self-end the session. */
|
|
82
|
+
BRIDGE_LOST_MS: 15_000,
|
|
83
|
+
/**
|
|
84
|
+
* Daemon self-shutdown: after this long with NO agent connected, NO browser session, and NO pool
|
|
85
|
+
* lease, the detached daemon tears itself down (closes Chromium + bridge, frees the port, removes its
|
|
86
|
+
* pidfile, exits) so Reticle never lingers eating resources after the editor closes. Long enough to
|
|
87
|
+
* survive brief agent reconnects between turns; overridable via RETICLE_IDLE_SHUTDOWN_MS (0 = never).
|
|
88
|
+
*/
|
|
89
|
+
DAEMON_IDLE_SHUTDOWN_MS: 300_000,
|
|
90
|
+
/** How often the daemon checks whether it has gone idle. Unref'd, so it never keeps the process up. */
|
|
91
|
+
DAEMON_IDLE_CHECK_MS: 30_000,
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Coding-agent session hygiene thresholds. Coding agents (Claude Code, Codex, Cursor) often
|
|
95
|
+
* complete their task and close their context without calling reticle_end_session. These constants
|
|
96
|
+
* drive two passive reminder layers: a one-time session_lease on first call, and recurring
|
|
97
|
+
* session_age_warning fields after WARN_AFTER_MS.
|
|
98
|
+
*/
|
|
99
|
+
export const SESSION_LEASE = {
|
|
100
|
+
/** ms after which age warnings appear on every session-bound tool result. */
|
|
101
|
+
WARN_AFTER_MS: 600_000, // 10 minutes
|
|
102
|
+
/** ms after which reticle_sessions marks a session as stale. */
|
|
103
|
+
STALE_AFTER_MS: 1_800_000, // 30 minutes
|
|
104
|
+
};
|
|
105
|
+
/** Why the SDK emitted a PAGE_HEALTH event. */
|
|
106
|
+
export const HealthReason = {
|
|
107
|
+
VISIBILITY: 'visibilitychange',
|
|
108
|
+
FOCUS: 'focus',
|
|
109
|
+
BLUR: 'blur',
|
|
110
|
+
HEARTBEAT: 'heartbeat',
|
|
111
|
+
INITIAL: 'initial',
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=session-constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-constants.js","sourceRoot":"","sources":["../src/session-constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;CACN,CAAC;AAGX,kGAAkG;AAClG,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,CACL,KAAK,KAAK,YAAY,CAAC,MAAM,IAAI,KAAK,KAAK,YAAY,CAAC,MAAM,IAAI,KAAK,KAAK,YAAY,CAAC,KAAK,CAC/F,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC;AAEnC,iGAAiG;AACjG,MAAM,CAAC,MAAM,gBAAgB,GAAG;IA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AS;CACV,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* reticle_state path selection + depth capping — pure, shared by the browser SDK (which applies them
|
|
3
|
+
* BEFORE the transport so a scoped read of a huge store isn't truncated) and the server (back-compat
|
|
4
|
+
* fallback when an older browser returns the whole store). `selectPath` walks a dot-path (with numeric
|
|
5
|
+
* array indices) and, on a miss, returns the keys that WERE available at the last good level so a wrong
|
|
6
|
+
* path is diagnosable rather than a bare null. `capDepth` prunes deeply-nested values to a budget.
|
|
7
|
+
*/
|
|
8
|
+
/** Result of walking a dot-path: the value, or a near-miss with the keys available where it stopped. */
|
|
9
|
+
export interface PathSelection {
|
|
10
|
+
found: boolean;
|
|
11
|
+
value: unknown;
|
|
12
|
+
/** On a miss: the keys present at the deepest level reached (so the agent can correct the path). */
|
|
13
|
+
availableKeys?: string[];
|
|
14
|
+
}
|
|
15
|
+
/** Walk `path` (e.g. "captionCache.v3.0.text") into `root`. Empty path returns root unchanged. */
|
|
16
|
+
export declare function selectPath(root: unknown, path: string): PathSelection;
|
|
17
|
+
/**
|
|
18
|
+
* Prune `value` to `maxDepth` levels: objects/arrays deeper than the budget collapse to a compact
|
|
19
|
+
* placeholder string recording their size, so a huge store can be skimmed shape-first. A negative
|
|
20
|
+
* budget means "no cap".
|
|
21
|
+
*/
|
|
22
|
+
export declare function capDepth(value: unknown, maxDepth: number): unknown;
|
|
23
|
+
//# sourceMappingURL=state-select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-select.d.ts","sourceRoot":"","sources":["../src/state-select.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,wGAAwG;AACxG,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,oGAAoG;IACpG,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAQD,kGAAkG;AAClG,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,CAmBrE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAelE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* reticle_state path selection + depth capping — pure, shared by the browser SDK (which applies them
|
|
3
|
+
* BEFORE the transport so a scoped read of a huge store isn't truncated) and the server (back-compat
|
|
4
|
+
* fallback when an older browser returns the whole store). `selectPath` walks a dot-path (with numeric
|
|
5
|
+
* array indices) and, on a miss, returns the keys that WERE available at the last good level so a wrong
|
|
6
|
+
* path is diagnosable rather than a bare null. `capDepth` prunes deeply-nested values to a budget.
|
|
7
|
+
*/
|
|
8
|
+
function keysOf(value) {
|
|
9
|
+
if (Array.isArray(value))
|
|
10
|
+
return value.map((_, i) => String(i));
|
|
11
|
+
if (typeof value === 'object' && value !== null)
|
|
12
|
+
return Object.keys(value);
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
/** Walk `path` (e.g. "captionCache.v3.0.text") into `root`. Empty path returns root unchanged. */
|
|
16
|
+
export function selectPath(root, path) {
|
|
17
|
+
const segments = path.split('.').filter((s) => s.length > 0);
|
|
18
|
+
let current = root;
|
|
19
|
+
for (const segment of segments) {
|
|
20
|
+
if (Array.isArray(current)) {
|
|
21
|
+
const index = Number(segment);
|
|
22
|
+
if (!Number.isInteger(index) || index < 0 || index >= current.length) {
|
|
23
|
+
return { found: false, value: null, availableKeys: keysOf(current) };
|
|
24
|
+
}
|
|
25
|
+
current = current[index];
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (typeof current === 'object' && current !== null && segment in current) {
|
|
29
|
+
current = current[segment];
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
return { found: false, value: null, availableKeys: keysOf(current) };
|
|
33
|
+
}
|
|
34
|
+
return { found: true, value: current };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Prune `value` to `maxDepth` levels: objects/arrays deeper than the budget collapse to a compact
|
|
38
|
+
* placeholder string recording their size, so a huge store can be skimmed shape-first. A negative
|
|
39
|
+
* budget means "no cap".
|
|
40
|
+
*/
|
|
41
|
+
export function capDepth(value, maxDepth) {
|
|
42
|
+
if (maxDepth < 0)
|
|
43
|
+
return value;
|
|
44
|
+
if (Array.isArray(value)) {
|
|
45
|
+
if (maxDepth === 0)
|
|
46
|
+
return `[Array(${String(value.length)})]`;
|
|
47
|
+
return value.map((v) => capDepth(v, maxDepth - 1));
|
|
48
|
+
}
|
|
49
|
+
if (typeof value === 'object' && value !== null) {
|
|
50
|
+
const keys = Object.keys(value);
|
|
51
|
+
if (maxDepth === 0)
|
|
52
|
+
return `{…${String(keys.length)} keys}`;
|
|
53
|
+
const out = {};
|
|
54
|
+
for (const key of keys)
|
|
55
|
+
out[key] = capDepth(value[key], maxDepth - 1);
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=state-select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-select.js","sourceRoot":"","sources":["../src/state-select.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3E,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,UAAU,CAAC,IAAa,EAAE,IAAY;IACpD,M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QACzB,IAAI,QAAQ,KAAK,CAAC;YAAE,OAAO,UAAU,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC;QAC9D,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChC,IAAI,QAAQ,KAAK,CAAC;YAAE,OAAO,KAAK,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC5D,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,GAAG,IAAI,IAAI;YACpB,GAAG,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAE,KAAiC,CAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC;QAC7E,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/toon.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOON — Token-Optimized Object Notation.
|
|
3
|
+
*
|
|
4
|
+
* A compact, deterministic, line-oriented text format for Reticle snapshots and query results.
|
|
5
|
+
* Losslessly round-trips to/from the internal JSON representation. Not a binary format — Claude
|
|
6
|
+
* must be able to generate and parse it reliably from its training data alone.
|
|
7
|
+
*
|
|
8
|
+
* Grammar (one element per line):
|
|
9
|
+
* type ref "name" [states] key=value ...
|
|
10
|
+
*
|
|
11
|
+
* Element types (abbreviated roles):
|
|
12
|
+
* btn button inp textbox/input sel combobox/listbox chk checkbox
|
|
13
|
+
* rad radio lnk link img img dlg dialog/alertdialog
|
|
14
|
+
* nav navigation lst list/listbox tab tab/tabpanel hdr heading
|
|
15
|
+
* frm form mn menu/menubar fld group/fieldset el (any other role)
|
|
16
|
+
*
|
|
17
|
+
* State flags (inside []):
|
|
18
|
+
* vis visible hid hidden en enabled dis disabled
|
|
19
|
+
* chk checked uch unchecked exp expanded col collapsed focus
|
|
20
|
+
*
|
|
21
|
+
* Attributes (key=value, space-separated):
|
|
22
|
+
* val="..." current value of the element
|
|
23
|
+
* count=N child count (for containers, replaces expanding children)
|
|
24
|
+
* ph="..." placeholder text
|
|
25
|
+
*/
|
|
26
|
+
/** Encode an ElementDescriptor to a TOON line. */
|
|
27
|
+
export interface ToonElement {
|
|
28
|
+
ref: string;
|
|
29
|
+
role: string;
|
|
30
|
+
name: string;
|
|
31
|
+
value?: string;
|
|
32
|
+
states?: string[];
|
|
33
|
+
visible?: boolean;
|
|
34
|
+
text?: string;
|
|
35
|
+
children?: ToonElement[];
|
|
36
|
+
childCount?: number;
|
|
37
|
+
}
|
|
38
|
+
/** Encode an array of ElementDescriptor-shaped objects to TOON text. */
|
|
39
|
+
export declare function toToon(elements: ToonElement[]): string;
|
|
40
|
+
/** Encode a single reticle_snapshot or reticle_query result object to TOON. */
|
|
41
|
+
export declare function resultToToon(result: Record<string, unknown>): string;
|
|
42
|
+
/** Whether a tool result object should be encoded as TOON (has an elements array). */
|
|
43
|
+
export declare function isToonable(result: unknown): boolean;
|
|
44
|
+
//# sourceMappingURL=toon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toon.d.ts","sourceRoot":"","sources":["../src/toon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,kDAAkD;AAClD,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAgHD,wEAAwE;AACxE,wBAAgB,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,CAGtD;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAIpE;AAED,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAOnD"}
|
package/dist/toon.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOON — Token-Optimized Object Notation.
|
|
3
|
+
*
|
|
4
|
+
* A compact, deterministic, line-oriented text format for Reticle snapshots and query results.
|
|
5
|
+
* Losslessly round-trips to/from the internal JSON representation. Not a binary format — Claude
|
|
6
|
+
* must be able to generate and parse it reliably from its training data alone.
|
|
7
|
+
*
|
|
8
|
+
* Grammar (one element per line):
|
|
9
|
+
* type ref "name" [states] key=value ...
|
|
10
|
+
*
|
|
11
|
+
* Element types (abbreviated roles):
|
|
12
|
+
* btn button inp textbox/input sel combobox/listbox chk checkbox
|
|
13
|
+
* rad radio lnk link img img dlg dialog/alertdialog
|
|
14
|
+
* nav navigation lst list/listbox tab tab/tabpanel hdr heading
|
|
15
|
+
* frm form mn menu/menubar fld group/fieldset el (any other role)
|
|
16
|
+
*
|
|
17
|
+
* State flags (inside []):
|
|
18
|
+
* vis visible hid hidden en enabled dis disabled
|
|
19
|
+
* chk checked uch unchecked exp expanded col collapsed focus
|
|
20
|
+
*
|
|
21
|
+
* Attributes (key=value, space-separated):
|
|
22
|
+
* val="..." current value of the element
|
|
23
|
+
* count=N child count (for containers, replaces expanding children)
|
|
24
|
+
* ph="..." placeholder text
|
|
25
|
+
*/
|
|
26
|
+
const ROLE_MAP = {
|
|
27
|
+
button: 'btn',
|
|
28
|
+
textbox: 'inp',
|
|
29
|
+
search: 'inp',
|
|
30
|
+
checkbox: 'chk',
|
|
31
|
+
radio: 'rad',
|
|
32
|
+
link: 'lnk',
|
|
33
|
+
img: 'img',
|
|
34
|
+
dialog: 'dlg',
|
|
35
|
+
alertdialog: 'dlg',
|
|
36
|
+
navigation: 'nav',
|
|
37
|
+
list: 'lst',
|
|
38
|
+
listbox: 'lst',
|
|
39
|
+
listitem: 'li',
|
|
40
|
+
combobox: 'sel',
|
|
41
|
+
option: 'opt',
|
|
42
|
+
tab: 'tab',
|
|
43
|
+
tabpanel: 'tab',
|
|
44
|
+
heading: 'hdr',
|
|
45
|
+
form: 'frm',
|
|
46
|
+
menu: 'mn',
|
|
47
|
+
menubar: 'mn',
|
|
48
|
+
menuitem: 'mi',
|
|
49
|
+
group: 'fld',
|
|
50
|
+
fieldset: 'fld',
|
|
51
|
+
table: 'tbl',
|
|
52
|
+
row: 'row',
|
|
53
|
+
cell: 'cel',
|
|
54
|
+
main: 'main',
|
|
55
|
+
banner: 'hdr',
|
|
56
|
+
grid: 'grd',
|
|
57
|
+
gridcell: 'cel',
|
|
58
|
+
tree: 'tree',
|
|
59
|
+
treeitem: 'titem',
|
|
60
|
+
switch: 'sw',
|
|
61
|
+
slider: 'sldr',
|
|
62
|
+
spinbutton: 'spin',
|
|
63
|
+
};
|
|
64
|
+
function abbreviateRole(role) {
|
|
65
|
+
return ROLE_MAP[role] ?? 'el';
|
|
66
|
+
}
|
|
67
|
+
function encodeStates(states, visible) {
|
|
68
|
+
const flags = [];
|
|
69
|
+
if (visible === true)
|
|
70
|
+
flags.push('vis');
|
|
71
|
+
else if (visible === false)
|
|
72
|
+
flags.push('hid');
|
|
73
|
+
for (const s of states) {
|
|
74
|
+
switch (s) {
|
|
75
|
+
case 'visible':
|
|
76
|
+
break; // handled above
|
|
77
|
+
case 'hidden':
|
|
78
|
+
break; // handled above
|
|
79
|
+
case 'enabled':
|
|
80
|
+
flags.push('en');
|
|
81
|
+
break;
|
|
82
|
+
case 'disabled':
|
|
83
|
+
flags.push('dis');
|
|
84
|
+
break;
|
|
85
|
+
case 'checked':
|
|
86
|
+
flags.push('chk');
|
|
87
|
+
break;
|
|
88
|
+
case 'unchecked':
|
|
89
|
+
flags.push('uch');
|
|
90
|
+
break;
|
|
91
|
+
case 'expanded':
|
|
92
|
+
flags.push('exp');
|
|
93
|
+
break;
|
|
94
|
+
case 'collapsed':
|
|
95
|
+
flags.push('col');
|
|
96
|
+
break;
|
|
97
|
+
case 'focused':
|
|
98
|
+
flags.push('focus');
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
flags.push(s);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return flags.length > 0 ? `[${flags.join(',')}]` : '';
|
|
105
|
+
}
|
|
106
|
+
function encodeName(name) {
|
|
107
|
+
return `"${name.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
108
|
+
}
|
|
109
|
+
function encodeValue(val) {
|
|
110
|
+
return `"${val.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
111
|
+
}
|
|
112
|
+
function encodeLine(el, depth) {
|
|
113
|
+
const indent = ' '.repeat(depth);
|
|
114
|
+
const type = abbreviateRole(el.role);
|
|
115
|
+
const states = encodeStates(el.states ?? [], el.visible);
|
|
116
|
+
const parts = [indent + type, el.ref, encodeName(el.name), ...(states ? [states] : [])];
|
|
117
|
+
if (el.value !== undefined && el.value.length > 0)
|
|
118
|
+
parts.push(`val=${encodeValue(el.value)}`);
|
|
119
|
+
if (el.childCount !== undefined)
|
|
120
|
+
parts.push(`count=${String(el.childCount)}`);
|
|
121
|
+
return parts.join(' ');
|
|
122
|
+
}
|
|
123
|
+
function encodeTree(elements, depth = 0) {
|
|
124
|
+
const lines = [];
|
|
125
|
+
for (const el of elements) {
|
|
126
|
+
lines.push(encodeLine(el, depth));
|
|
127
|
+
if (el.children && el.children.length > 0) {
|
|
128
|
+
lines.push(encodeTree(el.children, depth + 1));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return lines.join('\n');
|
|
132
|
+
}
|
|
133
|
+
/** Encode an array of ElementDescriptor-shaped objects to TOON text. */
|
|
134
|
+
export function toToon(elements) {
|
|
135
|
+
if (elements.length === 0)
|
|
136
|
+
return '# TOON v1 — empty';
|
|
137
|
+
return `# TOON v1\n${encodeTree(elements)}`;
|
|
138
|
+
}
|
|
139
|
+
/** Encode a single reticle_snapshot or reticle_query result object to TOON. */
|
|
140
|
+
export function resultToToon(result) {
|
|
141
|
+
const elements = result['elements'];
|
|
142
|
+
if (!Array.isArray(elements))
|
|
143
|
+
return JSON.stringify(result);
|
|
144
|
+
return toToon(elements);
|
|
145
|
+
}
|
|
146
|
+
/** Whether a tool result object should be encoded as TOON (has an elements array). */
|
|
147
|
+
export function isToonable(result) {
|
|
148
|
+
return (typeof result === 'object' &&
|
|
149
|
+
result !== null &&
|
|
150
|
+
!Array.isArray(result) &&
|
|
151
|
+
Array.isArray(result['elements']));
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=toon.js.map
|
package/dist/toon.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toon.js","sourceRoot":"","sources":["../src/toon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAeH,MAAM,QAAQ,GAA2B;IACvC,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,KAAK;IACb,QAAQ,EAAE,KAAK;IACf,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,KAAK;IACX,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,KAAK;IACb,WAAW,EAAE,KAAK;IAClB,UAAU,EAAE,KAAK;IACjB,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,IAAI;IACd,QAAQ,EAAE,KAAK;IACf,M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