@ksm0709/context 0.0.29 → 0.0.31
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/cli/index.js +1850 -247
- package/dist/index.js +4 -4
- package/dist/omc/session-start-hook.js +514 -0
- package/dist/omc/stop-hook.js +40 -0
- package/dist/omx/index.mjs +81 -51
- package/package.json +4 -4
package/dist/cli/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli/commands/update.ts
|
|
5
|
-
import { resolve, join as
|
|
6
|
-
import { existsSync as
|
|
7
|
-
import { homedir } from "os";
|
|
5
|
+
import { resolve as resolve3, join as join7 } from "path";
|
|
6
|
+
import { existsSync as existsSync8 } from "fs";
|
|
7
|
+
import { homedir as homedir3 } from "os";
|
|
8
8
|
|
|
9
9
|
// src/lib/scaffold.ts
|
|
10
10
|
import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
@@ -27,7 +27,7 @@ function resolveContextDir(projectDir) {
|
|
|
27
27
|
// package.json
|
|
28
28
|
var package_default = {
|
|
29
29
|
name: "@ksm0709/context",
|
|
30
|
-
version: "0.0.
|
|
30
|
+
version: "0.0.31",
|
|
31
31
|
author: {
|
|
32
32
|
name: "TaehoKang",
|
|
33
33
|
email: "ksm07091@gmail.com"
|
|
@@ -57,10 +57,10 @@ var package_default = {
|
|
|
57
57
|
access: "public"
|
|
58
58
|
},
|
|
59
59
|
scripts: {
|
|
60
|
-
build: "bun build ./src/index.ts --outdir dist --target bun && bun build ./src/mcp.ts --outdir dist --target bun && bun build ./src/cli/index.ts --outdir dist/cli --target bun && bun build ./src/omx/index.ts --outdir dist/omx --target node --format esm --external jsonc-parser && mv dist/omx/index.js dist/omx/index.mjs",
|
|
60
|
+
build: "bun build ./src/index.ts --outdir dist --target bun && bun build ./src/mcp.ts --outdir dist --target bun && bun build ./src/cli/index.ts --outdir dist/cli --target bun && bun build ./src/omx/index.ts --outdir dist/omx --target node --format esm --external jsonc-parser && mv dist/omx/index.js dist/omx/index.mjs && bun build ./src/omc/session-start-hook.ts --outdir dist/omc --target bun && bun build ./src/omc/stop-hook.ts --outdir dist/omc --target bun",
|
|
61
61
|
test: "vitest run",
|
|
62
62
|
lint: "eslint src --ext .ts",
|
|
63
|
-
prepublishOnly: "bun build ./src/index.ts --outdir dist --target bun && bun build ./src/mcp.ts --outdir dist --target bun && bun build ./src/cli/index.ts --outdir dist/cli --target bun && bun build ./src/omx/index.ts --outdir dist/omx --target node --format esm --external jsonc-parser && mv dist/omx/index.js dist/omx/index.mjs"
|
|
63
|
+
prepublishOnly: "bun build ./src/index.ts --outdir dist --target bun && bun build ./src/mcp.ts --outdir dist --target bun && bun build ./src/cli/index.ts --outdir dist/cli --target bun && bun build ./src/omx/index.ts --outdir dist/omx --target node --format esm --external jsonc-parser && mv dist/omx/index.js dist/omx/index.mjs && bun build ./src/omc/session-start-hook.ts --outdir dist/omc --target bun && bun build ./src/omc/stop-hook.ts --outdir dist/omc --target bun"
|
|
64
64
|
},
|
|
65
65
|
files: [
|
|
66
66
|
"dist"
|
|
@@ -69,7 +69,7 @@ var package_default = {
|
|
|
69
69
|
"@opencode-ai/plugin": ">=1.0.0"
|
|
70
70
|
},
|
|
71
71
|
dependencies: {
|
|
72
|
-
"@ksm0709/context": "^0.0.
|
|
72
|
+
"@ksm0709/context": "^0.0.30",
|
|
73
73
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
74
74
|
"jsonc-parser": "^3.0.0"
|
|
75
75
|
},
|
|
@@ -397,6 +397,29 @@ var TEMPLATE_FILES = {
|
|
|
397
397
|
"index.md": DEFAULT_INDEX_TEMPLATE,
|
|
398
398
|
"work-complete.txt": DEFAULT_WORK_COMPLETE_TEMPLATE
|
|
399
399
|
};
|
|
400
|
+
function scaffoldIfNeeded(projectDir) {
|
|
401
|
+
const contextDir = join2(projectDir, resolveContextDir(projectDir));
|
|
402
|
+
if (existsSync2(contextDir)) {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const templatesDir = join2(contextDir, "templates");
|
|
407
|
+
mkdirSync(templatesDir, { recursive: true });
|
|
408
|
+
const guidesDir = join2(contextDir, "guides");
|
|
409
|
+
mkdirSync(guidesDir, { recursive: true });
|
|
410
|
+
writeFileSync(join2(contextDir, "config.jsonc"), DEFAULT_CONFIG, "utf-8");
|
|
411
|
+
for (const [filename, content] of Object.entries(TEMPLATE_FILES)) {
|
|
412
|
+
writeFileSync(join2(templatesDir, filename), content, "utf-8");
|
|
413
|
+
}
|
|
414
|
+
for (const [filename, content] of Object.entries(GUIDE_FILES)) {
|
|
415
|
+
writeFileSync(join2(guidesDir, filename), content, "utf-8");
|
|
416
|
+
}
|
|
417
|
+
writeVersion(contextDir, PLUGIN_VERSION);
|
|
418
|
+
return true;
|
|
419
|
+
} catch {
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
400
423
|
function updateScaffold(projectDir) {
|
|
401
424
|
const contextDir = join2(projectDir, resolveContextDir(projectDir));
|
|
402
425
|
mkdirSync(join2(contextDir, "templates"), { recursive: true });
|
|
@@ -426,199 +449,63 @@ function writeVersion(contextDir, version) {
|
|
|
426
449
|
writeFileSync(join2(contextDir, ".version"), version, "utf-8");
|
|
427
450
|
}
|
|
428
451
|
|
|
429
|
-
// src/cli/commands/update.ts
|
|
430
|
-
var KNOWN_SUBCOMMANDS = ["all", "prompt", "plugin"];
|
|
431
|
-
function runUpdate(args) {
|
|
432
|
-
const [subcommand, ...rest] = args;
|
|
433
|
-
switch (subcommand) {
|
|
434
|
-
case undefined:
|
|
435
|
-
case "all":
|
|
436
|
-
runUpdateAll(resolve(rest[0] ?? process.cwd()));
|
|
437
|
-
break;
|
|
438
|
-
case "prompt":
|
|
439
|
-
process.stdout.write(`Prompt update is no longer supported.
|
|
440
|
-
`);
|
|
441
|
-
break;
|
|
442
|
-
case "plugin":
|
|
443
|
-
runUpdatePlugin(rest[0] ?? "latest");
|
|
444
|
-
break;
|
|
445
|
-
default:
|
|
446
|
-
if (!KNOWN_SUBCOMMANDS.includes(subcommand)) {
|
|
447
|
-
runUpdateAll(resolve(subcommand));
|
|
448
|
-
} else {
|
|
449
|
-
process.stderr.write(`Unknown update subcommand: ${subcommand}
|
|
450
|
-
`);
|
|
451
|
-
process.exit(1);
|
|
452
|
-
}
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
function runUpdateAll(projectDir) {
|
|
457
|
-
const updated = updateScaffold(projectDir);
|
|
458
|
-
if (updated.length === 0) {
|
|
459
|
-
process.stdout.write(`All scaffold files are already up to date.
|
|
460
|
-
`);
|
|
461
|
-
} else {
|
|
462
|
-
process.stdout.write(`Updated ${updated.length} file(s):
|
|
463
|
-
`);
|
|
464
|
-
for (const f of updated) {
|
|
465
|
-
process.stdout.write(` - ${f}
|
|
466
|
-
`);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
function detectPackageManager() {
|
|
471
|
-
if (existsSync3("bun.lock") || existsSync3("bun.lockb"))
|
|
472
|
-
return "bun";
|
|
473
|
-
if (existsSync3("pnpm-lock.yaml"))
|
|
474
|
-
return "pnpm";
|
|
475
|
-
if (existsSync3("yarn.lock"))
|
|
476
|
-
return "yarn";
|
|
477
|
-
if (existsSync3("package-lock.json"))
|
|
478
|
-
return "npm";
|
|
479
|
-
return "bun";
|
|
480
|
-
}
|
|
481
|
-
function detectGlobalInstalls() {
|
|
482
|
-
const installs = [];
|
|
483
|
-
const bunGlobalBin = join3(homedir(), ".bun", "bin", "context");
|
|
484
|
-
if (existsSync3(bunGlobalBin)) {
|
|
485
|
-
installs.push({ pm: "bun", label: "bun global", installCmd: ["bun", "install", "-g"] });
|
|
486
|
-
}
|
|
487
|
-
const spawnSync = globalThis.Bun?.spawnSync;
|
|
488
|
-
if (spawnSync) {
|
|
489
|
-
const whichResult = spawnSync(["which", "context"]);
|
|
490
|
-
if (whichResult.exitCode === 0) {
|
|
491
|
-
const binPath = whichResult.stdout.toString().trim();
|
|
492
|
-
if (binPath && !binPath.includes(".bun") && !binPath.includes("node_modules")) {
|
|
493
|
-
installs.push({ pm: "npm", label: "npm global", installCmd: ["npm", "install", "-g"] });
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
return installs;
|
|
498
|
-
}
|
|
499
|
-
function runUpdatePlugin(version) {
|
|
500
|
-
const pkg = `@ksm0709/context@${version}`;
|
|
501
|
-
const spawnSync = globalThis.Bun?.spawnSync;
|
|
502
|
-
if (!spawnSync) {
|
|
503
|
-
process.stderr.write(`Bun runtime required for plugin updates.
|
|
504
|
-
`);
|
|
505
|
-
process.exit(1);
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
const globalInstalls = detectGlobalInstalls();
|
|
509
|
-
for (const { label, installCmd } of globalInstalls) {
|
|
510
|
-
process.stdout.write(`Updating ${label} ${pkg}...
|
|
511
|
-
`);
|
|
512
|
-
const result = spawnSync([...installCmd, pkg]);
|
|
513
|
-
if (result.exitCode !== 0) {
|
|
514
|
-
process.stderr.write(`Failed to update ${label}: ${result.stderr.toString()}
|
|
515
|
-
`);
|
|
516
|
-
process.exit(1);
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
process.stdout.write(`Successfully updated ${label} ${pkg}.
|
|
520
|
-
`);
|
|
521
|
-
}
|
|
522
|
-
const pm = detectPackageManager();
|
|
523
|
-
process.stdout.write(`Updating local ${pkg} using ${pm}...
|
|
524
|
-
`);
|
|
525
|
-
const localResult = spawnSync([pm, "add", pkg]);
|
|
526
|
-
if (localResult.exitCode !== 0) {
|
|
527
|
-
process.stderr.write(`Failed to update local: ${localResult.stderr.toString()}
|
|
528
|
-
`);
|
|
529
|
-
process.exit(1);
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
process.stdout.write(`Successfully updated local ${pkg}.
|
|
533
|
-
`);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
// src/cli/commands/migrate.ts
|
|
537
|
-
import { resolve as resolve2, join as join4 } from "path";
|
|
538
|
-
import { existsSync as existsSync4, cpSync, rmSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
539
|
-
var LEGACY_CONTEXT_DIR = ".opencode/context";
|
|
540
|
-
var NEW_CONTEXT_DIR = ".context";
|
|
541
|
-
function runMigrate(args) {
|
|
542
|
-
const keepFlag = args.includes("--keep");
|
|
543
|
-
const pathArg = args.find((a) => !a.startsWith("--"));
|
|
544
|
-
const projectDir = resolve2(pathArg ?? process.cwd());
|
|
545
|
-
const legacyDir = join4(projectDir, LEGACY_CONTEXT_DIR);
|
|
546
|
-
const newDir = join4(projectDir, NEW_CONTEXT_DIR);
|
|
547
|
-
if (!existsSync4(legacyDir)) {
|
|
548
|
-
process.stdout.write(`Nothing to migrate.
|
|
549
|
-
`);
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
|
-
if (existsSync4(newDir)) {
|
|
553
|
-
process.stderr.write(`Target .context/ already exists. Aborting.
|
|
554
|
-
`);
|
|
555
|
-
process.exit(1);
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
cpSync(legacyDir, newDir, { recursive: true });
|
|
559
|
-
updateConfigPaths(newDir);
|
|
560
|
-
if (!keepFlag) {
|
|
561
|
-
rmSync(legacyDir, { recursive: true, force: true });
|
|
562
|
-
}
|
|
563
|
-
process.stdout.write(`Migrated .opencode/context/ \u2192 .context/
|
|
564
|
-
`);
|
|
565
|
-
}
|
|
566
|
-
function updateConfigPaths(contextDir) {
|
|
567
|
-
const configPath = join4(contextDir, "config.jsonc");
|
|
568
|
-
if (!existsSync4(configPath))
|
|
569
|
-
return;
|
|
570
|
-
try {
|
|
571
|
-
const content = readFileSync2(configPath, "utf-8");
|
|
572
|
-
const updated = content.replaceAll(".opencode/context/", "");
|
|
573
|
-
if (updated !== content) {
|
|
574
|
-
writeFileSync2(configPath, updated, "utf-8");
|
|
575
|
-
}
|
|
576
|
-
} catch {}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
452
|
// src/cli/commands/install.ts
|
|
580
|
-
import { join as join6, resolve as
|
|
581
|
-
import { existsSync as
|
|
453
|
+
import { join as join6, resolve as resolve2, dirname as dirname5 } from "path";
|
|
454
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync5, copyFileSync } from "fs";
|
|
582
455
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
583
|
-
import { createRequire } from "module";
|
|
456
|
+
import { createRequire as createRequire2 } from "module";
|
|
457
|
+
import { execSync } from "child_process";
|
|
584
458
|
|
|
585
459
|
// src/omx/registry.ts
|
|
460
|
+
import { join as join4, dirname as dirname2 } from "path";
|
|
461
|
+
import { existsSync as existsSync4, readFileSync as readFileSync2, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2 } from "fs";
|
|
462
|
+
import { homedir } from "os";
|
|
463
|
+
|
|
464
|
+
// src/shared/mcp-path.ts
|
|
586
465
|
import { fileURLToPath } from "url";
|
|
587
|
-
import { dirname, join as
|
|
588
|
-
import { existsSync as
|
|
589
|
-
import {
|
|
466
|
+
import { dirname, join as join3, resolve } from "path";
|
|
467
|
+
import { existsSync as existsSync3 } from "fs";
|
|
468
|
+
import { createRequire } from "module";
|
|
590
469
|
function resolveMcpPath() {
|
|
470
|
+
try {
|
|
471
|
+
const req = createRequire(import.meta.url);
|
|
472
|
+
const pkgJsonPath = req.resolve("@ksm0709/context/package.json");
|
|
473
|
+
const pkgRoot = dirname(pkgJsonPath);
|
|
474
|
+
const distMcp = join3(pkgRoot, "dist", "mcp.js");
|
|
475
|
+
if (existsSync3(distMcp))
|
|
476
|
+
return distMcp;
|
|
477
|
+
} catch {}
|
|
591
478
|
const currentFile = fileURLToPath(import.meta.url);
|
|
592
479
|
const currentDir = dirname(currentFile);
|
|
593
|
-
const distMcpPath =
|
|
594
|
-
if (
|
|
480
|
+
const distMcpPath = resolve(currentDir, "..", "mcp.js");
|
|
481
|
+
if (existsSync3(distMcpPath))
|
|
595
482
|
return distMcpPath;
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
if (existsSync5(srcMcpPath)) {
|
|
483
|
+
const srcMcpPath = resolve(currentDir, "..", "mcp.ts");
|
|
484
|
+
if (existsSync3(srcMcpPath))
|
|
599
485
|
return srcMcpPath;
|
|
600
|
-
}
|
|
601
486
|
return distMcpPath;
|
|
602
487
|
}
|
|
488
|
+
|
|
489
|
+
// src/omx/registry.ts
|
|
603
490
|
function getRegistryPaths() {
|
|
604
491
|
return [
|
|
605
|
-
|
|
606
|
-
|
|
492
|
+
join4(homedir(), ".omx", "mcp-registry.json"),
|
|
493
|
+
join4(homedir(), ".omc", "mcp-registry.json")
|
|
607
494
|
];
|
|
608
495
|
}
|
|
609
496
|
function ensureMcpRegistered(sdkLog) {
|
|
610
497
|
const registryPaths = getRegistryPaths();
|
|
611
498
|
let targetPath = registryPaths[0];
|
|
612
499
|
for (const p of registryPaths) {
|
|
613
|
-
if (
|
|
500
|
+
if (existsSync4(p)) {
|
|
614
501
|
targetPath = p;
|
|
615
502
|
break;
|
|
616
503
|
}
|
|
617
504
|
}
|
|
618
505
|
let registry = {};
|
|
619
|
-
if (
|
|
506
|
+
if (existsSync4(targetPath)) {
|
|
620
507
|
try {
|
|
621
|
-
const content =
|
|
508
|
+
const content = readFileSync2(targetPath, "utf-8");
|
|
622
509
|
registry = JSON.parse(content);
|
|
623
510
|
} catch (e) {
|
|
624
511
|
if (sdkLog) {
|
|
@@ -644,8 +531,8 @@ function ensureMcpRegistered(sdkLog) {
|
|
|
644
531
|
}
|
|
645
532
|
if (changed) {
|
|
646
533
|
try {
|
|
647
|
-
mkdirSync2(
|
|
648
|
-
|
|
534
|
+
mkdirSync2(dirname2(targetPath), { recursive: true });
|
|
535
|
+
writeFileSync2(targetPath, JSON.stringify(registry, null, 2), "utf-8");
|
|
649
536
|
if (sdkLog) {
|
|
650
537
|
sdkLog(`[INFO] Registered context_mcp in ${targetPath}`);
|
|
651
538
|
}
|
|
@@ -660,86 +547,1802 @@ function ensureMcpRegistered(sdkLog) {
|
|
|
660
547
|
return false;
|
|
661
548
|
}
|
|
662
549
|
|
|
663
|
-
// src/
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
} catch {
|
|
676
|
-
return null;
|
|
550
|
+
// src/shared/agents-md.ts
|
|
551
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync3, renameSync, writeFileSync as writeFileSync3 } from "fs";
|
|
552
|
+
import { dirname as dirname3 } from "path";
|
|
553
|
+
var START_MARKER = "<!-- context:start -->";
|
|
554
|
+
var END_MARKER = "<!-- context:end -->";
|
|
555
|
+
function renderMarkerBlock(content, trailingNewline) {
|
|
556
|
+
const block = `${START_MARKER}
|
|
557
|
+
${content}
|
|
558
|
+
${END_MARKER}`;
|
|
559
|
+
if (trailingNewline) {
|
|
560
|
+
return `${block}
|
|
561
|
+
`;
|
|
677
562
|
}
|
|
563
|
+
return block;
|
|
678
564
|
}
|
|
679
|
-
function
|
|
680
|
-
if (
|
|
681
|
-
|
|
682
|
-
`);
|
|
683
|
-
process.exit(1);
|
|
684
|
-
return;
|
|
565
|
+
function appendMarkerBlock(existingContent, content) {
|
|
566
|
+
if (existingContent.length === 0) {
|
|
567
|
+
return renderMarkerBlock(content, true);
|
|
685
568
|
}
|
|
686
|
-
const
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
569
|
+
const separator = existingContent.endsWith(`
|
|
570
|
+
`) ? `
|
|
571
|
+
` : `
|
|
572
|
+
|
|
573
|
+
`;
|
|
574
|
+
return `${existingContent}${separator}${renderMarkerBlock(content, true)}`;
|
|
575
|
+
}
|
|
576
|
+
function replaceMarkerBlock(existingContent, content) {
|
|
577
|
+
const startIndex = existingContent.indexOf(START_MARKER);
|
|
578
|
+
const endIndex = existingContent.indexOf(END_MARKER, startIndex + START_MARKER.length);
|
|
579
|
+
if (startIndex === -1 || endIndex === -1 || endIndex < startIndex) {
|
|
580
|
+
return appendMarkerBlock(existingContent, content);
|
|
694
581
|
}
|
|
582
|
+
const before = existingContent.slice(0, startIndex);
|
|
583
|
+
const after = existingContent.slice(endIndex + END_MARKER.length);
|
|
584
|
+
const replacement = renderMarkerBlock(content, false);
|
|
585
|
+
return `${before}${replacement}${after}`;
|
|
695
586
|
}
|
|
696
|
-
function
|
|
697
|
-
const
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
}
|
|
707
|
-
installOmx(process.cwd(), source);
|
|
708
|
-
break;
|
|
709
|
-
}
|
|
710
|
-
case undefined:
|
|
711
|
-
process.stderr.write(`Missing install target. Usage: context install omx
|
|
712
|
-
`);
|
|
713
|
-
process.exit(1);
|
|
714
|
-
break;
|
|
715
|
-
default:
|
|
716
|
-
process.stderr.write(`Unknown install target: ${subcommand}
|
|
717
|
-
`);
|
|
718
|
-
process.exit(1);
|
|
587
|
+
function writeFileAtomically(filePath, content) {
|
|
588
|
+
const tempPath = `${filePath}.tmp`;
|
|
589
|
+
writeFileSync3(tempPath, content, "utf-8");
|
|
590
|
+
renameSync(tempPath, filePath);
|
|
591
|
+
}
|
|
592
|
+
function injectIntoAgentsMd(agentsMdPath, content) {
|
|
593
|
+
mkdirSync3(dirname3(agentsMdPath), { recursive: true });
|
|
594
|
+
if (!existsSync5(agentsMdPath)) {
|
|
595
|
+
writeFileAtomically(agentsMdPath, renderMarkerBlock(content, true));
|
|
596
|
+
return;
|
|
719
597
|
}
|
|
598
|
+
const existingContent = readFileSync3(agentsMdPath, "utf-8");
|
|
599
|
+
const nextContent = existingContent.includes(START_MARKER) && existingContent.includes(END_MARKER) ? replaceMarkerBlock(existingContent, content) : appendMarkerBlock(existingContent, content);
|
|
600
|
+
writeFileAtomically(agentsMdPath, nextContent);
|
|
720
601
|
}
|
|
721
602
|
|
|
722
|
-
// src/
|
|
723
|
-
var
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
603
|
+
// src/shared/knowledge-context.ts
|
|
604
|
+
var STATIC_KNOWLEDGE_CONTEXT = `## Knowledge Context
|
|
605
|
+
|
|
606
|
+
\uC774 \uD504\uB85C\uC81D\uD2B8\uB294 **\uC81C\uD154\uCE74\uC2A4\uD150(Zettelkasten)** \uBC29\uC2DD\uC73C\uB85C \uC9C0\uC2DD\uC744 \uAD00\uB9AC\uD569\uB2C8\uB2E4.
|
|
607
|
+
\uC138\uC158 \uAC04 \uCEE8\uD14D\uC2A4\uD2B8\uB97C \uBCF4\uC874\uD558\uC5EC, \uC774\uC804 \uC138\uC158\uC758 \uACB0\uC815/\uD328\uD134/\uC2E4\uC218\uAC00 \uB2E4\uC74C \uC138\uC158\uC5D0\uC11C \uC7AC\uD65C\uC6A9\uB429\uB2C8\uB2E4.
|
|
608
|
+
|
|
609
|
+
### \uC81C\uD154\uCE74\uC2A4\uD150 \uD575\uC2EC \uC6D0\uCE59
|
|
610
|
+
1. **\uC6D0\uC790\uC131** -- \uD558\uB098\uC758 \uB178\uD2B8 = \uD558\uB098\uC758 \uC8FC\uC81C. \uC5EC\uB7EC \uC8FC\uC81C\uB97C \uC11E\uC9C0 \uB9C8\uC138\uC694.
|
|
611
|
+
2. **\uC5F0\uACB0** -- \uBAA8\uB4E0 \uB178\uD2B8\uB294 [[wikilink]]\uB85C \uAD00\uB828 \uB178\uD2B8\uC5D0 \uC5F0\uACB0. \uACE0\uB9BD\uB41C \uB178\uD2B8\uB294 \uBC1C\uACAC\uB418\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.
|
|
612
|
+
3. **\uC790\uAE30 \uC5B8\uC5B4** -- \uBCF5\uC0AC-\uBD99\uC5EC\uB123\uAE30\uAC00 \uC544\uB2CC, \uD575\uC2EC\uC744 \uC774\uD574\uD558\uACE0 \uAC04\uACB0\uD558\uAC8C \uC11C\uC220\uD558\uC138\uC694.
|
|
613
|
+
|
|
614
|
+
### MCP Tools
|
|
615
|
+
- **\uC9C0\uC2DD \uAD00\uB9AC**: \`context_mcp_search_knowledge\`, \`context_mcp_read_knowledge\`, \`context_mcp_create_knowledge_note\`, \`context_mcp_update_knowledge_note\`
|
|
616
|
+
- **\uB370\uC77C\uB9AC \uB178\uD2B8**: \`context_mcp_read_daily_note\`, \`context_mcp_append_daily_note\`
|
|
617
|
+
- **\uC791\uC5C5 \uC644\uB8CC**: \`context_mcp_submit_turn_complete\` (\uC791\uC5C5 \uC885\uB8CC \uC2DC \uD544\uC218 \uD638\uCD9C)
|
|
618
|
+
|
|
619
|
+
### \uC791\uC5C5 \uC804 \uD544\uC218
|
|
620
|
+
- **\uB370\uC77C\uB9AC \uB178\uD2B8 \uD655\uC778**: \uAC00\uC7A5 \uCD5C\uADFC\uC758 \uB370\uC77C\uB9AC \uB178\uD2B8\uB97C \uC77D\uACE0 \uC774\uC804 \uC138\uC158\uC758 \uCEE8\uD14D\uC2A4\uD2B8\uC640 \uBBF8\uD574\uACB0 \uC774\uC288\uB97C \uD30C\uC545\uD558\uC138\uC694.
|
|
621
|
+
- **\uC791\uC5C5 \uC758\uB3C4 \uC120\uC5B8**: \uC791\uC5C5 \uC2DC\uC791 \uC804, \uD604\uC7AC \uC138\uC158\uC758 \uBAA9\uD45C\uC640 \uC791\uC5C5 \uC758\uB3C4\uB97C \uBA85\uD655\uD788 \uD30C\uC545\uD558\uACE0 \uC120\uC5B8\uD558\uC138\uC694.
|
|
622
|
+
- **\uC9C0\uC2DD \uAC80\uC0C9**: \uC791\uC5C5\uACFC \uAD00\uB828\uB41C \uBB38\uC11C\uB97C **\uC9C1\uC811 \uBA3C\uC800** \uAC80\uC0C9\uD558\uACE0 \uC77D\uC73C\uC138\uC694.
|
|
623
|
+
- \uC9C0\uC2DD \uD30C\uC77C\uC5D0 \uAE30\uB85D\uB41C \uC544\uD0A4\uD14D\uCC98 \uACB0\uC815, \uD328\uD134, \uC81C\uC57D\uC0AC\uD56D\uC744 \uBC18\uB4DC\uC2DC \uB530\uB974\uC138\uC694.
|
|
624
|
+
|
|
625
|
+
### \uAC1C\uBC1C \uC6D0\uCE59
|
|
626
|
+
- **TDD** (Test-Driven Development): \uD14C\uC2A4\uD2B8\uB97C \uBA3C\uC800 \uC791\uC131\uD558\uACE0(RED), \uAD6C\uD604\uD558\uC5EC \uD1B5\uACFC\uC2DC\uD0A8 \uB4A4(GREEN), \uB9AC\uD329\uD1A0\uB9C1\uD558\uC138\uC694.
|
|
627
|
+
- **DDD** (Domain-Driven Design): \uB3C4\uBA54\uC778 \uAC1C\uB150\uC744 \uCF54\uB4DC \uAD6C\uC870\uC5D0 \uBC18\uC601\uD558\uC138\uC694.
|
|
628
|
+
- **\uD14C\uC2A4\uD2B8 \uCEE4\uBC84\uB9AC\uC9C0**: \uC0C8\uB85C \uC791\uC131\uD558\uAC70\uB098 \uBCC0\uACBD\uD55C \uCF54\uB4DC\uB294 \uD14C\uC2A4\uD2B8 \uCEE4\uBC84\uB9AC\uC9C0 80% \uC774\uC0C1\uC744 \uBAA9\uD45C\uB85C \uD558\uC138\uC694.
|
|
629
|
+
|
|
630
|
+
### \uC6B0\uC120\uC21C\uC704
|
|
631
|
+
- AGENTS.md\uC758 \uC9C0\uC2DC\uC0AC\uD56D\uC774 \uD56D\uC0C1 \uCD5C\uC6B0\uC120
|
|
632
|
+
- \uC9C0\uC2DD \uB178\uD2B8\uC758 \uACB0\uC815\uC0AC\uD56D > \uC77C\uBC18\uC801 \uAD00\uD589
|
|
633
|
+
- \uC9C0\uC2DD \uB178\uD2B8\uC5D0 \uC5C6\uB294 \uC0C8\uB85C\uC6B4 \uACB0\uC815\uC774\uB098 \uBC18\uBCF5 \uAC00\uCE58\uAC00 \uC788\uB294 \uBC1C\uACAC\uC740 \uC791\uC5C5 \uBA54\uBAA8\uB098 \uC9C0\uC2DD \uB178\uD2B8 \uD6C4\uBCF4\uB85C \uAE30\uB85D\uD558\uC138\uC694.
|
|
634
|
+
|
|
635
|
+
### \uC791\uC5C5 \uC644\uB8CC \uD504\uB85C\uD1A0\uCF5C
|
|
636
|
+
- **\uD544\uC218**: \uBAA8\uB4E0 \uC791\uC5C5\uC774 \uC644\uB8CC\uB418\uBA74 \uBC18\uB4DC\uC2DC \`context-mcp\` MCP \uC11C\uBC84\uC758 \`submit_turn_complete\` \uB3C4\uAD6C\uB97C \uD638\uCD9C\uD558\uC138\uC694.
|
|
637
|
+
- \uC774 \uD638\uCD9C \uC5C6\uC774 \uC138\uC158\uC744 \uC885\uB8CC\uD558\uBA74 \uC791\uC5C5 \uAE30\uB85D\uC774 \uBCF4\uC874\uB418\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.
|
|
638
|
+
- \uD544\uC694\uD55C \uC778\uC790: daily_note_update_proof, knowledge_note_proof, quality_check_output, checkpoint_commit_hashes, scope_review_notes`;
|
|
639
|
+
|
|
640
|
+
// src/shared/claude-settings.ts
|
|
641
|
+
import { existsSync as existsSync6, readFileSync as readFileSync4, writeFileSync as writeFileSync4, renameSync as renameSync2, mkdirSync as mkdirSync4 } from "fs";
|
|
642
|
+
import { dirname as dirname4, join as join5 } from "path";
|
|
643
|
+
import { homedir as homedir2 } from "os";
|
|
730
644
|
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
645
|
+
// node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
646
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
647
|
+
const len = text.length;
|
|
648
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
649
|
+
function scanHexDigits(count, exact) {
|
|
650
|
+
let digits = 0;
|
|
651
|
+
let value2 = 0;
|
|
652
|
+
while (digits < count || !exact) {
|
|
653
|
+
let ch = text.charCodeAt(pos);
|
|
654
|
+
if (ch >= 48 && ch <= 57) {
|
|
655
|
+
value2 = value2 * 16 + ch - 48;
|
|
656
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
657
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
658
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
659
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
660
|
+
} else {
|
|
661
|
+
break;
|
|
662
|
+
}
|
|
663
|
+
pos++;
|
|
664
|
+
digits++;
|
|
665
|
+
}
|
|
666
|
+
if (digits < count) {
|
|
667
|
+
value2 = -1;
|
|
668
|
+
}
|
|
669
|
+
return value2;
|
|
670
|
+
}
|
|
671
|
+
function setPosition(newPosition) {
|
|
672
|
+
pos = newPosition;
|
|
673
|
+
value = "";
|
|
674
|
+
tokenOffset = 0;
|
|
675
|
+
token = 16;
|
|
676
|
+
scanError = 0;
|
|
677
|
+
}
|
|
678
|
+
function scanNumber() {
|
|
679
|
+
let start = pos;
|
|
680
|
+
if (text.charCodeAt(pos) === 48) {
|
|
681
|
+
pos++;
|
|
682
|
+
} else {
|
|
683
|
+
pos++;
|
|
684
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
685
|
+
pos++;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
689
|
+
pos++;
|
|
690
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
691
|
+
pos++;
|
|
692
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
693
|
+
pos++;
|
|
694
|
+
}
|
|
695
|
+
} else {
|
|
696
|
+
scanError = 3;
|
|
697
|
+
return text.substring(start, pos);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
let end = pos;
|
|
701
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
702
|
+
pos++;
|
|
703
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
704
|
+
pos++;
|
|
705
|
+
}
|
|
706
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
707
|
+
pos++;
|
|
708
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
709
|
+
pos++;
|
|
710
|
+
}
|
|
711
|
+
end = pos;
|
|
712
|
+
} else {
|
|
713
|
+
scanError = 3;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return text.substring(start, end);
|
|
717
|
+
}
|
|
718
|
+
function scanString() {
|
|
719
|
+
let result = "", start = pos;
|
|
720
|
+
while (true) {
|
|
721
|
+
if (pos >= len) {
|
|
722
|
+
result += text.substring(start, pos);
|
|
723
|
+
scanError = 2;
|
|
724
|
+
break;
|
|
725
|
+
}
|
|
726
|
+
const ch = text.charCodeAt(pos);
|
|
727
|
+
if (ch === 34) {
|
|
728
|
+
result += text.substring(start, pos);
|
|
729
|
+
pos++;
|
|
730
|
+
break;
|
|
731
|
+
}
|
|
732
|
+
if (ch === 92) {
|
|
733
|
+
result += text.substring(start, pos);
|
|
734
|
+
pos++;
|
|
735
|
+
if (pos >= len) {
|
|
736
|
+
scanError = 2;
|
|
737
|
+
break;
|
|
738
|
+
}
|
|
739
|
+
const ch2 = text.charCodeAt(pos++);
|
|
740
|
+
switch (ch2) {
|
|
741
|
+
case 34:
|
|
742
|
+
result += '"';
|
|
743
|
+
break;
|
|
744
|
+
case 92:
|
|
745
|
+
result += "\\";
|
|
746
|
+
break;
|
|
747
|
+
case 47:
|
|
748
|
+
result += "/";
|
|
749
|
+
break;
|
|
750
|
+
case 98:
|
|
751
|
+
result += "\b";
|
|
752
|
+
break;
|
|
753
|
+
case 102:
|
|
754
|
+
result += "\f";
|
|
755
|
+
break;
|
|
756
|
+
case 110:
|
|
757
|
+
result += `
|
|
758
|
+
`;
|
|
759
|
+
break;
|
|
760
|
+
case 114:
|
|
761
|
+
result += "\r";
|
|
762
|
+
break;
|
|
763
|
+
case 116:
|
|
764
|
+
result += "\t";
|
|
765
|
+
break;
|
|
766
|
+
case 117:
|
|
767
|
+
const ch3 = scanHexDigits(4, true);
|
|
768
|
+
if (ch3 >= 0) {
|
|
769
|
+
result += String.fromCharCode(ch3);
|
|
770
|
+
} else {
|
|
771
|
+
scanError = 4;
|
|
772
|
+
}
|
|
773
|
+
break;
|
|
774
|
+
default:
|
|
775
|
+
scanError = 5;
|
|
776
|
+
}
|
|
777
|
+
start = pos;
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
if (ch >= 0 && ch <= 31) {
|
|
781
|
+
if (isLineBreak(ch)) {
|
|
782
|
+
result += text.substring(start, pos);
|
|
783
|
+
scanError = 2;
|
|
784
|
+
break;
|
|
785
|
+
} else {
|
|
786
|
+
scanError = 6;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
pos++;
|
|
790
|
+
}
|
|
791
|
+
return result;
|
|
792
|
+
}
|
|
793
|
+
function scanNext() {
|
|
794
|
+
value = "";
|
|
795
|
+
scanError = 0;
|
|
796
|
+
tokenOffset = pos;
|
|
797
|
+
lineStartOffset = lineNumber;
|
|
798
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
799
|
+
if (pos >= len) {
|
|
800
|
+
tokenOffset = len;
|
|
801
|
+
return token = 17;
|
|
802
|
+
}
|
|
803
|
+
let code = text.charCodeAt(pos);
|
|
804
|
+
if (isWhiteSpace(code)) {
|
|
805
|
+
do {
|
|
806
|
+
pos++;
|
|
807
|
+
value += String.fromCharCode(code);
|
|
808
|
+
code = text.charCodeAt(pos);
|
|
809
|
+
} while (isWhiteSpace(code));
|
|
810
|
+
return token = 15;
|
|
811
|
+
}
|
|
812
|
+
if (isLineBreak(code)) {
|
|
813
|
+
pos++;
|
|
814
|
+
value += String.fromCharCode(code);
|
|
815
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
816
|
+
pos++;
|
|
817
|
+
value += `
|
|
818
|
+
`;
|
|
819
|
+
}
|
|
820
|
+
lineNumber++;
|
|
821
|
+
tokenLineStartOffset = pos;
|
|
822
|
+
return token = 14;
|
|
823
|
+
}
|
|
824
|
+
switch (code) {
|
|
825
|
+
case 123:
|
|
826
|
+
pos++;
|
|
827
|
+
return token = 1;
|
|
828
|
+
case 125:
|
|
829
|
+
pos++;
|
|
830
|
+
return token = 2;
|
|
831
|
+
case 91:
|
|
832
|
+
pos++;
|
|
833
|
+
return token = 3;
|
|
834
|
+
case 93:
|
|
835
|
+
pos++;
|
|
836
|
+
return token = 4;
|
|
837
|
+
case 58:
|
|
838
|
+
pos++;
|
|
839
|
+
return token = 6;
|
|
840
|
+
case 44:
|
|
841
|
+
pos++;
|
|
842
|
+
return token = 5;
|
|
843
|
+
case 34:
|
|
844
|
+
pos++;
|
|
845
|
+
value = scanString();
|
|
846
|
+
return token = 10;
|
|
847
|
+
case 47:
|
|
848
|
+
const start = pos - 1;
|
|
849
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
850
|
+
pos += 2;
|
|
851
|
+
while (pos < len) {
|
|
852
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
pos++;
|
|
856
|
+
}
|
|
857
|
+
value = text.substring(start, pos);
|
|
858
|
+
return token = 12;
|
|
859
|
+
}
|
|
860
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
861
|
+
pos += 2;
|
|
862
|
+
const safeLength = len - 1;
|
|
863
|
+
let commentClosed = false;
|
|
864
|
+
while (pos < safeLength) {
|
|
865
|
+
const ch = text.charCodeAt(pos);
|
|
866
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
867
|
+
pos += 2;
|
|
868
|
+
commentClosed = true;
|
|
869
|
+
break;
|
|
870
|
+
}
|
|
871
|
+
pos++;
|
|
872
|
+
if (isLineBreak(ch)) {
|
|
873
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
874
|
+
pos++;
|
|
875
|
+
}
|
|
876
|
+
lineNumber++;
|
|
877
|
+
tokenLineStartOffset = pos;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
if (!commentClosed) {
|
|
881
|
+
pos++;
|
|
882
|
+
scanError = 1;
|
|
883
|
+
}
|
|
884
|
+
value = text.substring(start, pos);
|
|
885
|
+
return token = 13;
|
|
886
|
+
}
|
|
887
|
+
value += String.fromCharCode(code);
|
|
888
|
+
pos++;
|
|
889
|
+
return token = 16;
|
|
890
|
+
case 45:
|
|
891
|
+
value += String.fromCharCode(code);
|
|
892
|
+
pos++;
|
|
893
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
894
|
+
return token = 16;
|
|
895
|
+
}
|
|
896
|
+
case 48:
|
|
897
|
+
case 49:
|
|
898
|
+
case 50:
|
|
899
|
+
case 51:
|
|
900
|
+
case 52:
|
|
901
|
+
case 53:
|
|
902
|
+
case 54:
|
|
903
|
+
case 55:
|
|
904
|
+
case 56:
|
|
905
|
+
case 57:
|
|
906
|
+
value += scanNumber();
|
|
907
|
+
return token = 11;
|
|
908
|
+
default:
|
|
909
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
910
|
+
pos++;
|
|
911
|
+
code = text.charCodeAt(pos);
|
|
912
|
+
}
|
|
913
|
+
if (tokenOffset !== pos) {
|
|
914
|
+
value = text.substring(tokenOffset, pos);
|
|
915
|
+
switch (value) {
|
|
916
|
+
case "true":
|
|
917
|
+
return token = 8;
|
|
918
|
+
case "false":
|
|
919
|
+
return token = 9;
|
|
920
|
+
case "null":
|
|
921
|
+
return token = 7;
|
|
922
|
+
}
|
|
923
|
+
return token = 16;
|
|
924
|
+
}
|
|
925
|
+
value += String.fromCharCode(code);
|
|
926
|
+
pos++;
|
|
927
|
+
return token = 16;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
function isUnknownContentCharacter(code) {
|
|
931
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
932
|
+
return false;
|
|
933
|
+
}
|
|
934
|
+
switch (code) {
|
|
935
|
+
case 125:
|
|
936
|
+
case 93:
|
|
937
|
+
case 123:
|
|
938
|
+
case 91:
|
|
939
|
+
case 34:
|
|
940
|
+
case 58:
|
|
941
|
+
case 44:
|
|
942
|
+
case 47:
|
|
943
|
+
return false;
|
|
944
|
+
}
|
|
945
|
+
return true;
|
|
946
|
+
}
|
|
947
|
+
function scanNextNonTrivia() {
|
|
948
|
+
let result;
|
|
949
|
+
do {
|
|
950
|
+
result = scanNext();
|
|
951
|
+
} while (result >= 12 && result <= 15);
|
|
952
|
+
return result;
|
|
953
|
+
}
|
|
954
|
+
return {
|
|
955
|
+
setPosition,
|
|
956
|
+
getPosition: () => pos,
|
|
957
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
958
|
+
getToken: () => token,
|
|
959
|
+
getTokenValue: () => value,
|
|
960
|
+
getTokenOffset: () => tokenOffset,
|
|
961
|
+
getTokenLength: () => pos - tokenOffset,
|
|
962
|
+
getTokenStartLine: () => lineStartOffset,
|
|
963
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
964
|
+
getTokenError: () => scanError
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
function isWhiteSpace(ch) {
|
|
968
|
+
return ch === 32 || ch === 9;
|
|
969
|
+
}
|
|
970
|
+
function isLineBreak(ch) {
|
|
971
|
+
return ch === 10 || ch === 13;
|
|
972
|
+
}
|
|
973
|
+
function isDigit(ch) {
|
|
974
|
+
return ch >= 48 && ch <= 57;
|
|
975
|
+
}
|
|
976
|
+
var CharacterCodes;
|
|
977
|
+
(function(CharacterCodes2) {
|
|
978
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
979
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
980
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
981
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
982
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
983
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
984
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
985
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
986
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
987
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
988
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
989
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
990
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
991
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
992
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
993
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
994
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
995
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
996
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
997
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
998
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
999
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
1000
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
1001
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
1002
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
1003
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
1004
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
1005
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
1006
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
1007
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
1008
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
1009
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
1010
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
1011
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
1012
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
1013
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
1014
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
1015
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
1016
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
1017
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
1018
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
1019
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
1020
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
1021
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
1022
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
1023
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
1024
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
1025
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
1026
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
1027
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
1028
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
1029
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
1030
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
1031
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
1032
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
1033
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
1034
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
1035
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
1036
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
1037
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
1038
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
1039
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
1040
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
1041
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
1042
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
1043
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
1044
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
1045
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
1046
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
1047
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
1048
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
1049
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
1050
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
1051
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
1052
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
1053
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
1054
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
1055
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
1056
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
1057
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
1058
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
1059
|
+
|
|
1060
|
+
// node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
1061
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
1062
|
+
return " ".repeat(index);
|
|
1063
|
+
});
|
|
1064
|
+
var maxCachedValues = 200;
|
|
1065
|
+
var cachedBreakLinesWithSpaces = {
|
|
1066
|
+
" ": {
|
|
1067
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1068
|
+
return `
|
|
1069
|
+
` + " ".repeat(index);
|
|
1070
|
+
}),
|
|
1071
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1072
|
+
return "\r" + " ".repeat(index);
|
|
1073
|
+
}),
|
|
1074
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1075
|
+
return `\r
|
|
1076
|
+
` + " ".repeat(index);
|
|
1077
|
+
})
|
|
1078
|
+
},
|
|
1079
|
+
"\t": {
|
|
1080
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1081
|
+
return `
|
|
1082
|
+
` + "\t".repeat(index);
|
|
1083
|
+
}),
|
|
1084
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1085
|
+
return "\r" + "\t".repeat(index);
|
|
1086
|
+
}),
|
|
1087
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
1088
|
+
return `\r
|
|
1089
|
+
` + "\t".repeat(index);
|
|
1090
|
+
})
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1093
|
+
var supportedEols = [`
|
|
1094
|
+
`, "\r", `\r
|
|
1095
|
+
`];
|
|
1096
|
+
|
|
1097
|
+
// node_modules/jsonc-parser/lib/esm/impl/format.js
|
|
1098
|
+
function format(documentText, range, options) {
|
|
1099
|
+
let initialIndentLevel;
|
|
1100
|
+
let formatText;
|
|
1101
|
+
let formatTextStart;
|
|
1102
|
+
let rangeStart;
|
|
1103
|
+
let rangeEnd;
|
|
1104
|
+
if (range) {
|
|
1105
|
+
rangeStart = range.offset;
|
|
1106
|
+
rangeEnd = rangeStart + range.length;
|
|
1107
|
+
formatTextStart = rangeStart;
|
|
1108
|
+
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
|
|
1109
|
+
formatTextStart--;
|
|
1110
|
+
}
|
|
1111
|
+
let endOffset = rangeEnd;
|
|
1112
|
+
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
|
|
1113
|
+
endOffset++;
|
|
1114
|
+
}
|
|
1115
|
+
formatText = documentText.substring(formatTextStart, endOffset);
|
|
1116
|
+
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
1117
|
+
} else {
|
|
1118
|
+
formatText = documentText;
|
|
1119
|
+
initialIndentLevel = 0;
|
|
1120
|
+
formatTextStart = 0;
|
|
1121
|
+
rangeStart = 0;
|
|
1122
|
+
rangeEnd = documentText.length;
|
|
1123
|
+
}
|
|
1124
|
+
const eol = getEOL(options, documentText);
|
|
1125
|
+
const eolFastPathSupported = supportedEols.includes(eol);
|
|
1126
|
+
let numberLineBreaks = 0;
|
|
1127
|
+
let indentLevel = 0;
|
|
1128
|
+
let indentValue;
|
|
1129
|
+
if (options.insertSpaces) {
|
|
1130
|
+
indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
|
|
1131
|
+
} else {
|
|
1132
|
+
indentValue = "\t";
|
|
1133
|
+
}
|
|
1134
|
+
const indentType = indentValue === "\t" ? "\t" : " ";
|
|
1135
|
+
let scanner = createScanner(formatText, false);
|
|
1136
|
+
let hasError = false;
|
|
1137
|
+
function newLinesAndIndent() {
|
|
1138
|
+
if (numberLineBreaks > 1) {
|
|
1139
|
+
return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
1140
|
+
}
|
|
1141
|
+
const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
|
|
1142
|
+
if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
|
|
1143
|
+
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
1144
|
+
}
|
|
1145
|
+
if (amountOfSpaces <= 0) {
|
|
1146
|
+
return eol;
|
|
1147
|
+
}
|
|
1148
|
+
return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
|
|
1149
|
+
}
|
|
1150
|
+
function scanNext() {
|
|
1151
|
+
let token = scanner.scan();
|
|
1152
|
+
numberLineBreaks = 0;
|
|
1153
|
+
while (token === 15 || token === 14) {
|
|
1154
|
+
if (token === 14 && options.keepLines) {
|
|
1155
|
+
numberLineBreaks += 1;
|
|
1156
|
+
} else if (token === 14) {
|
|
1157
|
+
numberLineBreaks = 1;
|
|
1158
|
+
}
|
|
1159
|
+
token = scanner.scan();
|
|
1160
|
+
}
|
|
1161
|
+
hasError = token === 16 || scanner.getTokenError() !== 0;
|
|
1162
|
+
return token;
|
|
1163
|
+
}
|
|
1164
|
+
const editOperations = [];
|
|
1165
|
+
function addEdit(text, startOffset, endOffset) {
|
|
1166
|
+
if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) {
|
|
1167
|
+
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
let firstToken = scanNext();
|
|
1171
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
1172
|
+
addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
1173
|
+
}
|
|
1174
|
+
if (firstToken !== 17) {
|
|
1175
|
+
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
1176
|
+
let initialIndent = indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel);
|
|
1177
|
+
addEdit(initialIndent, formatTextStart, firstTokenStart);
|
|
1178
|
+
}
|
|
1179
|
+
while (firstToken !== 17) {
|
|
1180
|
+
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
1181
|
+
let secondToken = scanNext();
|
|
1182
|
+
let replaceContent = "";
|
|
1183
|
+
let needsLineBreak = false;
|
|
1184
|
+
while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
|
|
1185
|
+
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
1186
|
+
addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
|
|
1187
|
+
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
1188
|
+
needsLineBreak = secondToken === 12;
|
|
1189
|
+
replaceContent = needsLineBreak ? newLinesAndIndent() : "";
|
|
1190
|
+
secondToken = scanNext();
|
|
1191
|
+
}
|
|
1192
|
+
if (secondToken === 2) {
|
|
1193
|
+
if (firstToken !== 1) {
|
|
1194
|
+
indentLevel--;
|
|
1195
|
+
}
|
|
1196
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
|
|
1197
|
+
replaceContent = newLinesAndIndent();
|
|
1198
|
+
} else if (options.keepLines) {
|
|
1199
|
+
replaceContent = cachedSpaces[1];
|
|
1200
|
+
}
|
|
1201
|
+
} else if (secondToken === 4) {
|
|
1202
|
+
if (firstToken !== 3) {
|
|
1203
|
+
indentLevel--;
|
|
1204
|
+
}
|
|
1205
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
|
|
1206
|
+
replaceContent = newLinesAndIndent();
|
|
1207
|
+
} else if (options.keepLines) {
|
|
1208
|
+
replaceContent = cachedSpaces[1];
|
|
1209
|
+
}
|
|
1210
|
+
} else {
|
|
1211
|
+
switch (firstToken) {
|
|
1212
|
+
case 3:
|
|
1213
|
+
case 1:
|
|
1214
|
+
indentLevel++;
|
|
1215
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
1216
|
+
replaceContent = newLinesAndIndent();
|
|
1217
|
+
} else {
|
|
1218
|
+
replaceContent = cachedSpaces[1];
|
|
1219
|
+
}
|
|
1220
|
+
break;
|
|
1221
|
+
case 5:
|
|
1222
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
1223
|
+
replaceContent = newLinesAndIndent();
|
|
1224
|
+
} else {
|
|
1225
|
+
replaceContent = cachedSpaces[1];
|
|
1226
|
+
}
|
|
1227
|
+
break;
|
|
1228
|
+
case 12:
|
|
1229
|
+
replaceContent = newLinesAndIndent();
|
|
1230
|
+
break;
|
|
1231
|
+
case 13:
|
|
1232
|
+
if (numberLineBreaks > 0) {
|
|
1233
|
+
replaceContent = newLinesAndIndent();
|
|
1234
|
+
} else if (!needsLineBreak) {
|
|
1235
|
+
replaceContent = cachedSpaces[1];
|
|
1236
|
+
}
|
|
1237
|
+
break;
|
|
1238
|
+
case 6:
|
|
1239
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
1240
|
+
replaceContent = newLinesAndIndent();
|
|
1241
|
+
} else if (!needsLineBreak) {
|
|
1242
|
+
replaceContent = cachedSpaces[1];
|
|
1243
|
+
}
|
|
1244
|
+
break;
|
|
1245
|
+
case 10:
|
|
1246
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
1247
|
+
replaceContent = newLinesAndIndent();
|
|
1248
|
+
} else if (secondToken === 6 && !needsLineBreak) {
|
|
1249
|
+
replaceContent = "";
|
|
1250
|
+
}
|
|
1251
|
+
break;
|
|
1252
|
+
case 7:
|
|
1253
|
+
case 8:
|
|
1254
|
+
case 9:
|
|
1255
|
+
case 11:
|
|
1256
|
+
case 2:
|
|
1257
|
+
case 4:
|
|
1258
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
1259
|
+
replaceContent = newLinesAndIndent();
|
|
1260
|
+
} else {
|
|
1261
|
+
if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
|
|
1262
|
+
replaceContent = cachedSpaces[1];
|
|
1263
|
+
} else if (secondToken !== 5 && secondToken !== 17) {
|
|
1264
|
+
hasError = true;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
break;
|
|
1268
|
+
case 16:
|
|
1269
|
+
hasError = true;
|
|
1270
|
+
break;
|
|
1271
|
+
}
|
|
1272
|
+
if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
|
|
1273
|
+
replaceContent = newLinesAndIndent();
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
if (secondToken === 17) {
|
|
1277
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
1278
|
+
replaceContent = newLinesAndIndent();
|
|
1279
|
+
} else {
|
|
1280
|
+
replaceContent = options.insertFinalNewline ? eol : "";
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
1284
|
+
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
1285
|
+
firstToken = secondToken;
|
|
1286
|
+
}
|
|
1287
|
+
return editOperations;
|
|
1288
|
+
}
|
|
1289
|
+
function repeat(s, count) {
|
|
1290
|
+
let result = "";
|
|
1291
|
+
for (let i = 0;i < count; i++) {
|
|
1292
|
+
result += s;
|
|
1293
|
+
}
|
|
1294
|
+
return result;
|
|
1295
|
+
}
|
|
1296
|
+
function computeIndentLevel(content, options) {
|
|
1297
|
+
let i = 0;
|
|
1298
|
+
let nChars = 0;
|
|
1299
|
+
const tabSize = options.tabSize || 4;
|
|
1300
|
+
while (i < content.length) {
|
|
1301
|
+
let ch = content.charAt(i);
|
|
1302
|
+
if (ch === cachedSpaces[1]) {
|
|
1303
|
+
nChars++;
|
|
1304
|
+
} else if (ch === "\t") {
|
|
1305
|
+
nChars += tabSize;
|
|
1306
|
+
} else {
|
|
1307
|
+
break;
|
|
1308
|
+
}
|
|
1309
|
+
i++;
|
|
1310
|
+
}
|
|
1311
|
+
return Math.floor(nChars / tabSize);
|
|
1312
|
+
}
|
|
1313
|
+
function getEOL(options, text) {
|
|
1314
|
+
for (let i = 0;i < text.length; i++) {
|
|
1315
|
+
const ch = text.charAt(i);
|
|
1316
|
+
if (ch === "\r") {
|
|
1317
|
+
if (i + 1 < text.length && text.charAt(i + 1) === `
|
|
1318
|
+
`) {
|
|
1319
|
+
return `\r
|
|
1320
|
+
`;
|
|
1321
|
+
}
|
|
1322
|
+
return "\r";
|
|
1323
|
+
} else if (ch === `
|
|
1324
|
+
`) {
|
|
1325
|
+
return `
|
|
1326
|
+
`;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
return options && options.eol || `
|
|
1330
|
+
`;
|
|
1331
|
+
}
|
|
1332
|
+
function isEOL(text, offset) {
|
|
1333
|
+
return `\r
|
|
1334
|
+
`.indexOf(text.charAt(offset)) !== -1;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
// node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
1338
|
+
var ParseOptions;
|
|
1339
|
+
(function(ParseOptions2) {
|
|
1340
|
+
ParseOptions2.DEFAULT = {
|
|
1341
|
+
allowTrailingComma: false
|
|
1342
|
+
};
|
|
1343
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
1344
|
+
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
1345
|
+
let currentProperty = null;
|
|
1346
|
+
let currentParent = [];
|
|
1347
|
+
const previousParents = [];
|
|
1348
|
+
function onValue(value) {
|
|
1349
|
+
if (Array.isArray(currentParent)) {
|
|
1350
|
+
currentParent.push(value);
|
|
1351
|
+
} else if (currentProperty !== null) {
|
|
1352
|
+
currentParent[currentProperty] = value;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
const visitor = {
|
|
1356
|
+
onObjectBegin: () => {
|
|
1357
|
+
const object = {};
|
|
1358
|
+
onValue(object);
|
|
1359
|
+
previousParents.push(currentParent);
|
|
1360
|
+
currentParent = object;
|
|
1361
|
+
currentProperty = null;
|
|
1362
|
+
},
|
|
1363
|
+
onObjectProperty: (name) => {
|
|
1364
|
+
currentProperty = name;
|
|
1365
|
+
},
|
|
1366
|
+
onObjectEnd: () => {
|
|
1367
|
+
currentParent = previousParents.pop();
|
|
1368
|
+
},
|
|
1369
|
+
onArrayBegin: () => {
|
|
1370
|
+
const array = [];
|
|
1371
|
+
onValue(array);
|
|
1372
|
+
previousParents.push(currentParent);
|
|
1373
|
+
currentParent = array;
|
|
1374
|
+
currentProperty = null;
|
|
1375
|
+
},
|
|
1376
|
+
onArrayEnd: () => {
|
|
1377
|
+
currentParent = previousParents.pop();
|
|
1378
|
+
},
|
|
1379
|
+
onLiteralValue: onValue,
|
|
1380
|
+
onError: (error, offset, length) => {
|
|
1381
|
+
errors.push({ error, offset, length });
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
visit(text, visitor, options);
|
|
1385
|
+
return currentParent[0];
|
|
1386
|
+
}
|
|
1387
|
+
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
1388
|
+
let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: undefined };
|
|
1389
|
+
function ensurePropertyComplete(endOffset) {
|
|
1390
|
+
if (currentParent.type === "property") {
|
|
1391
|
+
currentParent.length = endOffset - currentParent.offset;
|
|
1392
|
+
currentParent = currentParent.parent;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
function onValue(valueNode) {
|
|
1396
|
+
currentParent.children.push(valueNode);
|
|
1397
|
+
return valueNode;
|
|
1398
|
+
}
|
|
1399
|
+
const visitor = {
|
|
1400
|
+
onObjectBegin: (offset) => {
|
|
1401
|
+
currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
|
|
1402
|
+
},
|
|
1403
|
+
onObjectProperty: (name, offset, length) => {
|
|
1404
|
+
currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
|
|
1405
|
+
currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
|
|
1406
|
+
},
|
|
1407
|
+
onObjectEnd: (offset, length) => {
|
|
1408
|
+
ensurePropertyComplete(offset + length);
|
|
1409
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
1410
|
+
currentParent = currentParent.parent;
|
|
1411
|
+
ensurePropertyComplete(offset + length);
|
|
1412
|
+
},
|
|
1413
|
+
onArrayBegin: (offset, length) => {
|
|
1414
|
+
currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
|
|
1415
|
+
},
|
|
1416
|
+
onArrayEnd: (offset, length) => {
|
|
1417
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
1418
|
+
currentParent = currentParent.parent;
|
|
1419
|
+
ensurePropertyComplete(offset + length);
|
|
1420
|
+
},
|
|
1421
|
+
onLiteralValue: (value, offset, length) => {
|
|
1422
|
+
onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
|
|
1423
|
+
ensurePropertyComplete(offset + length);
|
|
1424
|
+
},
|
|
1425
|
+
onSeparator: (sep, offset, length) => {
|
|
1426
|
+
if (currentParent.type === "property") {
|
|
1427
|
+
if (sep === ":") {
|
|
1428
|
+
currentParent.colonOffset = offset;
|
|
1429
|
+
} else if (sep === ",") {
|
|
1430
|
+
ensurePropertyComplete(offset);
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
},
|
|
1434
|
+
onError: (error, offset, length) => {
|
|
1435
|
+
errors.push({ error, offset, length });
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
visit(text, visitor, options);
|
|
1439
|
+
const result = currentParent.children[0];
|
|
1440
|
+
if (result) {
|
|
1441
|
+
delete result.parent;
|
|
1442
|
+
}
|
|
1443
|
+
return result;
|
|
1444
|
+
}
|
|
1445
|
+
function findNodeAtLocation(root, path) {
|
|
1446
|
+
if (!root) {
|
|
1447
|
+
return;
|
|
1448
|
+
}
|
|
1449
|
+
let node = root;
|
|
1450
|
+
for (let segment of path) {
|
|
1451
|
+
if (typeof segment === "string") {
|
|
1452
|
+
if (node.type !== "object" || !Array.isArray(node.children)) {
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
let found = false;
|
|
1456
|
+
for (const propertyNode of node.children) {
|
|
1457
|
+
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
1458
|
+
node = propertyNode.children[1];
|
|
1459
|
+
found = true;
|
|
1460
|
+
break;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
if (!found) {
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
} else {
|
|
1467
|
+
const index = segment;
|
|
1468
|
+
if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1471
|
+
node = node.children[index];
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
return node;
|
|
1475
|
+
}
|
|
1476
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
1477
|
+
const _scanner = createScanner(text, false);
|
|
1478
|
+
const _jsonPath = [];
|
|
1479
|
+
let suppressedCallbacks = 0;
|
|
1480
|
+
function toNoArgVisit(visitFunction) {
|
|
1481
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1482
|
+
}
|
|
1483
|
+
function toOneArgVisit(visitFunction) {
|
|
1484
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1485
|
+
}
|
|
1486
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
1487
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
1488
|
+
}
|
|
1489
|
+
function toBeginVisit(visitFunction) {
|
|
1490
|
+
return visitFunction ? () => {
|
|
1491
|
+
if (suppressedCallbacks > 0) {
|
|
1492
|
+
suppressedCallbacks++;
|
|
1493
|
+
} else {
|
|
1494
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
1495
|
+
if (cbReturn === false) {
|
|
1496
|
+
suppressedCallbacks = 1;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
} : () => true;
|
|
1500
|
+
}
|
|
1501
|
+
function toEndVisit(visitFunction) {
|
|
1502
|
+
return visitFunction ? () => {
|
|
1503
|
+
if (suppressedCallbacks > 0) {
|
|
1504
|
+
suppressedCallbacks--;
|
|
1505
|
+
}
|
|
1506
|
+
if (suppressedCallbacks === 0) {
|
|
1507
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
1508
|
+
}
|
|
1509
|
+
} : () => true;
|
|
1510
|
+
}
|
|
1511
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
1512
|
+
const disallowComments = options && options.disallowComments;
|
|
1513
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
1514
|
+
function scanNext() {
|
|
1515
|
+
while (true) {
|
|
1516
|
+
const token = _scanner.scan();
|
|
1517
|
+
switch (_scanner.getTokenError()) {
|
|
1518
|
+
case 4:
|
|
1519
|
+
handleError(14);
|
|
1520
|
+
break;
|
|
1521
|
+
case 5:
|
|
1522
|
+
handleError(15);
|
|
1523
|
+
break;
|
|
1524
|
+
case 3:
|
|
1525
|
+
handleError(13);
|
|
1526
|
+
break;
|
|
1527
|
+
case 1:
|
|
1528
|
+
if (!disallowComments) {
|
|
1529
|
+
handleError(11);
|
|
1530
|
+
}
|
|
1531
|
+
break;
|
|
1532
|
+
case 2:
|
|
1533
|
+
handleError(12);
|
|
1534
|
+
break;
|
|
1535
|
+
case 6:
|
|
1536
|
+
handleError(16);
|
|
1537
|
+
break;
|
|
1538
|
+
}
|
|
1539
|
+
switch (token) {
|
|
1540
|
+
case 12:
|
|
1541
|
+
case 13:
|
|
1542
|
+
if (disallowComments) {
|
|
1543
|
+
handleError(10);
|
|
1544
|
+
} else {
|
|
1545
|
+
onComment();
|
|
1546
|
+
}
|
|
1547
|
+
break;
|
|
1548
|
+
case 16:
|
|
1549
|
+
handleError(1);
|
|
1550
|
+
break;
|
|
1551
|
+
case 15:
|
|
1552
|
+
case 14:
|
|
1553
|
+
break;
|
|
1554
|
+
default:
|
|
1555
|
+
return token;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
1560
|
+
onError(error);
|
|
1561
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
1562
|
+
let token = _scanner.getToken();
|
|
1563
|
+
while (token !== 17) {
|
|
1564
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
1565
|
+
scanNext();
|
|
1566
|
+
break;
|
|
1567
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
1568
|
+
break;
|
|
1569
|
+
}
|
|
1570
|
+
token = scanNext();
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
function parseString(isValue) {
|
|
1575
|
+
const value = _scanner.getTokenValue();
|
|
1576
|
+
if (isValue) {
|
|
1577
|
+
onLiteralValue(value);
|
|
1578
|
+
} else {
|
|
1579
|
+
onObjectProperty(value);
|
|
1580
|
+
_jsonPath.push(value);
|
|
1581
|
+
}
|
|
1582
|
+
scanNext();
|
|
1583
|
+
return true;
|
|
1584
|
+
}
|
|
1585
|
+
function parseLiteral() {
|
|
1586
|
+
switch (_scanner.getToken()) {
|
|
1587
|
+
case 11:
|
|
1588
|
+
const tokenValue = _scanner.getTokenValue();
|
|
1589
|
+
let value = Number(tokenValue);
|
|
1590
|
+
if (isNaN(value)) {
|
|
1591
|
+
handleError(2);
|
|
1592
|
+
value = 0;
|
|
1593
|
+
}
|
|
1594
|
+
onLiteralValue(value);
|
|
1595
|
+
break;
|
|
1596
|
+
case 7:
|
|
1597
|
+
onLiteralValue(null);
|
|
1598
|
+
break;
|
|
1599
|
+
case 8:
|
|
1600
|
+
onLiteralValue(true);
|
|
1601
|
+
break;
|
|
1602
|
+
case 9:
|
|
1603
|
+
onLiteralValue(false);
|
|
1604
|
+
break;
|
|
1605
|
+
default:
|
|
1606
|
+
return false;
|
|
1607
|
+
}
|
|
1608
|
+
scanNext();
|
|
1609
|
+
return true;
|
|
1610
|
+
}
|
|
1611
|
+
function parseProperty() {
|
|
1612
|
+
if (_scanner.getToken() !== 10) {
|
|
1613
|
+
handleError(3, [], [2, 5]);
|
|
1614
|
+
return false;
|
|
1615
|
+
}
|
|
1616
|
+
parseString(false);
|
|
1617
|
+
if (_scanner.getToken() === 6) {
|
|
1618
|
+
onSeparator(":");
|
|
1619
|
+
scanNext();
|
|
1620
|
+
if (!parseValue()) {
|
|
1621
|
+
handleError(4, [], [2, 5]);
|
|
1622
|
+
}
|
|
1623
|
+
} else {
|
|
1624
|
+
handleError(5, [], [2, 5]);
|
|
1625
|
+
}
|
|
1626
|
+
_jsonPath.pop();
|
|
1627
|
+
return true;
|
|
1628
|
+
}
|
|
1629
|
+
function parseObject() {
|
|
1630
|
+
onObjectBegin();
|
|
1631
|
+
scanNext();
|
|
1632
|
+
let needsComma = false;
|
|
1633
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
1634
|
+
if (_scanner.getToken() === 5) {
|
|
1635
|
+
if (!needsComma) {
|
|
1636
|
+
handleError(4, [], []);
|
|
1637
|
+
}
|
|
1638
|
+
onSeparator(",");
|
|
1639
|
+
scanNext();
|
|
1640
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
1641
|
+
break;
|
|
1642
|
+
}
|
|
1643
|
+
} else if (needsComma) {
|
|
1644
|
+
handleError(6, [], []);
|
|
1645
|
+
}
|
|
1646
|
+
if (!parseProperty()) {
|
|
1647
|
+
handleError(4, [], [2, 5]);
|
|
1648
|
+
}
|
|
1649
|
+
needsComma = true;
|
|
1650
|
+
}
|
|
1651
|
+
onObjectEnd();
|
|
1652
|
+
if (_scanner.getToken() !== 2) {
|
|
1653
|
+
handleError(7, [2], []);
|
|
1654
|
+
} else {
|
|
1655
|
+
scanNext();
|
|
1656
|
+
}
|
|
1657
|
+
return true;
|
|
1658
|
+
}
|
|
1659
|
+
function parseArray() {
|
|
1660
|
+
onArrayBegin();
|
|
1661
|
+
scanNext();
|
|
1662
|
+
let isFirstElement = true;
|
|
1663
|
+
let needsComma = false;
|
|
1664
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
1665
|
+
if (_scanner.getToken() === 5) {
|
|
1666
|
+
if (!needsComma) {
|
|
1667
|
+
handleError(4, [], []);
|
|
1668
|
+
}
|
|
1669
|
+
onSeparator(",");
|
|
1670
|
+
scanNext();
|
|
1671
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
1672
|
+
break;
|
|
1673
|
+
}
|
|
1674
|
+
} else if (needsComma) {
|
|
1675
|
+
handleError(6, [], []);
|
|
1676
|
+
}
|
|
1677
|
+
if (isFirstElement) {
|
|
1678
|
+
_jsonPath.push(0);
|
|
1679
|
+
isFirstElement = false;
|
|
1680
|
+
} else {
|
|
1681
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
1682
|
+
}
|
|
1683
|
+
if (!parseValue()) {
|
|
1684
|
+
handleError(4, [], [4, 5]);
|
|
1685
|
+
}
|
|
1686
|
+
needsComma = true;
|
|
1687
|
+
}
|
|
1688
|
+
onArrayEnd();
|
|
1689
|
+
if (!isFirstElement) {
|
|
1690
|
+
_jsonPath.pop();
|
|
1691
|
+
}
|
|
1692
|
+
if (_scanner.getToken() !== 4) {
|
|
1693
|
+
handleError(8, [4], []);
|
|
1694
|
+
} else {
|
|
1695
|
+
scanNext();
|
|
1696
|
+
}
|
|
1697
|
+
return true;
|
|
1698
|
+
}
|
|
1699
|
+
function parseValue() {
|
|
1700
|
+
switch (_scanner.getToken()) {
|
|
1701
|
+
case 3:
|
|
1702
|
+
return parseArray();
|
|
1703
|
+
case 1:
|
|
1704
|
+
return parseObject();
|
|
1705
|
+
case 10:
|
|
1706
|
+
return parseString(true);
|
|
1707
|
+
default:
|
|
1708
|
+
return parseLiteral();
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
scanNext();
|
|
1712
|
+
if (_scanner.getToken() === 17) {
|
|
1713
|
+
if (options.allowEmptyContent) {
|
|
1714
|
+
return true;
|
|
1715
|
+
}
|
|
1716
|
+
handleError(4, [], []);
|
|
1717
|
+
return false;
|
|
1718
|
+
}
|
|
1719
|
+
if (!parseValue()) {
|
|
1720
|
+
handleError(4, [], []);
|
|
1721
|
+
return false;
|
|
1722
|
+
}
|
|
1723
|
+
if (_scanner.getToken() !== 17) {
|
|
1724
|
+
handleError(9, [], []);
|
|
1725
|
+
}
|
|
1726
|
+
return true;
|
|
1727
|
+
}
|
|
1728
|
+
function getNodeType(value) {
|
|
1729
|
+
switch (typeof value) {
|
|
1730
|
+
case "boolean":
|
|
1731
|
+
return "boolean";
|
|
1732
|
+
case "number":
|
|
1733
|
+
return "number";
|
|
1734
|
+
case "string":
|
|
1735
|
+
return "string";
|
|
1736
|
+
case "object": {
|
|
1737
|
+
if (!value) {
|
|
1738
|
+
return "null";
|
|
1739
|
+
} else if (Array.isArray(value)) {
|
|
1740
|
+
return "array";
|
|
1741
|
+
}
|
|
1742
|
+
return "object";
|
|
1743
|
+
}
|
|
1744
|
+
default:
|
|
1745
|
+
return "null";
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
// node_modules/jsonc-parser/lib/esm/impl/edit.js
|
|
1750
|
+
function setProperty(text, originalPath, value, options) {
|
|
1751
|
+
const path = originalPath.slice();
|
|
1752
|
+
const errors = [];
|
|
1753
|
+
const root = parseTree(text, errors);
|
|
1754
|
+
let parent = undefined;
|
|
1755
|
+
let lastSegment = undefined;
|
|
1756
|
+
while (path.length > 0) {
|
|
1757
|
+
lastSegment = path.pop();
|
|
1758
|
+
parent = findNodeAtLocation(root, path);
|
|
1759
|
+
if (parent === undefined && value !== undefined) {
|
|
1760
|
+
if (typeof lastSegment === "string") {
|
|
1761
|
+
value = { [lastSegment]: value };
|
|
1762
|
+
} else {
|
|
1763
|
+
value = [value];
|
|
1764
|
+
}
|
|
1765
|
+
} else {
|
|
1766
|
+
break;
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
if (!parent) {
|
|
1770
|
+
if (value === undefined) {
|
|
1771
|
+
throw new Error("Can not delete in empty document");
|
|
1772
|
+
}
|
|
1773
|
+
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
|
|
1774
|
+
} else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
|
|
1775
|
+
const existing = findNodeAtLocation(parent, [lastSegment]);
|
|
1776
|
+
if (existing !== undefined) {
|
|
1777
|
+
if (value === undefined) {
|
|
1778
|
+
if (!existing.parent) {
|
|
1779
|
+
throw new Error("Malformed AST");
|
|
1780
|
+
}
|
|
1781
|
+
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
1782
|
+
let removeBegin;
|
|
1783
|
+
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
1784
|
+
if (propertyIndex > 0) {
|
|
1785
|
+
let previous = parent.children[propertyIndex - 1];
|
|
1786
|
+
removeBegin = previous.offset + previous.length;
|
|
1787
|
+
} else {
|
|
1788
|
+
removeBegin = parent.offset + 1;
|
|
1789
|
+
if (parent.children.length > 1) {
|
|
1790
|
+
let next = parent.children[1];
|
|
1791
|
+
removeEnd = next.offset;
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
|
|
1795
|
+
} else {
|
|
1796
|
+
return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
|
|
1797
|
+
}
|
|
1798
|
+
} else {
|
|
1799
|
+
if (value === undefined) {
|
|
1800
|
+
return [];
|
|
1801
|
+
}
|
|
1802
|
+
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
1803
|
+
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
|
|
1804
|
+
let edit;
|
|
1805
|
+
if (index > 0) {
|
|
1806
|
+
let previous = parent.children[index - 1];
|
|
1807
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1808
|
+
} else if (parent.children.length === 0) {
|
|
1809
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1810
|
+
} else {
|
|
1811
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
|
|
1812
|
+
}
|
|
1813
|
+
return withFormatting(text, edit, options);
|
|
1814
|
+
}
|
|
1815
|
+
} else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
|
|
1816
|
+
const insertIndex = lastSegment;
|
|
1817
|
+
if (insertIndex === -1) {
|
|
1818
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1819
|
+
let edit;
|
|
1820
|
+
if (parent.children.length === 0) {
|
|
1821
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1822
|
+
} else {
|
|
1823
|
+
const previous = parent.children[parent.children.length - 1];
|
|
1824
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1825
|
+
}
|
|
1826
|
+
return withFormatting(text, edit, options);
|
|
1827
|
+
} else if (value === undefined && parent.children.length >= 0) {
|
|
1828
|
+
const removalIndex = lastSegment;
|
|
1829
|
+
const toRemove = parent.children[removalIndex];
|
|
1830
|
+
let edit;
|
|
1831
|
+
if (parent.children.length === 1) {
|
|
1832
|
+
edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
|
|
1833
|
+
} else if (parent.children.length - 1 === removalIndex) {
|
|
1834
|
+
let previous = parent.children[removalIndex - 1];
|
|
1835
|
+
let offset = previous.offset + previous.length;
|
|
1836
|
+
let parentEndOffset = parent.offset + parent.length;
|
|
1837
|
+
edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
|
|
1838
|
+
} else {
|
|
1839
|
+
edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
|
|
1840
|
+
}
|
|
1841
|
+
return withFormatting(text, edit, options);
|
|
1842
|
+
} else if (value !== undefined) {
|
|
1843
|
+
let edit;
|
|
1844
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1845
|
+
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
1846
|
+
const toModify = parent.children[lastSegment];
|
|
1847
|
+
edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
|
|
1848
|
+
} else if (parent.children.length === 0 || lastSegment === 0) {
|
|
1849
|
+
edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
|
|
1850
|
+
} else {
|
|
1851
|
+
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
1852
|
+
const previous = parent.children[index - 1];
|
|
1853
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1854
|
+
}
|
|
1855
|
+
return withFormatting(text, edit, options);
|
|
1856
|
+
} else {
|
|
1857
|
+
throw new Error(`Can not ${value === undefined ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
|
|
1858
|
+
}
|
|
1859
|
+
} else {
|
|
1860
|
+
throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
function withFormatting(text, edit, options) {
|
|
1864
|
+
if (!options.formattingOptions) {
|
|
1865
|
+
return [edit];
|
|
1866
|
+
}
|
|
1867
|
+
let newText = applyEdit(text, edit);
|
|
1868
|
+
let begin = edit.offset;
|
|
1869
|
+
let end = edit.offset + edit.content.length;
|
|
1870
|
+
if (edit.length === 0 || edit.content.length === 0) {
|
|
1871
|
+
while (begin > 0 && !isEOL(newText, begin - 1)) {
|
|
1872
|
+
begin--;
|
|
1873
|
+
}
|
|
1874
|
+
while (end < newText.length && !isEOL(newText, end)) {
|
|
1875
|
+
end++;
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
|
|
1879
|
+
for (let i = edits.length - 1;i >= 0; i--) {
|
|
1880
|
+
const edit2 = edits[i];
|
|
1881
|
+
newText = applyEdit(newText, edit2);
|
|
1882
|
+
begin = Math.min(begin, edit2.offset);
|
|
1883
|
+
end = Math.max(end, edit2.offset + edit2.length);
|
|
1884
|
+
end += edit2.content.length - edit2.length;
|
|
1885
|
+
}
|
|
1886
|
+
const editLength = text.length - (newText.length - end) - begin;
|
|
1887
|
+
return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
|
|
1888
|
+
}
|
|
1889
|
+
function applyEdit(text, edit) {
|
|
1890
|
+
return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
// node_modules/jsonc-parser/lib/esm/main.js
|
|
1894
|
+
var ScanError;
|
|
1895
|
+
(function(ScanError2) {
|
|
1896
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
1897
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
1898
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
1899
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
1900
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
1901
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
1902
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
1903
|
+
})(ScanError || (ScanError = {}));
|
|
1904
|
+
var SyntaxKind;
|
|
1905
|
+
(function(SyntaxKind2) {
|
|
1906
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
1907
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
1908
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
1909
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
1910
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
1911
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
1912
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
1913
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
1914
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
1915
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
1916
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
1917
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
1918
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
1919
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
1920
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
1921
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
1922
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
1923
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
1924
|
+
var parse2 = parse;
|
|
1925
|
+
var ParseErrorCode;
|
|
1926
|
+
(function(ParseErrorCode2) {
|
|
1927
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
1928
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
1929
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
1930
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
1931
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
1932
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
1933
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
1934
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
1935
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
1936
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
1937
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
1938
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
1939
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
1940
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
1941
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
1942
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
1943
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
1944
|
+
function modify(text, path, value, options) {
|
|
1945
|
+
return setProperty(text, path, value, options);
|
|
1946
|
+
}
|
|
1947
|
+
function applyEdits(text, edits) {
|
|
1948
|
+
let sortedEdits = edits.slice(0).sort((a, b) => {
|
|
1949
|
+
const diff = a.offset - b.offset;
|
|
1950
|
+
if (diff === 0) {
|
|
1951
|
+
return a.length - b.length;
|
|
1952
|
+
}
|
|
1953
|
+
return diff;
|
|
1954
|
+
});
|
|
1955
|
+
let lastModifiedOffset = text.length;
|
|
1956
|
+
for (let i = sortedEdits.length - 1;i >= 0; i--) {
|
|
1957
|
+
let e = sortedEdits[i];
|
|
1958
|
+
if (e.offset + e.length <= lastModifiedOffset) {
|
|
1959
|
+
text = applyEdit(text, e);
|
|
1960
|
+
} else {
|
|
1961
|
+
throw new Error("Overlapping edit");
|
|
1962
|
+
}
|
|
1963
|
+
lastModifiedOffset = e.offset;
|
|
1964
|
+
}
|
|
1965
|
+
return text;
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
// src/shared/claude-settings.ts
|
|
1969
|
+
var settingsPath = join5(homedir2(), ".claude", "settings.json");
|
|
1970
|
+
function readClaudeSettings() {
|
|
1971
|
+
if (!existsSync6(settingsPath)) {
|
|
1972
|
+
return {};
|
|
1973
|
+
}
|
|
1974
|
+
const content = readFileSync4(settingsPath, "utf8");
|
|
1975
|
+
return parse2(content) ?? {};
|
|
1976
|
+
}
|
|
1977
|
+
function writeClaudeSettings(settings) {
|
|
1978
|
+
const dir = dirname4(settingsPath);
|
|
1979
|
+
if (!existsSync6(dir)) {
|
|
1980
|
+
mkdirSync4(dir, { recursive: true });
|
|
1981
|
+
}
|
|
1982
|
+
let content;
|
|
1983
|
+
if (existsSync6(settingsPath)) {
|
|
1984
|
+
content = readFileSync4(settingsPath, "utf8");
|
|
1985
|
+
for (const [key, value] of Object.entries(settings)) {
|
|
1986
|
+
const edits = modify(content, [key], value, {});
|
|
1987
|
+
content = applyEdits(content, edits);
|
|
1988
|
+
}
|
|
1989
|
+
const existing = parse2(content) ?? {};
|
|
1990
|
+
for (const key of Object.keys(existing)) {
|
|
1991
|
+
if (!(key in settings)) {
|
|
1992
|
+
const edits = modify(content, [key], undefined, {});
|
|
1993
|
+
content = applyEdits(content, edits);
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
} else {
|
|
1997
|
+
content = JSON.stringify(settings, null, 2);
|
|
1998
|
+
}
|
|
1999
|
+
const tmp = settingsPath + ".tmp";
|
|
2000
|
+
writeFileSync4(tmp, content, "utf8");
|
|
2001
|
+
renameSync2(tmp, settingsPath);
|
|
2002
|
+
}
|
|
2003
|
+
function registerMcpServer(name, entry) {
|
|
2004
|
+
const settings = readClaudeSettings();
|
|
2005
|
+
if (!settings.mcpServers) {
|
|
2006
|
+
settings.mcpServers = {};
|
|
2007
|
+
}
|
|
2008
|
+
settings.mcpServers[name] = entry;
|
|
2009
|
+
writeClaudeSettings(settings);
|
|
2010
|
+
}
|
|
2011
|
+
function removeMcpServer(name) {
|
|
2012
|
+
const settings = readClaudeSettings();
|
|
2013
|
+
if (settings.mcpServers) {
|
|
2014
|
+
delete settings.mcpServers[name];
|
|
2015
|
+
writeClaudeSettings(settings);
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
function registerHook(event, rule) {
|
|
2019
|
+
const settings = readClaudeSettings();
|
|
2020
|
+
if (!settings.hooks) {
|
|
2021
|
+
settings.hooks = {};
|
|
2022
|
+
}
|
|
2023
|
+
if (!settings.hooks[event]) {
|
|
2024
|
+
settings.hooks[event] = [];
|
|
2025
|
+
}
|
|
2026
|
+
const rules = settings.hooks[event];
|
|
2027
|
+
for (const hookCmd of rule.hooks) {
|
|
2028
|
+
let replaced = false;
|
|
2029
|
+
for (let i = 0;i < rules.length; i++) {
|
|
2030
|
+
const existingIdx = rules[i].hooks.findIndex((h) => h.command === hookCmd.command);
|
|
2031
|
+
if (existingIdx !== -1) {
|
|
2032
|
+
rules[i] = rule;
|
|
2033
|
+
replaced = true;
|
|
2034
|
+
break;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
if (!replaced) {
|
|
2038
|
+
rules.push(rule);
|
|
2039
|
+
break;
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
writeClaudeSettings(settings);
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
// src/cli/commands/install.ts
|
|
2046
|
+
function resolveOmxSource() {
|
|
2047
|
+
try {
|
|
2048
|
+
const cliDir = dirname5(fileURLToPath2(import.meta.url));
|
|
2049
|
+
const pkgRoot = resolve2(cliDir, "..", "..");
|
|
2050
|
+
const source = join6(pkgRoot, "dist", "omx", "index.mjs");
|
|
2051
|
+
if (existsSync7(source))
|
|
2052
|
+
return source;
|
|
2053
|
+
} catch {}
|
|
2054
|
+
try {
|
|
2055
|
+
const req = createRequire2(import.meta.url);
|
|
2056
|
+
return req.resolve("@ksm0709/context/omx");
|
|
2057
|
+
} catch {
|
|
2058
|
+
return null;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
function installOmx(projectDir, sourcePath) {
|
|
2062
|
+
if (!existsSync7(sourcePath)) {
|
|
2063
|
+
process.stderr.write(`Could not find OMX plugin source file: ${sourcePath}
|
|
2064
|
+
`);
|
|
2065
|
+
process.exit(1);
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2068
|
+
const targetDir = join6(projectDir, ".omx", "hooks");
|
|
2069
|
+
mkdirSync5(targetDir, { recursive: true });
|
|
2070
|
+
copyFileSync(sourcePath, join6(targetDir, "context.mjs"));
|
|
2071
|
+
process.stdout.write(`Installed context plugin to .omx/hooks/context.mjs
|
|
2072
|
+
`);
|
|
2073
|
+
if (ensureMcpRegistered()) {
|
|
2074
|
+
process.stdout.write(`Successfully registered context-mcp in ~/.omx/mcp-registry.json
|
|
2075
|
+
`);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
function installOmc(projectDir) {
|
|
2079
|
+
scaffoldIfNeeded(projectDir);
|
|
2080
|
+
injectIntoAgentsMd(join6(projectDir, "AGENTS.md"), STATIC_KNOWLEDGE_CONTEXT);
|
|
2081
|
+
let bunPath = "bun";
|
|
2082
|
+
try {
|
|
2083
|
+
bunPath = execSync("which bun", { encoding: "utf-8" }).trim();
|
|
2084
|
+
} catch {}
|
|
2085
|
+
const mcpPath = resolveMcpPath();
|
|
2086
|
+
const hookBasePath = join6(dirname5(mcpPath), "omc") + "/";
|
|
2087
|
+
removeMcpServer("context_mcp");
|
|
2088
|
+
registerMcpServer("context-mcp", { command: bunPath, args: [mcpPath], enabled: true });
|
|
2089
|
+
registerHook("SessionStart", {
|
|
2090
|
+
matcher: "startup",
|
|
2091
|
+
hooks: [
|
|
2092
|
+
{
|
|
2093
|
+
type: "command",
|
|
2094
|
+
command: `${bunPath} ${hookBasePath}session-start-hook.js`,
|
|
2095
|
+
timeout: 15,
|
|
2096
|
+
statusMessage: "Initializing context plugin..."
|
|
2097
|
+
}
|
|
2098
|
+
]
|
|
2099
|
+
});
|
|
2100
|
+
registerHook("Stop", {
|
|
2101
|
+
hooks: [
|
|
2102
|
+
{
|
|
2103
|
+
type: "command",
|
|
2104
|
+
command: `${bunPath} ${hookBasePath}stop-hook.js`,
|
|
2105
|
+
timeout: 10,
|
|
2106
|
+
statusMessage: "Checking turn completion..."
|
|
2107
|
+
}
|
|
2108
|
+
]
|
|
2109
|
+
});
|
|
2110
|
+
process.stdout.write(`Successfully installed context (omc) plugin.
|
|
2111
|
+
`);
|
|
2112
|
+
}
|
|
2113
|
+
function runInstall(args) {
|
|
2114
|
+
const [subcommand] = args;
|
|
2115
|
+
switch (subcommand) {
|
|
2116
|
+
case "omx": {
|
|
2117
|
+
const source = resolveOmxSource();
|
|
2118
|
+
if (!source) {
|
|
2119
|
+
process.stderr.write(`Could not find OMX plugin source file (dist/omx/index.mjs).
|
|
2120
|
+
`);
|
|
2121
|
+
process.exit(1);
|
|
2122
|
+
return;
|
|
2123
|
+
}
|
|
2124
|
+
installOmx(process.cwd(), source);
|
|
2125
|
+
break;
|
|
2126
|
+
}
|
|
2127
|
+
case "omc":
|
|
2128
|
+
case "claude":
|
|
2129
|
+
installOmc(process.cwd());
|
|
2130
|
+
break;
|
|
2131
|
+
case undefined:
|
|
2132
|
+
process.stderr.write(`Missing install target. Usage: context install <omx|omc>
|
|
2133
|
+
`);
|
|
2134
|
+
process.exit(1);
|
|
2135
|
+
break;
|
|
2136
|
+
default:
|
|
2137
|
+
process.stderr.write(`Unknown install target: ${subcommand}
|
|
2138
|
+
`);
|
|
2139
|
+
process.exit(1);
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
// src/cli/commands/update.ts
|
|
2144
|
+
var KNOWN_SUBCOMMANDS = ["all", "prompt", "plugin"];
|
|
2145
|
+
function runUpdate(args) {
|
|
2146
|
+
const [subcommand, ...rest] = args;
|
|
2147
|
+
switch (subcommand) {
|
|
2148
|
+
case undefined:
|
|
2149
|
+
case "all":
|
|
2150
|
+
runUpdateAll(resolve3(rest[0] ?? process.cwd()));
|
|
2151
|
+
break;
|
|
2152
|
+
case "prompt":
|
|
2153
|
+
process.stdout.write(`Prompt update is no longer supported.
|
|
2154
|
+
`);
|
|
2155
|
+
break;
|
|
2156
|
+
case "plugin":
|
|
2157
|
+
runUpdatePlugin(rest[0] ?? "latest");
|
|
2158
|
+
break;
|
|
2159
|
+
default:
|
|
2160
|
+
if (!KNOWN_SUBCOMMANDS.includes(subcommand)) {
|
|
2161
|
+
runUpdateAll(resolve3(subcommand));
|
|
2162
|
+
} else {
|
|
2163
|
+
process.stderr.write(`Unknown update subcommand: ${subcommand}
|
|
2164
|
+
`);
|
|
2165
|
+
process.exit(1);
|
|
2166
|
+
}
|
|
2167
|
+
break;
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
function isOmxInstalled(projectDir) {
|
|
2171
|
+
return existsSync8(join7(projectDir, ".omx", "hooks", "context.mjs"));
|
|
2172
|
+
}
|
|
2173
|
+
function isOmcInstalled() {
|
|
2174
|
+
try {
|
|
2175
|
+
const settings = readClaudeSettings();
|
|
2176
|
+
return settings.mcpServers != null && "context-mcp" in settings.mcpServers;
|
|
2177
|
+
} catch {
|
|
2178
|
+
return false;
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
function runUpdateAll(projectDir) {
|
|
2182
|
+
const updated = updateScaffold(projectDir);
|
|
2183
|
+
if (updated.length === 0) {
|
|
2184
|
+
process.stdout.write(`All scaffold files are already up to date.
|
|
2185
|
+
`);
|
|
2186
|
+
} else {
|
|
2187
|
+
process.stdout.write(`Updated ${updated.length} file(s):
|
|
2188
|
+
`);
|
|
2189
|
+
for (const f of updated) {
|
|
2190
|
+
process.stdout.write(` - ${f}
|
|
2191
|
+
`);
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
if (isOmcInstalled()) {
|
|
2195
|
+
process.stdout.write(`
|
|
2196
|
+
Re-installing omc hooks and settings...
|
|
2197
|
+
`);
|
|
2198
|
+
installOmc(projectDir);
|
|
2199
|
+
}
|
|
2200
|
+
if (isOmxInstalled(projectDir)) {
|
|
2201
|
+
const source = resolveOmxSource();
|
|
2202
|
+
if (source) {
|
|
2203
|
+
process.stdout.write(`
|
|
2204
|
+
Re-installing omx plugin...
|
|
2205
|
+
`);
|
|
2206
|
+
installOmx(projectDir, source);
|
|
2207
|
+
} else {
|
|
2208
|
+
process.stderr.write(`
|
|
2209
|
+
Warning: could not resolve omx source; skipping omx reinstall.
|
|
2210
|
+
`);
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
function detectPackageManager() {
|
|
2215
|
+
if (existsSync8("bun.lock") || existsSync8("bun.lockb"))
|
|
2216
|
+
return "bun";
|
|
2217
|
+
if (existsSync8("pnpm-lock.yaml"))
|
|
2218
|
+
return "pnpm";
|
|
2219
|
+
if (existsSync8("yarn.lock"))
|
|
2220
|
+
return "yarn";
|
|
2221
|
+
if (existsSync8("package-lock.json"))
|
|
2222
|
+
return "npm";
|
|
2223
|
+
return "bun";
|
|
2224
|
+
}
|
|
2225
|
+
function detectGlobalInstalls() {
|
|
2226
|
+
const installs = [];
|
|
2227
|
+
const bunGlobalBin = join7(homedir3(), ".bun", "bin", "context");
|
|
2228
|
+
if (existsSync8(bunGlobalBin)) {
|
|
2229
|
+
installs.push({ pm: "bun", label: "bun global", installCmd: ["bun", "install", "-g"] });
|
|
2230
|
+
}
|
|
2231
|
+
const spawnSync = globalThis.Bun?.spawnSync;
|
|
2232
|
+
if (spawnSync) {
|
|
2233
|
+
const whichResult = spawnSync(["which", "context"]);
|
|
2234
|
+
if (whichResult.exitCode === 0) {
|
|
2235
|
+
const binPath = whichResult.stdout.toString().trim();
|
|
2236
|
+
if (binPath && !binPath.includes(".bun") && !binPath.includes("node_modules")) {
|
|
2237
|
+
installs.push({ pm: "npm", label: "npm global", installCmd: ["npm", "install", "-g"] });
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
return installs;
|
|
2242
|
+
}
|
|
2243
|
+
function runUpdatePlugin(version) {
|
|
2244
|
+
const pkg = `@ksm0709/context@${version}`;
|
|
2245
|
+
const spawnSync = globalThis.Bun?.spawnSync;
|
|
2246
|
+
if (!spawnSync) {
|
|
2247
|
+
process.stderr.write(`Bun runtime required for plugin updates.
|
|
2248
|
+
`);
|
|
2249
|
+
process.exit(1);
|
|
2250
|
+
return;
|
|
2251
|
+
}
|
|
2252
|
+
const globalInstalls = detectGlobalInstalls();
|
|
2253
|
+
for (const { label, installCmd } of globalInstalls) {
|
|
2254
|
+
process.stdout.write(`Updating ${label} ${pkg}...
|
|
2255
|
+
`);
|
|
2256
|
+
const result = spawnSync([...installCmd, pkg]);
|
|
2257
|
+
if (result.exitCode !== 0) {
|
|
2258
|
+
process.stderr.write(`Failed to update ${label}: ${result.stderr.toString()}
|
|
2259
|
+
`);
|
|
2260
|
+
process.exit(1);
|
|
2261
|
+
return;
|
|
2262
|
+
}
|
|
2263
|
+
process.stdout.write(`Successfully updated ${label} ${pkg}.
|
|
2264
|
+
`);
|
|
2265
|
+
}
|
|
2266
|
+
const pm = detectPackageManager();
|
|
2267
|
+
process.stdout.write(`Updating local ${pkg} using ${pm}...
|
|
2268
|
+
`);
|
|
2269
|
+
const localResult = spawnSync([pm, "add", pkg]);
|
|
2270
|
+
if (localResult.exitCode !== 0) {
|
|
2271
|
+
process.stderr.write(`Failed to update local: ${localResult.stderr.toString()}
|
|
2272
|
+
`);
|
|
2273
|
+
process.exit(1);
|
|
2274
|
+
return;
|
|
2275
|
+
}
|
|
2276
|
+
process.stdout.write(`Successfully updated local ${pkg}.
|
|
2277
|
+
`);
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
// src/cli/commands/migrate.ts
|
|
2281
|
+
import { resolve as resolve4, join as join8 } from "path";
|
|
2282
|
+
import { existsSync as existsSync9, cpSync, rmSync, readFileSync as readFileSync5, writeFileSync as writeFileSync5 } from "fs";
|
|
2283
|
+
var LEGACY_CONTEXT_DIR = ".opencode/context";
|
|
2284
|
+
var NEW_CONTEXT_DIR = ".context";
|
|
2285
|
+
function runMigrate(args) {
|
|
2286
|
+
const keepFlag = args.includes("--keep");
|
|
2287
|
+
const pathArg = args.find((a) => !a.startsWith("--"));
|
|
2288
|
+
const projectDir = resolve4(pathArg ?? process.cwd());
|
|
2289
|
+
const legacyDir = join8(projectDir, LEGACY_CONTEXT_DIR);
|
|
2290
|
+
const newDir = join8(projectDir, NEW_CONTEXT_DIR);
|
|
2291
|
+
if (!existsSync9(legacyDir)) {
|
|
2292
|
+
process.stdout.write(`Nothing to migrate.
|
|
2293
|
+
`);
|
|
2294
|
+
return;
|
|
2295
|
+
}
|
|
2296
|
+
if (existsSync9(newDir)) {
|
|
2297
|
+
process.stderr.write(`Target .context/ already exists. Aborting.
|
|
2298
|
+
`);
|
|
2299
|
+
process.exit(1);
|
|
2300
|
+
return;
|
|
2301
|
+
}
|
|
2302
|
+
cpSync(legacyDir, newDir, { recursive: true });
|
|
2303
|
+
updateConfigPaths(newDir);
|
|
2304
|
+
if (!keepFlag) {
|
|
2305
|
+
rmSync(legacyDir, { recursive: true, force: true });
|
|
2306
|
+
}
|
|
2307
|
+
process.stdout.write(`Migrated .opencode/context/ \u2192 .context/
|
|
2308
|
+
`);
|
|
2309
|
+
}
|
|
2310
|
+
function updateConfigPaths(contextDir) {
|
|
2311
|
+
const configPath = join8(contextDir, "config.jsonc");
|
|
2312
|
+
if (!existsSync9(configPath))
|
|
2313
|
+
return;
|
|
2314
|
+
try {
|
|
2315
|
+
const content = readFileSync5(configPath, "utf-8");
|
|
2316
|
+
const updated = content.replaceAll(".opencode/context/", "");
|
|
2317
|
+
if (updated !== content) {
|
|
2318
|
+
writeFileSync5(configPath, updated, "utf-8");
|
|
2319
|
+
}
|
|
2320
|
+
} catch {}
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
// src/cli/index.ts
|
|
2324
|
+
var PLUGIN_VERSION2 = package_default.version;
|
|
2325
|
+
function printHelp(out) {
|
|
2326
|
+
const write = out ?? ((s) => process.stdout.write(s));
|
|
2327
|
+
write(`Context Plugin CLI v${PLUGIN_VERSION2}
|
|
2328
|
+
|
|
2329
|
+
`);
|
|
2330
|
+
write(`Usage: context <command> [options]
|
|
2331
|
+
|
|
2332
|
+
`);
|
|
2333
|
+
write(`Commands:
|
|
2334
|
+
`);
|
|
2335
|
+
write(` update [all] [path] Force-update scaffold + reinstall omc/omx
|
|
2336
|
+
`);
|
|
2337
|
+
write(` update prompt [path] Force-update prompt files only
|
|
2338
|
+
`);
|
|
2339
|
+
write(` update plugin [version] Update @ksm0709/context package
|
|
2340
|
+
`);
|
|
2341
|
+
write(` migrate [path] [--keep] Migrate .opencode/context/ \u2192 .context/
|
|
2342
|
+
`);
|
|
2343
|
+
write(` install omx Install OMX hook plugin to .omx/hooks/
|
|
2344
|
+
`);
|
|
2345
|
+
write(` install omc Install OMC hooks/MCP to Claude settings
|
|
743
2346
|
`);
|
|
744
2347
|
write(`
|
|
745
2348
|
`);
|