@ancientpantheon/khronoton-core 0.4.1 → 0.5.0

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/CHANGELOG.md CHANGED
@@ -4,6 +4,51 @@ All notable changes to `@ancientpantheon/khronoton-core`.
4
4
 
5
5
  The engine's pre-extraction history lives in the AncientHoldings hub, whose inline scheduler ("Cronoton") this package extracts and generalises.
6
6
 
7
+ ## 0.5.0 — 2026-08-02
8
+
9
+ **MINOR — Builder screen: syntax-highlighted Pact editor, top/bottom layout, live tx-size/gas meter.**
10
+
11
+ - **Syntax highlighting on the Pact-code editor.** Keywords, definitions (`defun`/`defcap`/`defschema`/…),
12
+ types, strings, numbers, booleans, `;;` comments, `@doc`/`@model` annotations, symbols, and
13
+ parens/brackets/braces are now colored distinctly instead of one flat color. Colors are driven entirely
14
+ by the package's existing `--khr-*` theme-token convention (extended with five new tokens, below), so a
15
+ consumer's existing `body .khronoton-ui { --khr-*: ... }` override pattern applies unchanged.
16
+ - **New `--khr-*` tokens:** `--khr-syntax-keyword`, `--khr-syntax-type`, `--khr-syntax-string`,
17
+ `--khr-syntax-number`, `--khr-syntax-atom` (Pact-code syntax coloring — see `THEMING.md`), and
18
+ `--khr-selection` (the Pact editor's text-selection background — previously reused `--khr-accent-tint`,
19
+ which read as nearly invisible against the editor's own background; now its own token, defaulting to a
20
+ visible `#1e3a5f`).
21
+ - **Builder layout: top/bottom, not left/right.** The Pact-code editor now renders full-width at the top of
22
+ the Builder screen, clamped to ~7 visible lines with internal scroll, with the header/tab bar/tab content
23
+ full-width below it — the one standard layout for every cronoton, not a per-consumer option.
24
+ - **Live Tx Size + Gas metering strip**, between the editor's header and its code body: a byte-size bar
25
+ against StoaChain's fixed 2 MB Chainweb ceiling (live, recomputed as you type/configure — a local
26
+ estimate only, never signed or submitted), and a gas-used-vs-gas-limit bar once a Simulate result exists.
27
+ - **Dependency fix:** `@uiw/react-codemirror`, `@codemirror/state`, `@codemirror/view`,
28
+ `@codemirror/language`, `@lezer/highlight` are now real (optional) `peerDependencies` instead of
29
+ `devDependencies` silently relied on via hoisting from an unrelated dependency — a consumer without them
30
+ now sees an honest unmet-peer warning instead of a silent fallback to the plain-textarea editor.
31
+ - **Build fix (pre-existing, found in the same pass):** `tsup.config.ts`'s `external` list was missing
32
+ `@ouronet/ouronet-core` — `/blockchain/stoachain`'s lazy `@ouronet/ouronet-core/constants` import was
33
+ being bundled into `dist/blockchain/stoachain.js` instead of resolving from the consumer's own install,
34
+ reintroducing the version-pinning conflict 0.4.1 existed to fix. No behavior change for anyone not using
35
+ `/blockchain/stoachain`.
36
+
37
+ **832 specs pass.**
38
+
39
+ ## 0.4.2 — 2026-07-22
40
+
41
+ **PATCH — fix a dangling peerDependenciesMeta key.**
42
+
43
+ 0.4.1 renamed the Ouronet peer dependency to `@ouronet/ouronet-core` in
44
+ `peerDependencies` but left the matching `peerDependenciesMeta` entry under the
45
+ old `@stoachain/ouronet-core` name. The result was a meta entry marking a peer
46
+ that no longer exists as optional, while the real `@ouronet/ouronet-core` peer
47
+ carried no `optional: true` flag — so a consumer without it installed would see
48
+ a spurious unmet-peer warning. This aligns the meta key with the peer.
49
+
50
+ No code change; **799 specs pass**.
51
+
7
52
  ## 0.4.1 — 2026-07-22
8
53
 
9
54
  **PATCH — dependency rename, no code change.**
package/README.md CHANGED
@@ -6,13 +6,17 @@ Khronoton is the "When do I act?" Constructor of the Pantheon architecture — t
6
6
 
7
7
  ## Status
8
8
 
9
+ **`0.5.0` on public npmjs** — **MINOR.** Released 2026-08-02. The Builder screen's Pact-code editor is now syntax-highlighted (via the package's `--khr-*` theme tokens, five new ones added), moved to a full-width top strip (~7 lines, internal scroll) with the header/tabs/tab content full-width below it, and gained a live tx-size/gas metering strip. `@uiw/react-codemirror` + the CodeMirror/Lezer packages it now depends on for highlighting are real optional `peerDependencies`. **832 specs pass.**
10
+
11
+ **`0.4.2` on public npmjs** — **PATCH.** Released 2026-07-22. Aligns the `peerDependenciesMeta` key with the `@ouronet/ouronet-core` peer renamed in 0.4.1 (the meta entry still named the old `@stoachain` peer). No code change. **799 specs pass.**
12
+
9
13
  **`0.4.1` on public npmjs** — **PATCH (dependency rename, no code change).** Released 2026-07-22. `@stoachain/ouronet-core` → `@ouronet/ouronet-core` — same code, new scope, following the Phase-4 split into OuroborosNetwork/ouronet-libs. **799 specs pass.**
10
14
 
11
15
  **`0.4.0` on public npmjs** — the complete drop-in codex-cronoton experience, matching the AncientHoldings Hub, now **chain-polyglot**. On top of the byte-unchanged root `.` schedule engine and `/server` automaton engine (both from 0.2.0), the package ships the whole experience layer as subpaths so a consumer wires the Hub's cronoton UX end to end without re-implementing it:
12
16
 
13
17
  - **`/handlers`** — framework-agnostic HTTP route handlers over the `/server` store + executor (list/get/fires/signers/commit/edit/pause/resume/delete/simulate/execute-now/trigger/batch/recover), driven by a tiny `HandlerRequest`/`HandlerResponse` seam so any router (Next.js, Express, …) can mount them.
14
18
  - **`/provider` + `/hooks`** — the React data layer: `<KhronotonProvider adapter={…}>`, the 16-method `KhronotonAdapter` seam with two reference adapters (`createFetchAdapter` over HTTP, `createMemoryAdapter` over in-process handlers), the shared `runGated` confirm-retry, and the data + action hooks (`useCronotons`/`useCronoton`/`useCronotonFires`/`useManualBatch` + the lifecycle/execute action hooks).
15
- - **`/ui` + `/ui.css`** — the React UI at full Hub parity: the four screens **List**, **Detail/Observe** (fire history with 50/page pager, definition-drift flag, result tooltip, pluggable multi-tx renderer, wired recover), **Builder** (two-pane create + edit, Config/Payload/Gas Payer/Signatures/Execute tabs, Simulate→AUTO-gas calibrate), and a **Public** read-only transparency view — themed entirely through `--khr-*` CSS variables inside `<KhronotonUiRoot>`.
19
+ - **`/ui` + `/ui.css`** — the React UI at full Hub parity: the four screens **List**, **Detail/Observe** (fire history with 50/page pager, definition-drift flag, result tooltip, pluggable multi-tx renderer, wired recover), **Builder** (syntax-highlighted Pact-code editor full-width on top, Config/Payload/Gas Payer/Signatures/Execute tabs full-width below, Simulate→AUTO-gas calibrate, a live tx-size/gas metering strip), and a **Public** read-only transparency view — themed entirely through `--khr-*` CSS variables inside `<KhronotonUiRoot>`.
16
20
 
17
21
  Khronoton isn't chain-*agnostic* — it's chain-*polyglot*: the root schedule/tick engine orchestrates, and the **`/blockchain/<chain>`** subpath family teaches it to speak each supported chain's language natively (0.4.0):
18
22
 
@@ -230,6 +234,10 @@ npm install @ancientpantheon/khronoton-core
230
234
 
231
235
  ## Version history
232
236
 
237
+ **v0.5.0** — Builder screen upgrade: the Pact-code editor is syntax-highlighted (keywords, definitions, types, strings, numbers, booleans, comments, `@doc`/`@model` annotations, parens/atoms — colored via new `--khr-syntax-*`/`--khr-selection` tokens, not hardcoded), moved to a full-width top strip (~7 lines, internal scroll) with the header/tab bar/tab content full-width below it as the one standard layout, and gained a live tx-size/gas metering strip (local byte estimate against StoaChain's 2 MB ceiling; gas-used-vs-limit once Simulate runs). `@uiw/react-codemirror`, `@codemirror/state`, `@codemirror/view`, `@codemirror/language`, `@lezer/highlight` are now real optional `peerDependencies` instead of silently relied upon via hoisting. Released 2026-08-02. **832 specs pass.**
238
+
239
+ **v0.4.2** — fix dangling `peerDependenciesMeta` key (was still `@stoachain/ouronet-core`). Released 2026-07-22. **799 specs pass.**
240
+
233
241
  **v0.4.1** — dependency rename, no code change. Released 2026-07-22. `@stoachain/ouronet-core` → `@ouronet/ouronet-core`. **799 specs pass.**
234
242
 
235
243
  **v0.4.0** — Made khronoton **chain-polyglot**: added the `/blockchain/<chain>` subpath family, starting with `/blockchain/stoachain` (`createStoachainRuntime(config?)` → the core `ChainRuntime` seam, wrapping `@stoachain/*`). Each chain's SDK is an **optional peer dependency** imported lazily, so the package stays zero-SDK on install and a consumer carries only the chains it imports — one package, one drop-in for every automaton, rather than a separate npm package per chain. (This folds in the previously-separate `@ancientpantheon/khronoton-stoachain`, which is removed and was never published.) Root `.`/`/server`/`/handlers` outputs unchanged. React and `@stoachain/*` are optional peers for their respective subpaths only.
@@ -0,0 +1,226 @@
1
+ import CodeMirror from '@uiw/react-codemirror';
2
+ import { EditorView } from '@codemirror/view';
3
+ import { syntaxHighlighting, HighlightStyle, StreamLanguage } from '@codemirror/language';
4
+ import { tags } from '@lezer/highlight';
5
+ import { jsx } from 'react/jsx-runtime';
6
+
7
+ // src/ui/PactCodeMirror.tsx
8
+ var DEFINITION_KEYWORDS = /* @__PURE__ */ new Set([
9
+ "defun",
10
+ "defcap",
11
+ "defconst",
12
+ "defpact",
13
+ "defschema",
14
+ "deftable",
15
+ "module",
16
+ "interface",
17
+ "defproperty"
18
+ ]);
19
+ var KEYWORDS = /* @__PURE__ */ new Set([
20
+ "if",
21
+ "let",
22
+ "let*",
23
+ "lambda",
24
+ "cond",
25
+ "use",
26
+ "namespace",
27
+ "implements",
28
+ "bless",
29
+ "with-read",
30
+ "with-default-read",
31
+ "with-capability",
32
+ "bind",
33
+ "step",
34
+ "step-with-rollback",
35
+ "resume",
36
+ "yield",
37
+ "enforce",
38
+ "enforce-one",
39
+ "enforce-keyset",
40
+ "enforce-guard",
41
+ "require-capability",
42
+ "compose-capability",
43
+ "read",
44
+ "write",
45
+ "update",
46
+ "select",
47
+ "where",
48
+ "and",
49
+ "or",
50
+ "not",
51
+ "try",
52
+ "format",
53
+ "map",
54
+ "fold",
55
+ "filter",
56
+ "define-keyset",
57
+ "define-namespace"
58
+ ]);
59
+ var TYPE_NAMES = /* @__PURE__ */ new Set([
60
+ "integer",
61
+ "decimal",
62
+ "time",
63
+ "bool",
64
+ "string",
65
+ "list",
66
+ "value",
67
+ "keyset",
68
+ "guard",
69
+ "object",
70
+ "table"
71
+ ]);
72
+ function token(stream) {
73
+ if (stream.eatSpace()) return null;
74
+ if (stream.match(";;")) {
75
+ stream.skipToEnd();
76
+ return "lineComment";
77
+ }
78
+ if (stream.match(/^"(?:[^"\\]|\\.)*"?/)) return "string";
79
+ if (stream.match(/^\d+(\.\d+)?/)) return "number";
80
+ if (stream.match(/^'[a-zA-Z_-][a-zA-Z0-9_-]*/)) return "atom";
81
+ if (stream.match(/^@[a-zA-Z_][a-zA-Z0-9_-]*/)) return "meta";
82
+ if (stream.match(/^(:=|::)/)) return "operator";
83
+ if (stream.match(/^[+\-*/=<>!]=?/)) return "operator";
84
+ if (stream.match(/^[()]/)) return "paren";
85
+ if (stream.match(/^[[\]]/)) return "squareBracket";
86
+ if (stream.match(/^[{}]/)) return "brace";
87
+ const identifierMatch = stream.match(
88
+ /^[a-zA-Z_][a-zA-Z0-9_\-.%#+&$@<>=?*!|/]*/
89
+ );
90
+ if (identifierMatch) {
91
+ const word = identifierMatch[0];
92
+ if (DEFINITION_KEYWORDS.has(word)) return "definitionKeyword";
93
+ if (KEYWORDS.has(word)) return "keyword";
94
+ if (TYPE_NAMES.has(word)) return "typeName";
95
+ if (word === "true" || word === "false") return "bool";
96
+ return "variableName";
97
+ }
98
+ stream.next();
99
+ return null;
100
+ }
101
+ var PACT_TOKEN_TABLE = {
102
+ definitionKeyword: tags.definitionKeyword,
103
+ keyword: tags.keyword,
104
+ typeName: tags.typeName,
105
+ bool: tags.bool,
106
+ string: tags.string,
107
+ number: tags.number,
108
+ lineComment: tags.lineComment,
109
+ variableName: tags.variableName,
110
+ atom: tags.atom,
111
+ operator: tags.operator,
112
+ meta: tags.meta,
113
+ paren: tags.paren,
114
+ squareBracket: tags.squareBracket,
115
+ brace: tags.brace
116
+ };
117
+ function pactLanguageSupport() {
118
+ return StreamLanguage.define({
119
+ token,
120
+ languageData: {
121
+ commentTokens: { line: ";;" },
122
+ closeBrackets: { brackets: ["(", "[", "{", '"'] }
123
+ },
124
+ tokenTable: PACT_TOKEN_TABLE
125
+ });
126
+ }
127
+ var PACT_HIGHLIGHT_SPECS = [
128
+ { tag: tags.keyword, color: "var(--khr-syntax-keyword, #c586c0)" },
129
+ {
130
+ tag: tags.definitionKeyword,
131
+ color: "var(--khr-accent, #f0a500)",
132
+ fontWeight: "bold"
133
+ },
134
+ { tag: tags.typeName, color: "var(--khr-syntax-type, #4ec9b0)" },
135
+ { tag: tags.bool, color: "var(--khr-blue, #60a5fa)" },
136
+ { tag: tags.string, color: "var(--khr-syntax-string, #ce9178)" },
137
+ { tag: tags.number, color: "var(--khr-syntax-number, #b5cea8)" },
138
+ {
139
+ tag: tags.lineComment,
140
+ color: "var(--khr-text-dim2, #6b7280)",
141
+ fontStyle: "italic"
142
+ },
143
+ { tag: tags.variableName, color: "var(--khr-mono, #d2d3d4)" },
144
+ { tag: tags.atom, color: "var(--khr-syntax-atom, #d7ba7d)" },
145
+ // Reuses --khr-blue (also used for `bool`) — `@doc`/`@model` meta tags
146
+ // and `true`/`false` literals never appear adjacent in real Pact
147
+ // source, so sharing the color carries no real ambiguity risk, and it
148
+ // avoids a brand-new token for a single rare-elsewhere role.
149
+ { tag: tags.meta, color: "var(--khr-blue, #60a5fa)" },
150
+ { tag: tags.operator, color: "var(--khr-text-dim, #8a8f98)" },
151
+ { tag: tags.paren, color: "var(--khr-text-dim, #8a8f98)" },
152
+ { tag: tags.squareBracket, color: "var(--khr-text-dim, #8a8f98)" },
153
+ { tag: tags.brace, color: "var(--khr-text-dim, #8a8f98)" }
154
+ ];
155
+ var pactHighlightExtension = syntaxHighlighting(
156
+ HighlightStyle.define(PACT_HIGHLIGHT_SPECS)
157
+ );
158
+ var GUTTER_BG = "#0d1117";
159
+ var ACTIVE_LINE_BG = "#161616";
160
+ var KHRONOTON_EDITOR_THEME_SPEC = {
161
+ "&": {
162
+ backgroundColor: "var(--khr-panel, #0a0a0a)",
163
+ color: "var(--khr-mono, #d2d3d4)",
164
+ fontSize: "12px"
165
+ },
166
+ ".cm-content": {
167
+ fontFamily: "var(--khr-mono-font, ui-monospace, monospace)",
168
+ caretColor: "var(--khr-accent, #f0a500)",
169
+ lineHeight: "1.4"
170
+ },
171
+ ".cm-cursor, .cm-dropCursor": {
172
+ borderLeftColor: "var(--khr-accent, #f0a500)"
173
+ },
174
+ "&.cm-focused": {
175
+ outline: "none"
176
+ },
177
+ "&.cm-editor.cm-focused": {
178
+ outline: "1px solid var(--khr-accent, #f0a500)"
179
+ },
180
+ "&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
181
+ backgroundColor: "var(--khr-selection, #1e3a5f)"
182
+ },
183
+ ".cm-gutters": {
184
+ backgroundColor: GUTTER_BG,
185
+ color: "var(--khr-text-dim, #8a8f98)",
186
+ border: "none"
187
+ },
188
+ ".cm-activeLine": { backgroundColor: ACTIVE_LINE_BG },
189
+ ".cm-activeLineGutter": { backgroundColor: ACTIVE_LINE_BG }
190
+ };
191
+ var khronotonEditorTheme = EditorView.theme(KHRONOTON_EDITOR_THEME_SPEC, {
192
+ dark: true
193
+ });
194
+ var PACT_EDITOR_EXTENSIONS = [
195
+ pactLanguageSupport(),
196
+ pactHighlightExtension
197
+ ];
198
+ function buildPactEditorExtensions() {
199
+ return PACT_EDITOR_EXTENSIONS;
200
+ }
201
+ var BASIC_SETUP = {
202
+ lineNumbers: true,
203
+ foldGutter: false,
204
+ closeBrackets: false,
205
+ autocompletion: false,
206
+ highlightActiveLine: true
207
+ };
208
+ function PactCodeMirror({
209
+ value,
210
+ onChange,
211
+ height
212
+ }) {
213
+ return /* @__PURE__ */ jsx(
214
+ CodeMirror,
215
+ {
216
+ value,
217
+ height: `${height}px`,
218
+ theme: khronotonEditorTheme,
219
+ extensions: buildPactEditorExtensions(),
220
+ basicSetup: BASIC_SETUP,
221
+ onChange
222
+ }
223
+ );
224
+ }
225
+
226
+ export { KHRONOTON_EDITOR_THEME_SPEC, buildPactEditorExtensions, PactCodeMirror as default };
@@ -125,7 +125,9 @@ interface DetailProps {
125
125
  declare function Detail({ id, access, onBack, onEdit, onNavigateToList, robots, }: DetailProps): ReactNode;
126
126
 
127
127
  /**
128
- * Builder assembly — the two-pane create/edit form (REQ-B01/B02/B11).
128
+ * Builder assembly — the top/bottom create/edit form (REQ-B01/B02/B11): the
129
+ * Pact-code editor renders full-width at the top (with the shared tx-size/gas
130
+ * meter strip), and the header + five-tab bar render full-width below it.
129
131
  *
130
132
  * This is the single owner of the shared {@link BuilderState}: it hosts the
131
133
  * already-built controlled tabs (Config, Payload, Gas Payer, Signatures, Execute)
@@ -159,9 +161,10 @@ interface BuilderProps {
159
161
  readonly robots?: string;
160
162
  }
161
163
  /**
162
- * The two-pane codex-cronoton builder. Owns `BuilderState`; renders the Pact editor
163
- * on the left and the header + five-tab bar on the right, feeding every tab the
164
- * shared state and folding its `onChange` back in.
164
+ * The top/bottom codex-cronoton builder. Owns `BuilderState`; renders the Pact
165
+ * editor full-width at the top (with the shared tx-size/gas meter strip) and the
166
+ * header + five-tab bar full-width below it, feeding every tab the shared state
167
+ * and folding its `onChange` back in.
165
168
  */
166
169
  declare function Builder({ editId, access: _access, onDone, robots, }: BuilderProps): ReactNode;
167
170
 
package/dist/ui/index.js CHANGED
@@ -1619,7 +1619,7 @@ function detailToBuilderState(row) {
1619
1619
  runtimeArgKeysText: ""
1620
1620
  };
1621
1621
  }
1622
- var LazyPactCodeMirror = lazy(() => import('../PactCodeMirror-HQTGE2K3.js'));
1622
+ var LazyPactCodeMirror = lazy(() => import('../PactCodeMirror-4MRUD325.js'));
1623
1623
  var panelStyle = {
1624
1624
  display: "flex",
1625
1625
  flexDirection: "column",
@@ -1651,12 +1651,17 @@ var clearButtonStyle = {
1651
1651
  padding: "3px 10px",
1652
1652
  cursor: "pointer"
1653
1653
  };
1654
+ var subBarWrapStyle = {
1655
+ padding: "0 12px 10px",
1656
+ borderBottom: "1px solid var(--khr-border)"
1657
+ };
1654
1658
  function PactCodeEditor({
1655
1659
  value,
1656
1660
  onChange,
1657
1661
  onClear,
1658
1662
  height = 460,
1659
- forceFallback = false
1663
+ forceFallback = false,
1664
+ subBar
1660
1665
  }) {
1661
1666
  const [mounted, setMounted] = useState(false);
1662
1667
  useEffect(() => {
@@ -1691,6 +1696,7 @@ function PactCodeEditor({
1691
1696
  /* @__PURE__ */ jsx("span", { style: eyebrowStyle, children: "PACT Code Editor" }),
1692
1697
  onClear ? /* @__PURE__ */ jsx("button", { type: "button", onClick: onClear, style: clearButtonStyle, children: "Clear" }) : null
1693
1698
  ] }),
1699
+ subBar ? /* @__PURE__ */ jsx("div", { "data-testid": "pact-editor-subbar", style: subBarWrapStyle, children: subBar }) : null,
1694
1700
  /* @__PURE__ */ jsx("div", { style: { height }, children: useCodeMirror ? /* @__PURE__ */ jsx(Suspense, { fallback, children: /* @__PURE__ */ jsx(LazyPactCodeMirror, { value, onChange, height }) }) : fallback })
1695
1701
  ] });
1696
1702
  }
@@ -1805,6 +1811,11 @@ function BuilderHeader({
1805
1811
  ] })
1806
1812
  ] });
1807
1813
  }
1814
+
1815
+ // src/ui/builder/format.ts
1816
+ function formatThousands(n) {
1817
+ return n.toLocaleString("en-US");
1818
+ }
1808
1819
  var INPUT_STYLE4 = {
1809
1820
  display: "block",
1810
1821
  width: "100%",
@@ -1875,9 +1886,6 @@ var GAS_LABEL_STYLE = {
1875
1886
  function Hint({ children }) {
1876
1887
  return /* @__PURE__ */ jsx("p", { style: HINT_STYLE, children });
1877
1888
  }
1878
- function formatThousands(n) {
1879
- return n.toLocaleString("en-US");
1880
- }
1881
1889
  function ConfigTab({ state, onChange, calibratedGasLimit }) {
1882
1890
  const config = state.config;
1883
1891
  const patch = (next) => {
@@ -3308,13 +3316,10 @@ var REASONS_STYLE = {
3308
3316
  lineHeight: 1.6
3309
3317
  };
3310
3318
  var TRIGGER_ONLY_SCHEDULE = "Trigger-only (external / manual)";
3311
- function formatThousands2(n) {
3312
- return n.toLocaleString("en-US");
3313
- }
3314
3319
  function gasLine(state) {
3315
3320
  const c = state.config;
3316
3321
  const suffix = c.autoGasLimit ? " (AUTO)" : "";
3317
- return `${formatThousands2(c.gasLimit)} @ ${c.gasPriceAnu} ANU${suffix}`;
3322
+ return `${formatThousands(c.gasLimit)} @ ${c.gasPriceAnu} ANU${suffix}`;
3318
3323
  }
3319
3324
  function gasPayerLabel(gasPayer) {
3320
3325
  if (gasPayer.type === "gas-station") return "Gas Station";
@@ -3342,8 +3347,13 @@ function SummaryRow({
3342
3347
  /* @__PURE__ */ jsx("span", { style: ROW_VALUE_STYLE, children: value })
3343
3348
  ] });
3344
3349
  }
3345
- function ExecuteTab({ state, onChange, onCommit, committing }) {
3346
- const sim = useSimulate();
3350
+ function ExecuteTab({
3351
+ state,
3352
+ onChange,
3353
+ onCommit,
3354
+ committing,
3355
+ sim
3356
+ }) {
3347
3357
  const [banner, setBanner] = useState(null);
3348
3358
  const commit = builderToCommit(state);
3349
3359
  const payloadKeyCount = Object.keys(commit.envelope.payload ?? {}).length;
@@ -3372,7 +3382,7 @@ function ExecuteTab({ state, onChange, onCommit, committing }) {
3372
3382
  setBanner(
3373
3383
  renderBanner(
3374
3384
  "var(--khr-success)",
3375
- `Simulation succeeded \u2014 calibrated ${formatThousands2(view.calibratedGasLimit)} gas.`
3385
+ `Simulation succeeded \u2014 calibrated ${formatThousands(view.calibratedGasLimit)} gas.`
3376
3386
  )
3377
3387
  );
3378
3388
  return;
@@ -3439,6 +3449,146 @@ function renderBanner(color, message) {
3439
3449
  }
3440
3450
  );
3441
3451
  }
3452
+
3453
+ // src/ui/tx-size.ts
3454
+ var STOA_TX_BYTE_CEILING = 2 * 1024 * 1024;
3455
+ var PROXY_SOFT_LIMIT = 1 * 1024 * 1024;
3456
+ var BYTES_PER_SIGNATURE = 140;
3457
+ function estimateFallbackBytes(pactCode, payload) {
3458
+ return new TextEncoder().encode(pactCode + JSON.stringify(payload)).length;
3459
+ }
3460
+ async function estimateTxSize(state) {
3461
+ const commit = builderToCommit(state);
3462
+ const { pactCode, config, payload, signers } = commit.envelope;
3463
+ let bytes;
3464
+ try {
3465
+ const { Pact } = await import('@stoachain/kadena-stoic-legacy/client');
3466
+ const { anuToStoa } = await import('@stoachain/stoa-core/gas');
3467
+ const { KADENA_NETWORK } = await import('@stoachain/stoa-core/constants');
3468
+ const builder = Pact.builder.execution(pactCode || "").setMeta({
3469
+ senderAccount: state.gasPayer.type === "codex" ? state.gasPayer.address ?? "" : "c:gas-station",
3470
+ chainId: config.chainId,
3471
+ gasLimit: config.gasLimit,
3472
+ gasPrice: anuToStoa(config.gasPrice),
3473
+ ttl: config.ttl
3474
+ }).setNetworkId(KADENA_NETWORK);
3475
+ for (const [k, v] of Object.entries(payload ?? {})) {
3476
+ builder.addData(k, v);
3477
+ }
3478
+ const tx = builder.createTransaction();
3479
+ const body = JSON.stringify({ cmds: [tx] });
3480
+ bytes = new TextEncoder().encode(body).length + signers.length * BYTES_PER_SIGNATURE;
3481
+ } catch {
3482
+ bytes = estimateFallbackBytes(pactCode, payload);
3483
+ }
3484
+ return {
3485
+ bytes,
3486
+ ceiling: STOA_TX_BYTE_CEILING,
3487
+ fraction: bytes / STOA_TX_BYTE_CEILING,
3488
+ permille: bytes / STOA_TX_BYTE_CEILING * 1e3,
3489
+ over: bytes > STOA_TX_BYTE_CEILING
3490
+ };
3491
+ }
3492
+ var WRAP_STYLE = {
3493
+ display: "flex",
3494
+ flexDirection: "column",
3495
+ gap: "4px"
3496
+ };
3497
+ var ROW_STYLE5 = {
3498
+ display: "flex",
3499
+ alignItems: "center",
3500
+ gap: "8px",
3501
+ fontSize: "11px"
3502
+ };
3503
+ var LABEL_STYLE2 = {
3504
+ color: "var(--khr-text-dim)",
3505
+ textTransform: "uppercase",
3506
+ letterSpacing: "0.06em",
3507
+ minWidth: "46px"
3508
+ };
3509
+ var TRACK_STYLE = {
3510
+ flex: 1,
3511
+ height: "6px",
3512
+ borderRadius: "999px",
3513
+ backgroundColor: "var(--khr-inset)",
3514
+ overflow: "hidden",
3515
+ display: "flex"
3516
+ };
3517
+ var VALUE_STYLE = {
3518
+ fontFamily: "var(--khr-mono-font)",
3519
+ minWidth: "120px",
3520
+ textAlign: "right"
3521
+ };
3522
+ function formatBytes(n) {
3523
+ if (n < 1024) return `${n} B`;
3524
+ if (n < 1024 * 1024) return `${(n / 1024).toFixed(2)} KB`;
3525
+ return `${(n / 1024 / 1024).toFixed(3)} MB`;
3526
+ }
3527
+ function TxMeters({ state, sim }) {
3528
+ const [estimate, setEstimate] = useState(null);
3529
+ useEffect(() => {
3530
+ let active = true;
3531
+ void (async () => {
3532
+ const next = await estimateTxSize(state);
3533
+ if (active) setEstimate(next);
3534
+ })();
3535
+ return () => {
3536
+ active = false;
3537
+ };
3538
+ }, [
3539
+ state.pactCode,
3540
+ state.config.chainId,
3541
+ state.config.gasLimit,
3542
+ state.config.gasPriceAnu,
3543
+ state.config.ttl,
3544
+ state.payload,
3545
+ state.signers.length,
3546
+ state.gasPayer
3547
+ ]);
3548
+ const sizeTier = !estimate ? "pending" : estimate.over ? "error" : estimate.bytes > PROXY_SOFT_LIMIT ? "amber" : "ok";
3549
+ const sizeColor = sizeTier === "error" ? "var(--khr-error)" : sizeTier === "amber" ? "var(--khr-amber)" : sizeTier === "ok" ? "var(--khr-success)" : "var(--khr-text-dim)";
3550
+ const sizeValue = estimate ? `${formatBytes(estimate.bytes)} \xB7 ${estimate.permille.toFixed(4)} \u2030${estimate.over ? " \u26A0" : ""}` : "\u2026";
3551
+ const used = sim.result?.gasUsed;
3552
+ const limit = state.config.gasLimit;
3553
+ const hasSim = sim.result?.ok === true && typeof used === "number" && limit > 0;
3554
+ const overLimit = hasSim && used > limit;
3555
+ const usedFraction = hasSim ? Math.min(used / limit * 100, 100) : 0;
3556
+ const gasValue = hasSim ? overLimit ? `${formatThousands(used)} > ${formatThousands(limit)} \u26A0` : `${formatThousands(used)} / ${formatThousands(limit)}` : "Run Simulate";
3557
+ return /* @__PURE__ */ jsxs("div", { style: WRAP_STYLE, children: [
3558
+ /* @__PURE__ */ jsxs("div", { style: ROW_STYLE5, children: [
3559
+ /* @__PURE__ */ jsx("span", { style: LABEL_STYLE2, children: "Tx Size" }),
3560
+ /* @__PURE__ */ jsx("div", { style: TRACK_STYLE, children: /* @__PURE__ */ jsx(
3561
+ "div",
3562
+ {
3563
+ style: {
3564
+ width: estimate ? `${Math.min(estimate.fraction * 100, 100)}%` : "0%",
3565
+ backgroundColor: sizeColor
3566
+ }
3567
+ }
3568
+ ) }),
3569
+ /* @__PURE__ */ jsx("span", { style: { ...VALUE_STYLE, color: sizeColor }, children: sizeValue })
3570
+ ] }),
3571
+ /* @__PURE__ */ jsxs("div", { style: ROW_STYLE5, children: [
3572
+ /* @__PURE__ */ jsx("span", { style: LABEL_STYLE2, children: "Gas" }),
3573
+ /* @__PURE__ */ jsx("div", { style: TRACK_STYLE, children: hasSim ? overLimit ? /* @__PURE__ */ jsx("div", { style: { width: "100%", backgroundColor: "var(--khr-error)" } }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3574
+ /* @__PURE__ */ jsx("div", { style: { width: `${usedFraction}%`, backgroundColor: "var(--khr-amber)" } }),
3575
+ /* @__PURE__ */ jsx(
3576
+ "div",
3577
+ {
3578
+ style: { width: `${100 - usedFraction}%`, backgroundColor: "var(--khr-error)" }
3579
+ }
3580
+ )
3581
+ ] }) : null }),
3582
+ /* @__PURE__ */ jsx(
3583
+ "span",
3584
+ {
3585
+ style: { ...VALUE_STYLE, color: hasSim ? "var(--khr-text)" : "var(--khr-text-dim)" },
3586
+ children: gasValue
3587
+ }
3588
+ )
3589
+ ] })
3590
+ ] });
3591
+ }
3442
3592
  var DEFAULT_BUILDER_ROBOTS = "noindex,nofollow";
3443
3593
  var TABS = [
3444
3594
  { key: "config", label: "Config" },
@@ -3448,10 +3598,9 @@ var TABS = [
3448
3598
  { key: "execute", label: "Execute" }
3449
3599
  ];
3450
3600
  var PANE_WRAP = {
3451
- display: "grid",
3452
- gridTemplateColumns: "minmax(0, 1fr) minmax(0, 1fr)",
3453
- gap: "1rem",
3454
- alignItems: "start"
3601
+ display: "flex",
3602
+ flexDirection: "column",
3603
+ gap: "1rem"
3455
3604
  };
3456
3605
  var TABLIST = {
3457
3606
  display: "flex",
@@ -3490,6 +3639,7 @@ function Builder({
3490
3639
  }) {
3491
3640
  const adapter = useKhronotonAdapter();
3492
3641
  const actions = useCronotonActions(editId);
3642
+ const sim = useSimulate();
3493
3643
  const [state, setState] = useState(() => makeEmptyBuilderState());
3494
3644
  const [signers, setSigners] = useState([]);
3495
3645
  const [activeTab, setActiveTab] = useState("config");
@@ -3546,6 +3696,9 @@ function Builder({
3546
3696
  }
3547
3697
  }, [state, isEdit, editId, actions, onDone]);
3548
3698
  const calibratedGasLimit = state.config.autoGasLimit ? state.config.gasLimit : null;
3699
+ const handlePactCodeChange = useCallback((pactCode) => {
3700
+ setState((s) => ({ ...s, pactCode }));
3701
+ }, []);
3549
3702
  return /* @__PURE__ */ jsxs("div", { className: "khronoton-ui", children: [
3550
3703
  /* @__PURE__ */ jsx("meta", { name: "robots", content: robots }),
3551
3704
  isEdit && /* @__PURE__ */ jsxs("div", { style: EDIT_BANNER, children: [
@@ -3562,8 +3715,10 @@ function Builder({
3562
3715
  PactCodeEditor,
3563
3716
  {
3564
3717
  value: state.pactCode,
3565
- onChange: (pactCode) => setState((s) => ({ ...s, pactCode })),
3566
- onClear: () => setState((s) => ({ ...s, pactCode: "" }))
3718
+ onChange: handlePactCodeChange,
3719
+ onClear: () => setState((s) => ({ ...s, pactCode: "" })),
3720
+ height: 126,
3721
+ subBar: /* @__PURE__ */ jsx(TxMeters, { state, sim })
3567
3722
  }
3568
3723
  ),
3569
3724
  /* @__PURE__ */ jsxs("div", { children: [
@@ -3590,7 +3745,8 @@ function Builder({
3590
3745
  state,
3591
3746
  onChange: setState,
3592
3747
  onCommit: handleCommit,
3593
- committing
3748
+ committing,
3749
+ sim
3594
3750
  }
3595
3751
  )
3596
3752
  ] })
package/dist/ui.css CHANGED
@@ -32,4 +32,10 @@
32
32
  --khr-radius-lg: 14px;
33
33
  --khr-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
34
34
  --khr-mono-font: ui-monospace, "SFMono-Regular", "Geist Mono", Menlo, Consolas, monospace;
35
+ --khr-syntax-keyword: #c586c0;
36
+ --khr-syntax-type: #4ec9b0;
37
+ --khr-syntax-string: #ce9178;
38
+ --khr-syntax-number: #b5cea8;
39
+ --khr-syntax-atom: #d7ba7d;
40
+ --khr-selection: #1e3a5f;
35
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancientpantheon/khronoton-core",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Headless framework-agnostic scheduler engine: pure schedule math plus an injectable tick engine. No database, no job queue, no framework — hosts inject storage and firing via hooks.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -74,9 +74,14 @@
74
74
  },
75
75
  "license": "UNLICENSED",
76
76
  "peerDependencies": {
77
+ "@codemirror/language": "^6.12.4",
78
+ "@codemirror/state": "^6.5.2",
79
+ "@codemirror/view": "^6.36.4",
80
+ "@lezer/highlight": "^1.2.3",
77
81
  "@ouronet/ouronet-core": "^4.3.6",
78
82
  "@stoachain/kadena-stoic-legacy": "^4.3.6",
79
83
  "@stoachain/stoa-core": "^4.3.6",
84
+ "@uiw/react-codemirror": "^4.23.10",
80
85
  "react": "^18 || ^19",
81
86
  "react-dom": "^18 || ^19"
82
87
  },
@@ -93,7 +98,22 @@
93
98
  "@stoachain/stoa-core": {
94
99
  "optional": true
95
100
  },
96
- "@stoachain/ouronet-core": {
101
+ "@ouronet/ouronet-core": {
102
+ "optional": true
103
+ },
104
+ "@uiw/react-codemirror": {
105
+ "optional": true
106
+ },
107
+ "@codemirror/state": {
108
+ "optional": true
109
+ },
110
+ "@codemirror/view": {
111
+ "optional": true
112
+ },
113
+ "@codemirror/language": {
114
+ "optional": true
115
+ },
116
+ "@lezer/highlight": {
97
117
  "optional": true
98
118
  }
99
119
  },
@@ -101,8 +121,10 @@
101
121
  "better-sqlite3": "^12.11.1"
102
122
  },
103
123
  "devDependencies": {
124
+ "@codemirror/language": "^6.12.4",
104
125
  "@codemirror/state": "^6.5.2",
105
126
  "@codemirror/view": "^6.36.4",
127
+ "@lezer/highlight": "^1.2.3",
106
128
  "@ouronet/ouronet-core": "^4.3.6",
107
129
  "@stoachain/kadena-stoic-legacy": "^4.3.6",
108
130
  "@stoachain/stoa-core": "^4.3.6",
@@ -1,64 +0,0 @@
1
- import CodeMirror from '@uiw/react-codemirror';
2
- import { EditorView } from '@codemirror/view';
3
- import { jsx } from 'react/jsx-runtime';
4
-
5
- // src/ui/PactCodeMirror.tsx
6
- var GUTTER_BG = "#0d1117";
7
- var ACTIVE_LINE_BG = "#161616";
8
- var khronotonEditorTheme = EditorView.theme(
9
- {
10
- "&": {
11
- backgroundColor: "var(--khr-panel, #0a0a0a)",
12
- color: "var(--khr-mono, #d2d3d4)",
13
- fontSize: "12px"
14
- },
15
- ".cm-content": {
16
- fontFamily: "var(--khr-mono-font, ui-monospace, monospace)",
17
- caretColor: "var(--khr-accent, #f0a500)"
18
- },
19
- ".cm-cursor, .cm-dropCursor": {
20
- borderLeftColor: "var(--khr-accent, #f0a500)"
21
- },
22
- "&.cm-focused": {
23
- outline: "none"
24
- },
25
- "&.cm-editor.cm-focused": {
26
- outline: "1px solid var(--khr-accent, #f0a500)"
27
- },
28
- "&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": {
29
- backgroundColor: "var(--khr-accent-tint, #1a1500)"
30
- },
31
- ".cm-gutters": {
32
- backgroundColor: GUTTER_BG,
33
- color: "var(--khr-text-dim, #8a8f98)",
34
- border: "none"
35
- },
36
- ".cm-activeLine": { backgroundColor: ACTIVE_LINE_BG },
37
- ".cm-activeLineGutter": { backgroundColor: ACTIVE_LINE_BG }
38
- },
39
- { dark: true }
40
- );
41
- function PactCodeMirror({
42
- value,
43
- onChange,
44
- height
45
- }) {
46
- return /* @__PURE__ */ jsx(
47
- CodeMirror,
48
- {
49
- value,
50
- height: `${height}px`,
51
- theme: khronotonEditorTheme,
52
- basicSetup: {
53
- lineNumbers: true,
54
- foldGutter: false,
55
- closeBrackets: false,
56
- autocompletion: false,
57
- highlightActiveLine: true
58
- },
59
- onChange
60
- }
61
- );
62
- }
63
-
64
- export { PactCodeMirror as default };