@parall/cli 1.68.0 → 1.70.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/commands/dbs.d.ts.map +1 -1
- package/dist/commands/dbs.js +1 -8
- package/dist/commands/wiki.d.ts.map +1 -1
- package/dist/commands/wiki.js +20 -8
- package/dist/lib/wiki-index.d.ts +2 -0
- package/dist/lib/wiki-index.d.ts.map +1 -1
- package/dist/lib/wiki-index.js +28 -73
- package/dist/lib/wiki-search-text.d.ts +37 -0
- package/dist/lib/wiki-search-text.d.ts.map +1 -0
- package/dist/lib/wiki-search-text.js +170 -0
- package/package.json +8 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dbs.d.ts","sourceRoot":"","sources":["../../src/commands/dbs.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOtD;;;;;;;;8EAQ8E;AAC9E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"dbs.d.ts","sourceRoot":"","sources":["../../src/commands/dbs.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOtD;;;;;;;;8EAQ8E;AAC9E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,QAsHlD;AASD;yBACyB;AACzB,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,EAC1C,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAYjB"}
|
package/dist/commands/dbs.js
CHANGED
|
@@ -52,7 +52,6 @@ export function registerDbCommands(program) {
|
|
|
52
52
|
.option('--project <projectId>', DEPRECATED_PROJECT)
|
|
53
53
|
.requiredOption('--name <name>', 'Database name (unique in the organization)')
|
|
54
54
|
.option('--description <text>', 'Description')
|
|
55
|
-
.option('--members-read-only', 'Reserved for the future action layer; no effect on the raw-SQL surface')
|
|
56
55
|
.option('--agent-destructive-requires-approval <bool>', 'true (default) = destructive DDL and restores by an agent need org owner/admin approval')
|
|
57
56
|
.action(async (opts) => {
|
|
58
57
|
try {
|
|
@@ -60,8 +59,6 @@ export function registerDbCommands(program) {
|
|
|
60
59
|
const data = { name: opts.name };
|
|
61
60
|
if (opts.description)
|
|
62
61
|
data.description = opts.description;
|
|
63
|
-
if (opts.membersReadOnly)
|
|
64
|
-
data.members_read_only = true;
|
|
65
62
|
if (opts.agentDestructiveRequiresApproval !== undefined) {
|
|
66
63
|
data.agent_destructive_requires_approval = parseBoolFlag('--agent-destructive-requires-approval', opts.agentDestructiveRequiresApproval);
|
|
67
64
|
}
|
|
@@ -79,7 +76,6 @@ export function registerDbCommands(program) {
|
|
|
79
76
|
.option('--project <projectId>', DEPRECATED_PROJECT)
|
|
80
77
|
.option('--name <name>', 'New name')
|
|
81
78
|
.option('--description <text>', 'New description (empty string clears)')
|
|
82
|
-
.option('--members-read-only <bool>', 'Reserved for the future action layer; no effect on the raw-SQL surface')
|
|
83
79
|
.option('--agent-destructive-requires-approval <bool>', 'true (default) = destructive DDL and restores by an agent need org owner/admin approval')
|
|
84
80
|
.action(async (idOrName, opts) => {
|
|
85
81
|
try {
|
|
@@ -89,14 +85,11 @@ export function registerDbCommands(program) {
|
|
|
89
85
|
data.name = opts.name;
|
|
90
86
|
if (opts.description !== undefined)
|
|
91
87
|
data.description = opts.description;
|
|
92
|
-
if (opts.membersReadOnly !== undefined) {
|
|
93
|
-
data.members_read_only = parseBoolFlag('--members-read-only', opts.membersReadOnly);
|
|
94
|
-
}
|
|
95
88
|
if (opts.agentDestructiveRequiresApproval !== undefined) {
|
|
96
89
|
data.agent_destructive_requires_approval = parseBoolFlag('--agent-destructive-requires-approval', opts.agentDestructiveRequiresApproval);
|
|
97
90
|
}
|
|
98
91
|
if (Object.keys(data).length === 0) {
|
|
99
|
-
throw new Error('Nothing to update: pass at least one of --name, --description, --
|
|
92
|
+
throw new Error('Nothing to update: pass at least one of --name, --description, --agent-destructive-requires-approval');
|
|
100
93
|
}
|
|
101
94
|
const id = await resolveDatabaseId(ctx, idOrName);
|
|
102
95
|
printJson(await ctx.client.updateMiniAppDatabase(ctx.orgId, id, data));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wiki.d.ts","sourceRoot":"","sources":["../../src/commands/wiki.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"wiki.d.ts","sourceRoot":"","sources":["../../src/commands/wiki.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,QA+sBpD"}
|
package/dist/commands/wiki.js
CHANGED
|
@@ -448,15 +448,27 @@ export function registerWikiCommands(program) {
|
|
|
448
448
|
const { resolveWikiRefOrDefault, getWikiOutline } = await import('../lib/wiki.js');
|
|
449
449
|
const wiki = await resolveWikiRefOrDefault(ctx, wikiRef);
|
|
450
450
|
const outline = await getWikiOutline(ctx, wiki.slug, { pathPrefix: filePath });
|
|
451
|
-
// Find section whose heading_path ends with the fragment parts
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
451
|
+
// Find the section whose heading_path ends with the fragment parts.
|
|
452
|
+
// Unified search returns heading paths as reader text (character
|
|
453
|
+
// references decoded) while the outline keeps raw Markdown headings,
|
|
454
|
+
// so a raw match wins and a decoded match is the fallback; raw first
|
|
455
|
+
// keeps existing anchors resolving as before. When one heading's
|
|
456
|
+
// reader text equals another heading's raw text, the anchor resolves
|
|
457
|
+
// to the raw one: `x &amp; y` reads `x & y`, so next to a
|
|
458
|
+
// heading written `x & y` it cannot be located (its raw text has
|
|
459
|
+
// a `#`).
|
|
460
|
+
const endsWithFragment = (headings) => {
|
|
461
|
+
if (headings.length < fragParts.length)
|
|
456
462
|
return false;
|
|
457
|
-
const offset =
|
|
458
|
-
return fragParts.every((part, i) =>
|
|
459
|
-
}
|
|
463
|
+
const offset = headings.length - fragParts.length;
|
|
464
|
+
return fragParts.every((part, i) => headings[offset + i].toLowerCase() === part);
|
|
465
|
+
};
|
|
466
|
+
const fileNodes = outline.nodes.filter((node) => node.path === filePath);
|
|
467
|
+
let match = fileNodes.find((node) => endsWithFragment(node.heading_path ?? []));
|
|
468
|
+
if (!match) {
|
|
469
|
+
const { decodeHeadingCharacterReferences } = await import('../lib/wiki-search-text.js');
|
|
470
|
+
match = fileNodes.find((node) => endsWithFragment((node.heading_path ?? []).map(decodeHeadingCharacterReferences)));
|
|
471
|
+
}
|
|
460
472
|
if (!match) {
|
|
461
473
|
process.stderr.write(`Section not found: ${anchor}\n`);
|
|
462
474
|
process.stderr.write(`Available sections in ${filePath}:\n`);
|
package/dist/lib/wiki-index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wiki-index.d.ts","sourceRoot":"","sources":["../../src/lib/wiki-index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wiki-index.d.ts","sourceRoot":"","sources":["../../src/lib/wiki-index.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EAWtB,MAAM,kBAAkB,CAAC;AAE1B,KAAK,iBAAiB,GAAG,eAAe,GAAG;IACzC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAKF,KAAK,WAAW,GAAG;IACjB,O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MAAM,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAiBA"}
|
package/dist/lib/wiki-index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// Local wiki content index: node-section artifacts, search / query scoring
|
|
2
|
-
// markdown heading parsing
|
|
1
|
+
// Local wiki content index: node-section artifacts, search / query scoring
|
|
2
|
+
// and markdown heading parsing. Search text is tokenized by ./wiki-search-text.ts.
|
|
3
3
|
// Entry point for consumers is ./wiki.ts, which re-exports the public surface.
|
|
4
4
|
import { promises as fs } from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { hasFrontMatter, parseFrontMatter } from './wiki-frontmatter.js';
|
|
7
|
+
import { decodeCharacterReferences, decodeHeadingCharacterReferences, tokenize, } from './wiki-search-text.js';
|
|
7
8
|
import { PRLL_WIKI_DIR, compactWhitespace, enforceAllowedPrefix, matchesAllowedPrefix, normalizeRef, normalizeRequiredWikiPath, normalizeWikiPath, resolveLocalWikiMount, resolvePathInsideRoot, truncateSnippet, walkLocalMarkdownFiles, } from './wiki-shared.js';
|
|
8
9
|
/** Local wiki mount resolved from mount manifest V2 (REST-based). */
|
|
9
10
|
const MARKDOWN_HEADING_RE = /^\s{0,3}(#{1,6})[ \t]+(.+?)\s*$/;
|
|
@@ -281,14 +282,17 @@ function buildNodeSection(wiki, input) {
|
|
|
281
282
|
};
|
|
282
283
|
}
|
|
283
284
|
function buildIndexedNode(section, includeFrontmatter) {
|
|
285
|
+
const title = section.level > 0 ? decodeHeadingCharacterReferences(section.title) : section.title;
|
|
286
|
+
const headingPath = (section.heading_path ?? []).map(decodeHeadingCharacterReferences);
|
|
287
|
+
const content = decodeCharacterReferences(section.content);
|
|
284
288
|
const searchText = [
|
|
285
289
|
section.path,
|
|
286
|
-
|
|
287
|
-
|
|
290
|
+
title,
|
|
291
|
+
headingPath.join(' '),
|
|
288
292
|
...(includeFrontmatter
|
|
289
293
|
? [section.type ?? '', section.description ?? '', section.tags?.join(' ') ?? '']
|
|
290
294
|
: []),
|
|
291
|
-
|
|
295
|
+
content,
|
|
292
296
|
]
|
|
293
297
|
.join('\n')
|
|
294
298
|
.trim();
|
|
@@ -299,11 +303,13 @@ function buildIndexedNode(section, includeFrontmatter) {
|
|
|
299
303
|
}
|
|
300
304
|
return {
|
|
301
305
|
section,
|
|
302
|
-
|
|
306
|
+
title,
|
|
307
|
+
headingPath,
|
|
308
|
+
content,
|
|
303
309
|
lowerPath: section.path.toLowerCase(),
|
|
304
|
-
lowerTitle:
|
|
305
|
-
lowerBody:
|
|
306
|
-
lowerJoined: section.
|
|
310
|
+
lowerTitle: title.toLowerCase(),
|
|
311
|
+
lowerBody: content.toLowerCase(),
|
|
312
|
+
lowerJoined: [section.path, ...headingPath].join(' > ').toLowerCase(),
|
|
307
313
|
termFreq,
|
|
308
314
|
docLen: tokens.length,
|
|
309
315
|
};
|
|
@@ -334,7 +340,7 @@ export function scoreNodes(nodes, query, options) {
|
|
|
334
340
|
...stripNodeSectionContent(node.section),
|
|
335
341
|
score,
|
|
336
342
|
snippet: buildSnippet(node, lowerQuery, queryTokens),
|
|
337
|
-
content: options.includeContent ? node.content : undefined,
|
|
343
|
+
content: options.includeContent ? node.section.content : undefined,
|
|
338
344
|
source: options.source,
|
|
339
345
|
});
|
|
340
346
|
}
|
|
@@ -380,7 +386,7 @@ export function planWikiQuery(sections, query, options) {
|
|
|
380
386
|
score: plan.score,
|
|
381
387
|
document_score: documentScore,
|
|
382
388
|
snippet: buildSnippet(node, lowerQuery, queryTokens),
|
|
383
|
-
content: options.includeContent ? node.content : undefined,
|
|
389
|
+
content: options.includeContent ? node.section.content : undefined,
|
|
384
390
|
source: options.source,
|
|
385
391
|
reasoning: plan.reasoning,
|
|
386
392
|
});
|
|
@@ -419,7 +425,10 @@ function buildIndexedDocuments(sections) {
|
|
|
419
425
|
const documents = [];
|
|
420
426
|
for (const [filePath, fileSections] of byPath.entries()) {
|
|
421
427
|
fileSections.sort((a, b) => a.start_line - b.start_line);
|
|
422
|
-
const headings = Array.from(new Set(fileSections
|
|
428
|
+
const headings = Array.from(new Set(fileSections
|
|
429
|
+
.flatMap((section) => section.heading_path ?? [])
|
|
430
|
+
.filter(Boolean)
|
|
431
|
+
.map(decodeHeadingCharacterReferences)));
|
|
423
432
|
const title = fileSections.find((section) => section.level === 0)?.title ?? defaultFileTitle(filePath);
|
|
424
433
|
const searchText = [filePath, title, headings.join(' ')].join('\n').trim();
|
|
425
434
|
const tokens = tokenize(searchText);
|
|
@@ -468,6 +477,8 @@ function scoreDocuments(documents, queryTokens, lowerQuery) {
|
|
|
468
477
|
end_line: 1,
|
|
469
478
|
content: '',
|
|
470
479
|
},
|
|
480
|
+
title: document.title,
|
|
481
|
+
headingPath: document.headings,
|
|
471
482
|
content: '',
|
|
472
483
|
lowerPath: document.lowerPath,
|
|
473
484
|
lowerTitle: document.lowerTitle,
|
|
@@ -502,7 +513,7 @@ function scoreTreeAwareNode(node, queryTokens, lowerQuery, documentScore, scope)
|
|
|
502
513
|
score += 2.5;
|
|
503
514
|
reasoning.push('section title directly matches the query');
|
|
504
515
|
}
|
|
505
|
-
const matchedAncestors =
|
|
516
|
+
const matchedAncestors = node.headingPath
|
|
506
517
|
.slice(0, -1)
|
|
507
518
|
.filter((heading) => heading.toLowerCase().includes(lowerQuery) ||
|
|
508
519
|
queryTokens.some((token) => heading.toLowerCase().includes(token)));
|
|
@@ -510,7 +521,7 @@ function scoreTreeAwareNode(node, queryTokens, lowerQuery, documentScore, scope)
|
|
|
510
521
|
score += matchedAncestors.length * 1.25;
|
|
511
522
|
reasoning.push('ancestor headings match the query context');
|
|
512
523
|
}
|
|
513
|
-
const headingTokenHits = queryTokens.filter((token) =>
|
|
524
|
+
const headingTokenHits = queryTokens.filter((token) => node.headingPath.some((heading) => heading.toLowerCase().includes(token))).length;
|
|
514
525
|
if (headingTokenHits > 0) {
|
|
515
526
|
score += headingTokenHits * 0.6;
|
|
516
527
|
reasoning.push('heading path overlaps with query terms');
|
|
@@ -563,7 +574,7 @@ function scoreNode(node, queryTokens, lowerQuery, docFreq, totalDocs, avgDocLen)
|
|
|
563
574
|
return score;
|
|
564
575
|
}
|
|
565
576
|
function buildSnippet(node, lowerQuery, queryTokens) {
|
|
566
|
-
const lines = [node.
|
|
577
|
+
const lines = [node.title, ...node.content.split('\n')];
|
|
567
578
|
for (const line of lines) {
|
|
568
579
|
const compact = compactWhitespace(line);
|
|
569
580
|
if (!compact) {
|
|
@@ -584,7 +595,8 @@ function buildSnippet(node, lowerQuery, queryTokens) {
|
|
|
584
595
|
return truncateSnippet(compact, 220);
|
|
585
596
|
}
|
|
586
597
|
}
|
|
587
|
-
|
|
598
|
+
const sectionPath = [node.section.path, ...node.headingPath].join(' > ');
|
|
599
|
+
return truncateSnippet(compactWhitespace(node.content || sectionPath), 220);
|
|
588
600
|
}
|
|
589
601
|
// ---------------------------------------------------------------------------
|
|
590
602
|
// Markdown parsing helpers
|
|
@@ -699,60 +711,3 @@ function findFirstNonEmptyLine(lines, startLine, endLine) {
|
|
|
699
711
|
}
|
|
700
712
|
return start;
|
|
701
713
|
}
|
|
702
|
-
// ---------------------------------------------------------------------------
|
|
703
|
-
// Tokenizer (CJK-aware, for search/query)
|
|
704
|
-
// ---------------------------------------------------------------------------
|
|
705
|
-
function tokenize(text) {
|
|
706
|
-
const trimmed = text.trim();
|
|
707
|
-
if (!trimmed) {
|
|
708
|
-
return [];
|
|
709
|
-
}
|
|
710
|
-
const tokens = [];
|
|
711
|
-
let word = '';
|
|
712
|
-
let cjkRun = '';
|
|
713
|
-
const flushWord = () => {
|
|
714
|
-
if (!word) {
|
|
715
|
-
return;
|
|
716
|
-
}
|
|
717
|
-
tokens.push(word.toLowerCase());
|
|
718
|
-
word = '';
|
|
719
|
-
};
|
|
720
|
-
const flushCjk = () => {
|
|
721
|
-
if (!cjkRun) {
|
|
722
|
-
return;
|
|
723
|
-
}
|
|
724
|
-
const chars = Array.from(cjkRun.toLowerCase());
|
|
725
|
-
tokens.push(...chars);
|
|
726
|
-
if (chars.length > 1) {
|
|
727
|
-
for (let i = 0; i < chars.length - 1; i += 1) {
|
|
728
|
-
tokens.push(chars[i] + chars[i + 1]);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
cjkRun = '';
|
|
732
|
-
};
|
|
733
|
-
for (const char of Array.from(trimmed)) {
|
|
734
|
-
if (isCjkChar(char)) {
|
|
735
|
-
flushWord();
|
|
736
|
-
cjkRun += char;
|
|
737
|
-
continue;
|
|
738
|
-
}
|
|
739
|
-
if (/[0-9\p{L}]/u.test(char)) {
|
|
740
|
-
flushCjk();
|
|
741
|
-
word += char.toLowerCase();
|
|
742
|
-
continue;
|
|
743
|
-
}
|
|
744
|
-
flushWord();
|
|
745
|
-
flushCjk();
|
|
746
|
-
}
|
|
747
|
-
flushWord();
|
|
748
|
-
flushCjk();
|
|
749
|
-
return tokens;
|
|
750
|
-
}
|
|
751
|
-
function isCjkChar(char) {
|
|
752
|
-
const codePoint = char.codePointAt(0) ?? 0;
|
|
753
|
-
return ((codePoint >= 0x4e00 && codePoint <= 0x9fff) ||
|
|
754
|
-
(codePoint >= 0x3400 && codePoint <= 0x4dbf) ||
|
|
755
|
-
(codePoint >= 0x3040 && codePoint <= 0x309f) ||
|
|
756
|
-
(codePoint >= 0x30a0 && codePoint <= 0x30ff) ||
|
|
757
|
-
(codePoint >= 0xac00 && codePoint <= 0xd7af));
|
|
758
|
-
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Longer text is returned raw. micromark's inline resolution is quadratic on
|
|
3
|
+
* adversarial input (a 30 KB run of `_a*` takes over a second), and local
|
|
4
|
+
* search decodes every section on every query. Real sections are far smaller:
|
|
5
|
+
* when this cap was set, 1 of the 6,181 sections in the repository's docs/
|
|
6
|
+
* exceeded it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MAX_DECODED_LENGTH: number;
|
|
9
|
+
/**
|
|
10
|
+
* Markdown with every CommonMark character reference in reader text (`&`,
|
|
11
|
+
* `张`, `张`) replaced by the character(s) it denotes. The Web
|
|
12
|
+
* editor writes such references next to emphasis delimiters, e.g.
|
|
13
|
+
* `**负责人:**张三`, and every Wiki reader shows 张三.
|
|
14
|
+
*
|
|
15
|
+
* micromark (the Web reader's parser) recognizes the references, so code,
|
|
16
|
+
* raw HTML, autolinks and backslash-escaped ampersands are never touched; all
|
|
17
|
+
* other Markdown syntax is kept byte-for-byte. Text longer than
|
|
18
|
+
* {@link MAX_DECODED_LENGTH} is returned as is.
|
|
19
|
+
*
|
|
20
|
+
* Section content arrives trimmed by the section parser, so a body that opens
|
|
21
|
+
* with an indented code block parses as a paragraph here and its references
|
|
22
|
+
* decode; headings lose code context too (see
|
|
23
|
+
* {@link decodeHeadingCharacterReferences}).
|
|
24
|
+
*/
|
|
25
|
+
export declare function decodeCharacterReferences(markdown: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Decodes one heading title (inline heading content) as {@link decodeCharacterReferences}.
|
|
28
|
+
* The heading parser trims leading and trailing backticks from titles, which
|
|
29
|
+
* loses code context whenever a heading starts or ends with a code span:
|
|
30
|
+
* "`A&B`", "`A&B` notes" and "notes `A&B`" decode the reference
|
|
31
|
+
* inside the code, while "`a` & `b`" now reads as one code span and keeps
|
|
32
|
+
* the text reference literal. Only a reader title computed at parse time can
|
|
33
|
+
* tell these shapes apart.
|
|
34
|
+
*/
|
|
35
|
+
export declare function decodeHeadingCharacterReferences(title: string): string;
|
|
36
|
+
export declare function tokenize(text: string): string[];
|
|
37
|
+
//# sourceMappingURL=wiki-search-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wiki-search-text.d.ts","sourceRoot":"","sources":["../../src/lib/wiki-search-text.ts"],"names":[],"mappings":"AAiCA;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,QAAY,CAAC;AAK5C;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAiDlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKtE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAiD/C"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// Text preparation for local wiki search and query scoring: CommonMark
|
|
2
|
+
// character-reference decoding (the text a Wiki reader sees) and the
|
|
3
|
+
// CJK-aware tokenizer (Latin/digit words plus CJK unigrams and bigrams).
|
|
4
|
+
import { decodeNamedCharacterReference } from 'decode-named-character-reference';
|
|
5
|
+
import { parse, postprocess, preprocess } from 'micromark';
|
|
6
|
+
import { gfmTable } from 'micromark-extension-gfm-table';
|
|
7
|
+
import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference';
|
|
8
|
+
/** Text a reader never sees: link and definition destinations and titles, the
|
|
9
|
+
* labels of definitions and full references, and fenced-code info strings.
|
|
10
|
+
* References there stay literal, like code. */
|
|
11
|
+
const LITERAL_CONSTRUCTS = new Set([
|
|
12
|
+
'resourceDestination',
|
|
13
|
+
'resourceTitle',
|
|
14
|
+
'definitionLabelString',
|
|
15
|
+
'definitionDestination',
|
|
16
|
+
'definitionTitle',
|
|
17
|
+
'referenceString',
|
|
18
|
+
'codeFencedFenceInfo',
|
|
19
|
+
'codeFencedFenceMeta',
|
|
20
|
+
]);
|
|
21
|
+
/** GFM tables, as the server's search projection parses them: a `|` splits a
|
|
22
|
+
* cell even inside backticks. GFM autolink literals stay off there too, so
|
|
23
|
+
* references in a bare URL decode like the rest of the paragraph. */
|
|
24
|
+
const PARSE_OPTIONS = { extensions: [gfmTable()] };
|
|
25
|
+
/** Every character reference micromark can accept has this shape: 1–7
|
|
26
|
+
* decimal or 1–6 hexadecimal digits, or a 2–31 character entity name. Text
|
|
27
|
+
* without one is its own decoding and skips the parser. */
|
|
28
|
+
const REFERENCE_SHAPE = /&(?:#\d{1,7}|#[xX][\dA-Fa-f]{1,6}|[A-Za-z][A-Za-z\d]{1,30});/;
|
|
29
|
+
/**
|
|
30
|
+
* Longer text is returned raw. micromark's inline resolution is quadratic on
|
|
31
|
+
* adversarial input (a 30 KB run of `_a*` takes over a second), and local
|
|
32
|
+
* search decodes every section on every query. Real sections are far smaller:
|
|
33
|
+
* when this cap was set, 1 of the 6,181 sections in the repository's docs/
|
|
34
|
+
* exceeded it.
|
|
35
|
+
*/
|
|
36
|
+
export const MAX_DECODED_LENGTH = 16 * 1024;
|
|
37
|
+
/** Headings are decoded as ATX heading content, never as a block of their own. */
|
|
38
|
+
const HEADING_PREFIX = '# ';
|
|
39
|
+
/**
|
|
40
|
+
* Markdown with every CommonMark character reference in reader text (`&`,
|
|
41
|
+
* `张`, `张`) replaced by the character(s) it denotes. The Web
|
|
42
|
+
* editor writes such references next to emphasis delimiters, e.g.
|
|
43
|
+
* `**负责人:**张三`, and every Wiki reader shows 张三.
|
|
44
|
+
*
|
|
45
|
+
* micromark (the Web reader's parser) recognizes the references, so code,
|
|
46
|
+
* raw HTML, autolinks and backslash-escaped ampersands are never touched; all
|
|
47
|
+
* other Markdown syntax is kept byte-for-byte. Text longer than
|
|
48
|
+
* {@link MAX_DECODED_LENGTH} is returned as is.
|
|
49
|
+
*
|
|
50
|
+
* Section content arrives trimmed by the section parser, so a body that opens
|
|
51
|
+
* with an indented code block parses as a paragraph here and its references
|
|
52
|
+
* decode; headings lose code context too (see
|
|
53
|
+
* {@link decodeHeadingCharacterReferences}).
|
|
54
|
+
*/
|
|
55
|
+
export function decodeCharacterReferences(markdown) {
|
|
56
|
+
if (markdown.length > MAX_DECODED_LENGTH || !REFERENCE_SHAPE.test(markdown)) {
|
|
57
|
+
return markdown;
|
|
58
|
+
}
|
|
59
|
+
const events = postprocess(parse(PARSE_OPTIONS)
|
|
60
|
+
.document()
|
|
61
|
+
.write(preprocess()(markdown, undefined, true)));
|
|
62
|
+
// micromark skips a leading byte order mark, so its offsets start after it.
|
|
63
|
+
// wiki-service keeps a file's BOM in the file's first section.
|
|
64
|
+
const base = markdown.charCodeAt(0) === 0xfeff ? 1 : 0;
|
|
65
|
+
let out = '';
|
|
66
|
+
let copied = 0;
|
|
67
|
+
let literalDepth = 0;
|
|
68
|
+
let reference = { start: 0, end: 0, radix: 0 };
|
|
69
|
+
for (const [kind, token, context] of events) {
|
|
70
|
+
if (LITERAL_CONSTRUCTS.has(token.type)) {
|
|
71
|
+
literalDepth += kind === 'enter' ? 1 : -1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (literalDepth > 0 || kind !== 'enter') {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
switch (token.type) {
|
|
78
|
+
case 'characterReference':
|
|
79
|
+
reference = { start: base + token.start.offset, end: base + token.end.offset, radix: 0 };
|
|
80
|
+
break;
|
|
81
|
+
case 'characterReferenceMarkerNumeric':
|
|
82
|
+
reference.radix = 10;
|
|
83
|
+
break;
|
|
84
|
+
case 'characterReferenceMarkerHexadecimal':
|
|
85
|
+
reference.radix = 16;
|
|
86
|
+
break;
|
|
87
|
+
case 'characterReferenceValue': {
|
|
88
|
+
const value = context.sliceSerialize(token);
|
|
89
|
+
const decoded = reference.radix === 0
|
|
90
|
+
? decodeNamedCharacterReference(value)
|
|
91
|
+
: decodeNumericCharacterReference(value, reference.radix);
|
|
92
|
+
if (decoded !== false) {
|
|
93
|
+
out += markdown.slice(copied, reference.start) + decoded;
|
|
94
|
+
copied = reference.end;
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return out + markdown.slice(copied);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Decodes one heading title (inline heading content) as {@link decodeCharacterReferences}.
|
|
104
|
+
* The heading parser trims leading and trailing backticks from titles, which
|
|
105
|
+
* loses code context whenever a heading starts or ends with a code span:
|
|
106
|
+
* "`A&B`", "`A&B` notes" and "notes `A&B`" decode the reference
|
|
107
|
+
* inside the code, while "`a` & `b`" now reads as one code span and keeps
|
|
108
|
+
* the text reference literal. Only a reader title computed at parse time can
|
|
109
|
+
* tell these shapes apart.
|
|
110
|
+
*/
|
|
111
|
+
export function decodeHeadingCharacterReferences(title) {
|
|
112
|
+
if (!title.includes('&') || /[\r\n]/.test(title)) {
|
|
113
|
+
return title;
|
|
114
|
+
}
|
|
115
|
+
return decodeCharacterReferences(HEADING_PREFIX + title).slice(HEADING_PREFIX.length);
|
|
116
|
+
}
|
|
117
|
+
export function tokenize(text) {
|
|
118
|
+
const trimmed = text.trim();
|
|
119
|
+
if (!trimmed) {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
const tokens = [];
|
|
123
|
+
let word = '';
|
|
124
|
+
let cjkRun = '';
|
|
125
|
+
const flushWord = () => {
|
|
126
|
+
if (!word) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
tokens.push(word.toLowerCase());
|
|
130
|
+
word = '';
|
|
131
|
+
};
|
|
132
|
+
const flushCjk = () => {
|
|
133
|
+
if (!cjkRun) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const chars = Array.from(cjkRun.toLowerCase());
|
|
137
|
+
tokens.push(...chars);
|
|
138
|
+
if (chars.length > 1) {
|
|
139
|
+
for (let i = 0; i < chars.length - 1; i += 1) {
|
|
140
|
+
tokens.push(chars[i] + chars[i + 1]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
cjkRun = '';
|
|
144
|
+
};
|
|
145
|
+
for (const char of Array.from(trimmed)) {
|
|
146
|
+
if (isCjkChar(char)) {
|
|
147
|
+
flushWord();
|
|
148
|
+
cjkRun += char;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (/[0-9\p{L}]/u.test(char)) {
|
|
152
|
+
flushCjk();
|
|
153
|
+
word += char.toLowerCase();
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
flushWord();
|
|
157
|
+
flushCjk();
|
|
158
|
+
}
|
|
159
|
+
flushWord();
|
|
160
|
+
flushCjk();
|
|
161
|
+
return tokens;
|
|
162
|
+
}
|
|
163
|
+
function isCjkChar(char) {
|
|
164
|
+
const codePoint = char.codePointAt(0) ?? 0;
|
|
165
|
+
return ((codePoint >= 0x4e00 && codePoint <= 0x9fff) ||
|
|
166
|
+
(codePoint >= 0x3400 && codePoint <= 0x4dbf) ||
|
|
167
|
+
(codePoint >= 0x3040 && codePoint <= 0x309f) ||
|
|
168
|
+
(codePoint >= 0x30a0 && codePoint <= 0x30ff) ||
|
|
169
|
+
(codePoint >= 0xac00 && codePoint <= 0xd7af));
|
|
170
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parall/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.70.0",
|
|
4
4
|
"description": "CLI client for Parall — universal agent & human access to Parall API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -33,13 +33,17 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@modelcontextprotocol/sdk": "1.27.1",
|
|
35
35
|
"commander": "^13.0.0",
|
|
36
|
+
"decode-named-character-reference": "^1.3.0",
|
|
36
37
|
"diff": "^8.0.3",
|
|
37
38
|
"js-yaml": "^4.1.0",
|
|
39
|
+
"micromark": "^4.0.2",
|
|
40
|
+
"micromark-extension-gfm-table": "^2.1.1",
|
|
41
|
+
"micromark-util-decode-numeric-character-reference": "^2.0.2",
|
|
38
42
|
"node-diff3": "3.2.1",
|
|
39
43
|
"tar-stream": "^3.2.1",
|
|
40
44
|
"zod": "^4.3.6",
|
|
41
|
-
"@parall/agent-core": "1.
|
|
42
|
-
"@parall/sdk": "1.
|
|
45
|
+
"@parall/agent-core": "1.70.0",
|
|
46
|
+
"@parall/sdk": "1.70.0"
|
|
43
47
|
},
|
|
44
48
|
"devDependencies": {
|
|
45
49
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -47,7 +51,7 @@
|
|
|
47
51
|
"@types/tar-stream": "^3.1.4",
|
|
48
52
|
"esbuild": "^0.25.0",
|
|
49
53
|
"typescript": "^5.7.0",
|
|
50
|
-
"@parall/agent-core": "1.
|
|
54
|
+
"@parall/agent-core": "1.70.0"
|
|
51
55
|
},
|
|
52
56
|
"scripts": {
|
|
53
57
|
"build": "tsc",
|