@moxxy/sdk 0.13.0 → 0.14.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/dist/compactor-helpers.d.ts.map +1 -1
- package/dist/compactor-helpers.js +6 -3
- package/dist/compactor-helpers.js.map +1 -1
- package/dist/events.d.ts +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/frontmatter.d.ts +40 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +161 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/json-file-store.d.ts +84 -0
- package/dist/json-file-store.d.ts.map +1 -0
- package/dist/json-file-store.js +56 -0
- package/dist/json-file-store.js.map +1 -0
- package/dist/mode.d.ts +10 -0
- package/dist/mode.d.ts.map +1 -1
- package/dist/mode.js.map +1 -1
- package/dist/tool-dispatch.d.ts.map +1 -1
- package/dist/tool-dispatch.js +5 -2
- package/dist/tool-dispatch.js.map +1 -1
- package/dist/types.test-d.js +5 -0
- package/dist/types.test-d.js.map +1 -1
- package/package.json +1 -1
- package/src/compactor-helpers.test.ts +52 -0
- package/src/compactor-helpers.ts +6 -2
- package/src/events.ts +8 -1
- package/src/frontmatter.test.ts +141 -0
- package/src/frontmatter.ts +159 -0
- package/src/index.ts +12 -0
- package/src/json-file-store.test.ts +207 -0
- package/src/json-file-store.ts +144 -0
- package/src/mode.ts +10 -0
- package/src/tool-dispatch.ts +5 -2
- package/src/types.test-d.ts +13 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-dispatch.js","sourceRoot":"","sources":["../src/tool-dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAMxC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,gBAAgB,CAC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CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,sBAAsB,CAAC;QAC3E,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YACxB,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;gBAC5F,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;QACD,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC;YACnB,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,MAAM,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC;SAC1E,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/types.test-d.js
CHANGED
|
@@ -19,4 +19,9 @@ describe('event union narrowing', () => {
|
|
|
19
19
|
expectTypeOf(handle).returns.toEqualTypeOf();
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
|
+
describe('PluginRegisteredEvent.kind stays in sync with PluginKind', () => {
|
|
23
|
+
it('the inlined kind union equals PluginKind member-for-member', () => {
|
|
24
|
+
expectTypeOf().toEqualTypeOf();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
22
27
|
//# sourceMappingURL=types.test-d.js.map
|
package/dist/types.test-d.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.test-d.js","sourceRoot":"","sources":["../src/types.test-d.ts"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6 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
|
|
|
2
2
|
import {
|
|
3
3
|
asEventId,
|
|
4
4
|
asSessionId,
|
|
5
|
+
asToolCallId,
|
|
5
6
|
asTurnId,
|
|
6
7
|
estimateContextTokens,
|
|
7
8
|
isContextOverflowError,
|
|
@@ -39,6 +40,57 @@ describe('estimateContextTokens', () => {
|
|
|
39
40
|
// summary should count.
|
|
40
41
|
expect(estimateContextTokens(log)).toBe(10);
|
|
41
42
|
});
|
|
43
|
+
|
|
44
|
+
it('measures a ToolDisplayResult by its short forModel, not the bulky display', () => {
|
|
45
|
+
// A recent (not-yet-elided) file-diff tool_result: the model only ever
|
|
46
|
+
// sees the short `forModel` string, but a previous version of eventChars
|
|
47
|
+
// JSON.stringified the whole `display` payload — wildly over-counting and
|
|
48
|
+
// tripping compaction/elision thresholds prematurely. The estimate must
|
|
49
|
+
// match what projection actually sends (forModel only).
|
|
50
|
+
const forModel = 'Updated src/foo.ts (42 lines)'; // 29 chars
|
|
51
|
+
// A large display payload: many diff lines whose stringified form dwarfs
|
|
52
|
+
// forModel. If counted, the estimate would balloon.
|
|
53
|
+
const lines = Array.from({ length: 200 }, (_, i) => ({
|
|
54
|
+
kind: 'add' as const,
|
|
55
|
+
text: 'x'.repeat(80),
|
|
56
|
+
newNo: i + 1,
|
|
57
|
+
}));
|
|
58
|
+
const output = {
|
|
59
|
+
forModel,
|
|
60
|
+
display: {
|
|
61
|
+
kind: 'file-diff' as const,
|
|
62
|
+
path: 'src/foo.ts',
|
|
63
|
+
mode: 'update' as const,
|
|
64
|
+
added: 200,
|
|
65
|
+
removed: 0,
|
|
66
|
+
hunks: [{ oldStart: 1, oldLines: 0, newStart: 1, newLines: 200, lines }],
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
const log = reader([
|
|
70
|
+
event(0, { type: 'user_prompt', turnId: tid, source: 'user', text: 'hi' }),
|
|
71
|
+
event(1, {
|
|
72
|
+
type: 'tool_call_requested',
|
|
73
|
+
turnId: tid,
|
|
74
|
+
source: 'model',
|
|
75
|
+
callId: asToolCallId('c1'),
|
|
76
|
+
name: 'Edit',
|
|
77
|
+
input: {},
|
|
78
|
+
}),
|
|
79
|
+
event(2, {
|
|
80
|
+
type: 'tool_result',
|
|
81
|
+
turnId: tid,
|
|
82
|
+
source: 'tool',
|
|
83
|
+
callId: asToolCallId('c1'),
|
|
84
|
+
ok: true,
|
|
85
|
+
output,
|
|
86
|
+
}),
|
|
87
|
+
]);
|
|
88
|
+
// forModel is 29 chars; the bulky display (>16 KB stringified) must NOT be
|
|
89
|
+
// counted. Estimate must stay within a couple tokens of forModel.length/4,
|
|
90
|
+
// never the thousands of tokens the stringified display would imply.
|
|
91
|
+
const tokens = estimateContextTokens(log);
|
|
92
|
+
expect(tokens).toBeLessThan(50);
|
|
93
|
+
});
|
|
42
94
|
});
|
|
43
95
|
|
|
44
96
|
describe('runCompactionIfNeeded', () => {
|
package/src/compactor-helpers.ts
CHANGED
|
@@ -76,8 +76,12 @@ function eventChars(e: MoxxyEvent): number {
|
|
|
76
76
|
return e.name.length + safeJsonLen(e.input);
|
|
77
77
|
case 'tool_result':
|
|
78
78
|
if (e.error) return (e.error.message?.length ?? 0) + 12;
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
// Use the shared sizing helper so the estimate matches projection: a
|
|
80
|
+
// ToolDisplayResult (file diff) only ever sends its short `forModel`
|
|
81
|
+
// string, so `toolResultBytes` measures THAT rather than the bulky
|
|
82
|
+
// `display` payload — which would otherwise trip elision/compaction
|
|
83
|
+
// thresholds prematurely. Strings/JSON collapse into the same path.
|
|
84
|
+
return toolResultBytes(e.output);
|
|
81
85
|
default:
|
|
82
86
|
return 0;
|
|
83
87
|
}
|
package/src/events.ts
CHANGED
|
@@ -135,7 +135,9 @@ export interface PluginRegisteredEvent extends EventBase {
|
|
|
135
135
|
readonly name: string;
|
|
136
136
|
readonly version: string;
|
|
137
137
|
// Keep in sync with PluginKind (plugin.ts). Inlined rather than imported to
|
|
138
|
-
// avoid an events↔plugin type cycle (dep-cruiser flags circular deps).
|
|
138
|
+
// avoid an events↔plugin type cycle (dep-cruiser flags circular deps). The
|
|
139
|
+
// type-level test in events.test-d.ts asserts this union stays in lockstep
|
|
140
|
+
// with PluginKind so future additions fail the build instead of drifting.
|
|
139
141
|
readonly kind: ReadonlyArray<
|
|
140
142
|
| 'tools'
|
|
141
143
|
| 'provider'
|
|
@@ -147,10 +149,15 @@ export interface PluginRegisteredEvent extends EventBase {
|
|
|
147
149
|
| 'mcp'
|
|
148
150
|
| 'cli'
|
|
149
151
|
| 'channel'
|
|
152
|
+
| 'surface'
|
|
150
153
|
| 'hooks'
|
|
151
154
|
| 'agent'
|
|
152
155
|
| 'command'
|
|
153
156
|
| 'transcriber'
|
|
157
|
+
| 'synthesizer'
|
|
158
|
+
| 'embedder'
|
|
159
|
+
| 'isolator'
|
|
160
|
+
| 'workflow-executor'
|
|
154
161
|
>;
|
|
155
162
|
}
|
|
156
163
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { parseFrontmatter, parseFrontmatterFile, renderFrontmatter } from './frontmatter.js';
|
|
3
|
+
|
|
4
|
+
// Golden tests for the canonical frontmatter parser. This module replaced two
|
|
5
|
+
// previously-copy-pasted copies (packages/core/src/skills/parse.ts and
|
|
6
|
+
// packages/plugin-memory/src/parse.ts). The cases below pin the EXACT prior
|
|
7
|
+
// behavior of the more-correct `core` copy: parse output fields, missing/blank
|
|
8
|
+
// frontmatter handling, body offset, and the inline-array/scalar typing where
|
|
9
|
+
// the two copies had diverged.
|
|
10
|
+
describe('parseFrontmatterFile', () => {
|
|
11
|
+
it('returns empty frontmatter and original body when no fence present', () => {
|
|
12
|
+
const { frontmatter, body } = parseFrontmatterFile('hello world');
|
|
13
|
+
expect(frontmatter).toEqual({});
|
|
14
|
+
expect(body).toBe('hello world');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('returns the original content unchanged when the closing fence is missing', () => {
|
|
18
|
+
const input = '---\nname: foo\nbody but no close';
|
|
19
|
+
const { frontmatter, body } = parseFrontmatterFile(input);
|
|
20
|
+
expect(frontmatter).toEqual({});
|
|
21
|
+
expect(body).toBe(input);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('parses simple frontmatter and offsets the body past the closing fence', () => {
|
|
25
|
+
const { frontmatter, body } = parseFrontmatterFile(`---
|
|
26
|
+
name: foo
|
|
27
|
+
description: bar
|
|
28
|
+
---
|
|
29
|
+
body text`);
|
|
30
|
+
expect(frontmatter).toEqual({ name: 'foo', description: 'bar' });
|
|
31
|
+
expect(body).toBe('body text');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('preserves a multiline body verbatim after the --- fence', () => {
|
|
35
|
+
const md = `---\nname: foo\ndescription: d\n---\nline 1\n\nline 2`;
|
|
36
|
+
const { body } = parseFrontmatterFile(md);
|
|
37
|
+
expect(body).toBe('line 1\n\nline 2');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('treats an empty body after the fence as an empty string', () => {
|
|
41
|
+
const { frontmatter, body } = parseFrontmatterFile(`---\nname: foo\n---`);
|
|
42
|
+
expect(frontmatter).toEqual({ name: 'foo' });
|
|
43
|
+
expect(body).toBe('');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('handles CRLF opening + closing fences', () => {
|
|
47
|
+
const { frontmatter, body } = parseFrontmatterFile('---\r\nname: foo\r\n---\r\nbody');
|
|
48
|
+
expect(frontmatter).toEqual({ name: 'foo' });
|
|
49
|
+
expect(body).toBe('body');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('does not treat a leading "---" without a newline as a fence', () => {
|
|
53
|
+
const { frontmatter, body } = parseFrontmatterFile('---not a fence');
|
|
54
|
+
expect(frontmatter).toEqual({});
|
|
55
|
+
expect(body).toBe('---not a fence');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('parseFrontmatter', () => {
|
|
60
|
+
it('parses inline arrays with quoted commas (canonical splitArray behavior)', () => {
|
|
61
|
+
const fm = parseFrontmatter('triggers: [a, b, "c d"]');
|
|
62
|
+
expect(fm.triggers).toEqual(['a', 'b', 'c d']);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('keeps a quoted comma inside one inline-array element (divergence fix)', () => {
|
|
66
|
+
// The diverged plugin-memory copy split on bare commas; the canonical
|
|
67
|
+
// (core) copy must keep "a, b" as a single element.
|
|
68
|
+
const fm = parseFrontmatter('tags: ["a, b", c]');
|
|
69
|
+
expect(fm.tags).toEqual(['a, b', 'c']);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('parses nested inline arrays', () => {
|
|
73
|
+
const fm = parseFrontmatter('matrix: [[1, 2], [3, 4]]');
|
|
74
|
+
expect(fm.matrix).toEqual([
|
|
75
|
+
[1, 2],
|
|
76
|
+
[3, 4],
|
|
77
|
+
]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('parses empty inline arrays', () => {
|
|
81
|
+
expect(parseFrontmatter('items: []').items).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('parses block-list arrays', () => {
|
|
85
|
+
const fm = parseFrontmatter('allowed-tools:\n - Read\n - Edit\n - Bash');
|
|
86
|
+
expect(fm['allowed-tools']).toEqual(['Read', 'Edit', 'Bash']);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('parses numbers, floats, booleans, and null', () => {
|
|
90
|
+
const fm = parseFrontmatter('count: 3\nratio: 1.5\nbig: true\nzero: false\nempty: null\ntwiddle: ~');
|
|
91
|
+
expect(fm.count).toBe(3);
|
|
92
|
+
expect(fm.ratio).toBe(1.5);
|
|
93
|
+
expect(fm.big).toBe(true);
|
|
94
|
+
expect(fm.zero).toBe(false);
|
|
95
|
+
expect(fm.empty).toBeNull();
|
|
96
|
+
expect(fm.twiddle).toBeNull();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('strips quotes and tolerates colons inside quoted values', () => {
|
|
100
|
+
const fm = parseFrontmatter('description: "a: b"');
|
|
101
|
+
expect(fm.description).toBe('a: b');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('skips blank lines, comments, and lines without a colon', () => {
|
|
105
|
+
const fm = parseFrontmatter('# a comment\n\nname: foo\nnocolon\ndescription: bar');
|
|
106
|
+
expect(fm).toEqual({ name: 'foo', description: 'bar' });
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('returns an empty object for blank frontmatter text', () => {
|
|
110
|
+
expect(parseFrontmatter('')).toEqual({});
|
|
111
|
+
expect(parseFrontmatter(' \n ')).toEqual({});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('renderFrontmatter', () => {
|
|
116
|
+
it('renders scalars, arrays, and quotes values that need it', () => {
|
|
117
|
+
const rendered = renderFrontmatter({
|
|
118
|
+
name: 'foo',
|
|
119
|
+
tags: ['a', 'b'],
|
|
120
|
+
desc: 'a: b',
|
|
121
|
+
count: 3,
|
|
122
|
+
});
|
|
123
|
+
expect(rendered).toBe('---\nname: foo\ntags: [a, b]\ndesc: "a: b"\ncount: 3\n---');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('skips null and undefined values', () => {
|
|
127
|
+
const rendered = renderFrontmatter({ name: 'foo', gone: null, missing: undefined });
|
|
128
|
+
expect(rendered).toBe('---\nname: foo\n---');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('round-trips a representative document through render -> parse', () => {
|
|
132
|
+
const fm = { name: 'foo', description: 'a thing', tags: ['x', 'y'] };
|
|
133
|
+
const doc = `${renderFrontmatter(fm)}\n\nbody content\n`;
|
|
134
|
+
const parsed = parseFrontmatterFile(doc);
|
|
135
|
+
expect(parsed.frontmatter).toEqual(fm);
|
|
136
|
+
// The closing fence regex consumes `\n---\n`, so the blank line authored
|
|
137
|
+
// between the fence and the body survives in the body offset (unchanged
|
|
138
|
+
// historical behavior).
|
|
139
|
+
expect(parsed.body).toBe('\nbody content\n');
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical minimal Markdown + YAML-subset frontmatter parser.
|
|
3
|
+
*
|
|
4
|
+
* Pure string work, zero dependencies (node builtins only). This is the single
|
|
5
|
+
* home for the mini-parser that was previously copy-pasted into
|
|
6
|
+
* `packages/core/src/skills/parse.ts` and `packages/plugin-memory/src/parse.ts`.
|
|
7
|
+
* The plugin-memory copy had diverged (its inline-array scalar split on bare
|
|
8
|
+
* commas and dropped null/float typing); this module keeps the more-correct
|
|
9
|
+
* `core` behavior — depth/quote-aware inline arrays via {@link splitArray},
|
|
10
|
+
* `null`/`~`, and float parsing — so both packages share one source of truth.
|
|
11
|
+
*
|
|
12
|
+
* Supports a deliberately tiny YAML subset:
|
|
13
|
+
* - `key: value` scalars (string/number/float/bool/null, with quote stripping)
|
|
14
|
+
* - inline arrays `key: [a, b, "c d"]` (depth- and quote-aware)
|
|
15
|
+
* - block-list arrays (`key:` followed by ` - item` lines)
|
|
16
|
+
* Comments (`#`) and blank lines are skipped. Anything not recognized is left
|
|
17
|
+
* out of the frontmatter object.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export interface ParsedFrontmatter {
|
|
21
|
+
frontmatter: Record<string, unknown>;
|
|
22
|
+
body: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const FRONTMATTER_FENCE = '---';
|
|
26
|
+
const OPENING_FENCE_LF = FRONTMATTER_FENCE + '\n';
|
|
27
|
+
const OPENING_FENCE_CRLF = FRONTMATTER_FENCE + '\r\n';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Split a `---`-fenced Markdown document into its parsed frontmatter and body.
|
|
31
|
+
*
|
|
32
|
+
* If the content does not open with a `---` fence (LF or CRLF), or the closing
|
|
33
|
+
* `---` is missing, returns `{ frontmatter: {}, body: <original content> }`
|
|
34
|
+
* unchanged. The body excludes the closing fence and its trailing newline.
|
|
35
|
+
*/
|
|
36
|
+
export function parseFrontmatterFile(content: string): ParsedFrontmatter {
|
|
37
|
+
if (!content.startsWith(OPENING_FENCE_LF) && !content.startsWith(OPENING_FENCE_CRLF)) {
|
|
38
|
+
return { frontmatter: {}, body: content };
|
|
39
|
+
}
|
|
40
|
+
const fenceLen = content.startsWith(OPENING_FENCE_CRLF) ? OPENING_FENCE_CRLF.length : OPENING_FENCE_LF.length;
|
|
41
|
+
const rest = content.slice(fenceLen);
|
|
42
|
+
const endMatch = /\r?\n---(?:\r?\n|$)/.exec(rest);
|
|
43
|
+
if (!endMatch) return { frontmatter: {}, body: content };
|
|
44
|
+
return {
|
|
45
|
+
frontmatter: parseFrontmatter(rest.slice(0, endMatch.index)),
|
|
46
|
+
body: rest.slice(endMatch.index + endMatch[0].length),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Parse the inner text of a frontmatter block into a key/value object. */
|
|
51
|
+
export function parseFrontmatter(text: string): Record<string, unknown> {
|
|
52
|
+
const result: Record<string, unknown> = {};
|
|
53
|
+
const lines = text.split(/\r?\n/);
|
|
54
|
+
for (let i = 0; i < lines.length; i++) {
|
|
55
|
+
const trimmed = (lines[i] ?? '').trim();
|
|
56
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
57
|
+
const colon = trimmed.indexOf(':');
|
|
58
|
+
if (colon === -1) continue;
|
|
59
|
+
const key = trimmed.slice(0, colon).trim();
|
|
60
|
+
const raw = trimmed.slice(colon + 1).trim();
|
|
61
|
+
|
|
62
|
+
if (raw === '' && i + 1 < lines.length && /^\s*-\s/.test(lines[i + 1] ?? '')) {
|
|
63
|
+
const items: unknown[] = [];
|
|
64
|
+
while (i + 1 < lines.length && /^\s*-\s/.test(lines[i + 1] ?? '')) {
|
|
65
|
+
i += 1;
|
|
66
|
+
items.push(parseScalar((lines[i] ?? '').replace(/^\s*-\s*/, '').trim()));
|
|
67
|
+
}
|
|
68
|
+
result[key] = items;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
result[key] = parseScalar(raw);
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function parseScalar(v: string): unknown {
|
|
78
|
+
if (!v) return '';
|
|
79
|
+
if (v.startsWith('[') && v.endsWith(']')) {
|
|
80
|
+
const inner = v.slice(1, -1).trim();
|
|
81
|
+
if (!inner) return [];
|
|
82
|
+
return splitArray(inner).map((s) => parseScalar(s.trim()));
|
|
83
|
+
}
|
|
84
|
+
if (v === 'true') return true;
|
|
85
|
+
if (v === 'false') return false;
|
|
86
|
+
if (v === 'null' || v === '~') return null;
|
|
87
|
+
if (/^-?\d+$/.test(v)) return Number(v);
|
|
88
|
+
if (/^-?\d+\.\d+$/.test(v)) return Number(v);
|
|
89
|
+
return stripQuotes(v);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function stripQuotes(s: string): string {
|
|
93
|
+
if (s.length >= 2 && ((s.startsWith('"') && s.endsWith('"')) || (s.startsWith("'") && s.endsWith("'")))) {
|
|
94
|
+
return s.slice(1, -1);
|
|
95
|
+
}
|
|
96
|
+
return s;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Split a comma-separated inline-array body, honoring nesting and quotes. */
|
|
100
|
+
function splitArray(s: string): string[] {
|
|
101
|
+
const out: string[] = [];
|
|
102
|
+
let depth = 0;
|
|
103
|
+
let buf = '';
|
|
104
|
+
let inStr: '"' | "'" | null = null;
|
|
105
|
+
for (const c of s) {
|
|
106
|
+
if (inStr) {
|
|
107
|
+
buf += c;
|
|
108
|
+
if (c === inStr) inStr = null;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (c === '"' || c === "'") {
|
|
112
|
+
inStr = c;
|
|
113
|
+
buf += c;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (c === '[' || c === '{') depth++;
|
|
117
|
+
if (c === ']' || c === '}') depth--;
|
|
118
|
+
if (c === ',' && depth === 0) {
|
|
119
|
+
out.push(buf);
|
|
120
|
+
buf = '';
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
buf += c;
|
|
124
|
+
}
|
|
125
|
+
if (buf.trim()) out.push(buf);
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Render a frontmatter object back into a `---`-fenced YAML-subset block.
|
|
131
|
+
* Inverse-ish of {@link parseFrontmatter}; `undefined`/`null` values are
|
|
132
|
+
* skipped. (Used by callers that round-trip Markdown documents, e.g. the
|
|
133
|
+
* memory store.)
|
|
134
|
+
*/
|
|
135
|
+
export function renderFrontmatter(frontmatter: Record<string, unknown>): string {
|
|
136
|
+
const out: string[] = ['---'];
|
|
137
|
+
for (const [k, v] of Object.entries(frontmatter)) {
|
|
138
|
+
if (v === undefined || v === null) continue;
|
|
139
|
+
out.push(`${k}: ${renderValue(v)}`);
|
|
140
|
+
}
|
|
141
|
+
out.push('---');
|
|
142
|
+
return out.join('\n');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function renderValue(v: unknown): string {
|
|
146
|
+
if (v === null || v === undefined) return '';
|
|
147
|
+
if (typeof v === 'string') {
|
|
148
|
+
return needsQuoting(v) ? `"${v.replace(/"/g, '\\"')}"` : v;
|
|
149
|
+
}
|
|
150
|
+
if (typeof v === 'boolean' || typeof v === 'number') return String(v);
|
|
151
|
+
if (Array.isArray(v)) {
|
|
152
|
+
return `[${v.map((x) => renderValue(x)).join(', ')}]`;
|
|
153
|
+
}
|
|
154
|
+
return JSON.stringify(v);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function needsQuoting(s: string): boolean {
|
|
158
|
+
return s.includes(':') || s.includes('#') || s.includes('"') || s.startsWith(' ') || s.endsWith(' ');
|
|
159
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -191,6 +191,11 @@ export {
|
|
|
191
191
|
type WriteFileAtomicOptions,
|
|
192
192
|
} from './fs-utils.js';
|
|
193
193
|
export { createMutex, type Mutex } from './mutex.js';
|
|
194
|
+
export {
|
|
195
|
+
createJsonFileStore,
|
|
196
|
+
type JsonFileStore,
|
|
197
|
+
type JsonFileStoreOptions,
|
|
198
|
+
} from './json-file-store.js';
|
|
194
199
|
export { assertNever } from './assert.js';
|
|
195
200
|
export { compareSemver, parseSemverCore } from './semver.js';
|
|
196
201
|
export { readRequestBody, bearerTokenMatches } from './http-utils.js';
|
|
@@ -443,6 +448,13 @@ export {
|
|
|
443
448
|
type MoxxyPackageInput,
|
|
444
449
|
} from './schemas.js';
|
|
445
450
|
|
|
451
|
+
export {
|
|
452
|
+
parseFrontmatterFile,
|
|
453
|
+
parseFrontmatter,
|
|
454
|
+
renderFrontmatter,
|
|
455
|
+
type ParsedFrontmatter,
|
|
456
|
+
} from './frontmatter.js';
|
|
457
|
+
|
|
446
458
|
export {
|
|
447
459
|
getInstallHint,
|
|
448
460
|
type InstallHint,
|