@usecontextlayer/ctxe 0.4.0 → 0.4.2

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.mjs CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env node
2
+
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d97c9b53-4423-5a49-9ffa-bd79394a4775")}catch(e){}}();
2
4
  import { createRequire } from "node:module";
3
5
  import * as Sentry from "@sentry/node";
4
6
  import * as xi from "node:fs";
@@ -57,7 +59,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
57
59
 
58
60
  //#endregion
59
61
  //#region package.json
60
- var version$1 = "0.4.0";
62
+ var version$1 = "0.4.2";
61
63
 
62
64
  //#endregion
63
65
  //#region sentry.ts
@@ -29488,7 +29490,7 @@ function validate(raw, sourcePath) {
29488
29490
  }
29489
29491
  function applyDefaults(input) {
29490
29492
  return {
29491
- synthesizerImage: input.synthesizerImage ?? "ghcr.io/usecontextlayer/ctx-sandbox:0.4.0",
29493
+ synthesizerImage: input.synthesizerImage ?? "ghcr.io/usecontextlayer/ctx-sandbox:0.4.2",
29492
29494
  ...input.microsandbox !== void 0 ? { microsandbox: input.microsandbox } : {},
29493
29495
  ...input.oldestConsideredPoint !== void 0 ? { oldestConsideredPoint: input.oldestConsideredPoint } : {},
29494
29496
  maxSliceSize: input.maxSliceSize ?? 864e5,
@@ -29661,6 +29663,9 @@ async function commitSynthesizerTransaction(repo, input) {
29661
29663
  async function commitRootRepair(repo, input) {
29662
29664
  return await createCommit(repo, buildRootRepairCommitMessage(input));
29663
29665
  }
29666
+ async function commitRootReset(repo, input) {
29667
+ return await createCommit(repo, buildRootResetCommitMessage(input));
29668
+ }
29664
29669
  async function pushToOrigin(repo) {
29665
29670
  if (repo.mode !== "remote") return;
29666
29671
  await runGit(repo, [
@@ -29790,6 +29795,14 @@ function buildRootRepairCommitMessage(input) {
29790
29795
  ""
29791
29796
  ].join("\n");
29792
29797
  }
29798
+ function buildRootResetCommitMessage(input) {
29799
+ return [
29800
+ `ctxe: root reset @ ${input.resetId}`,
29801
+ "",
29802
+ "reset: wipe synthesized content + cursors",
29803
+ ""
29804
+ ].join("\n");
29805
+ }
29793
29806
  function parsePorcelainV1Z(stdout) {
29794
29807
  const entries = stdout.split("\0").filter((entry) => entry.length > 0);
29795
29808
  const paths = [];
@@ -30158,7 +30171,7 @@ engine has prepared three files in your working directory:
30158
30171
  - \`./output/\` — the only path that persists back to the host. Anything written
30159
30172
  elsewhere is lost when the sandbox exits.
30160
30173
 
30161
- A \`contextengine\` skill is installed. Read and follow it — it defines how to
30174
+ A \`contextengine-synthesizer\` skill is installed. Read and follow it — it defines how to
30162
30175
  synthesize well. Then do the work in \`./synthesizer.md\` and exit.
30163
30176
 
30164
30177
  A clean exit is success; the engine records the run from its own metadata. Do
@@ -31333,6 +31346,53 @@ function formatCombinedRepairError(repo, branch, tree) {
31333
31346
  "Operator must inspect and choose the order manually."
31334
31347
  ].join("\n");
31335
31348
  }
31349
+ const RESERVED_OUTPUT_SUBDIRS = new Set(["types", "views"]);
31350
+ const OUTPUT_DIR_RELATIVE = "output";
31351
+ const CURSORS_DIR_RELATIVE = ".engine/cursors";
31352
+ async function planRootReset(rootDir) {
31353
+ const cursorFiles = (await readDirNames(cursorsDirPath(rootDir))).filter((name) => name.endsWith(".json"));
31354
+ return {
31355
+ contentPaths: (await readDirNames(path.join(rootDir, OUTPUT_DIR_RELATIVE))).filter((name) => !RESERVED_OUTPUT_SUBDIRS.has(name)).map((name) => path.join(OUTPUT_DIR_RELATIVE, name)).sort(),
31356
+ cursorPaths: cursorFiles.map((name) => path.join(CURSORS_DIR_RELATIVE, name)).sort()
31357
+ };
31358
+ }
31359
+ async function runRootReset(repo, options = {}) {
31360
+ const preflight = await runRootPreflight(repo);
31361
+ if (!preflight.ready && !options.force) throw new Error(formatNotReadyError(repo, preflight.issues));
31362
+ const plan = await planRootReset(repo.rootDir);
31363
+ for (const relativePath of [...plan.cursorPaths, ...plan.contentPaths]) await rm(path.join(repo.rootDir, relativePath), {
31364
+ force: true,
31365
+ recursive: true
31366
+ });
31367
+ if ((await inspectWorkingTree(repo)).clean) return { kind: "no_op" };
31368
+ const { sha } = await commitRootReset(repo, { resetId: v7() });
31369
+ await pushToOrigin(repo);
31370
+ return {
31371
+ commit: {
31372
+ pushed: repo.mode === "remote",
31373
+ sha
31374
+ },
31375
+ kind: "reset",
31376
+ removedContent: plan.contentPaths,
31377
+ removedCursors: plan.cursorPaths
31378
+ };
31379
+ }
31380
+ async function readDirNames(dir) {
31381
+ try {
31382
+ return await readdir$1(dir);
31383
+ } catch (error) {
31384
+ if (isNodeError(error) && error.code === "ENOENT") return [];
31385
+ throw error;
31386
+ }
31387
+ }
31388
+ function formatNotReadyError(repo, issues) {
31389
+ const list = issues.map((issue) => ` - ${issue.message}`).join("\n");
31390
+ return [
31391
+ `RootReset refuses to act: engine root '${repo.rootDir}' is not ready.`,
31392
+ list,
31393
+ "Commit your authored config (or run 'ctxe repair'), or pass --force to reset anyway."
31394
+ ].join("\n");
31395
+ }
31336
31396
  const SOURCE_UPDATED_AT_COLUMN = "_ctx_source_updated_at";
31337
31397
  async function captureWatermark(input) {
31338
31398
  const sql = src_default(input.databaseUrl);
@@ -31508,6 +31568,29 @@ async function runRepairCommand(repo) {
31508
31568
  process.stdout.write(`${formatJsonOutput(result)}\n`);
31509
31569
  }
31510
31570
 
31571
+ //#endregion
31572
+ //#region commands/reset.ts
31573
+ async function runResetCommand(input) {
31574
+ const { repo, yes, force } = input;
31575
+ if (!yes) {
31576
+ const preflight = await runRootPreflight(repo);
31577
+ const plan = await planRootReset(repo.rootDir);
31578
+ process.stdout.write(`${formatJsonOutput({
31579
+ dryRun: true,
31580
+ hint: "pass --yes to execute (commits the wipe), then 'ctxe backfill <name>' to rebuild",
31581
+ issues: preflight.issues,
31582
+ ready: preflight.ready,
31583
+ wouldRemove: {
31584
+ content: plan.contentPaths,
31585
+ cursors: plan.cursorPaths
31586
+ }
31587
+ })}\n`);
31588
+ return;
31589
+ }
31590
+ const result = await runRootReset(repo, { force });
31591
+ process.stdout.write(`${formatJsonOutput(result)}\n`);
31592
+ }
31593
+
31511
31594
  //#endregion
31512
31595
  //#region commands/run.ts
31513
31596
  async function runRunCommand(input) {
@@ -31610,6 +31693,13 @@ function createProgram() {
31610
31693
  program.command("repair").description("Explicit out-of-band root repair: safe fast-forward when clean and stale, or dirty-root rollback that preserves .engine/runs/**. Refuses local-ahead state, divergence, and the combined stale-plus-dirty case.").action(async function() {
31611
31694
  await runRepairCommand(resolveRepoContext(this));
31612
31695
  });
31696
+ program.command("reset").option("--yes", "Execute the reset (delete cursors + wipe synthesized content, then commit). Without it, prints the plan and exits without mutating.").option("--force", "Reset even when the root is not preflight-ready (e.g. a dirty working tree). Use with care; normally you commit authored config or run 'ctxe repair' first.").description("Reset the whole workspace to a clean pre-synthesis state so it can be rebuilt from scratch: delete every synthesizer cursor (the next run bootstraps from engine.json's oldestConsideredPoint) and wipe all synthesized content under output/ except the authored types/ and views/, in one commit. Whole-workspace by design — output/ is not partitioned by synthesizer. Preserves .engine/runs/**. Default is a dry run; pass --yes to execute, then rebuild with 'ctxe backfill <synthesizer>' or 'ctxe daemon start'.").action(async function(options) {
31697
+ await runResetCommand({
31698
+ force: options.force ?? false,
31699
+ repo: resolveRepoContext(this),
31700
+ yes: options.yes ?? false
31701
+ });
31702
+ });
31613
31703
  program.command("run").argument("<synthesizer>", "Synthesizer name").option("--database-url <url>", "Postgres URL of the ContextBase database the synthesizer reads from. Falls back to CTXB_DATABASE_URL.").description("Run a single synthesizer once. Exits non-zero on a failed or timed-out run.").action(async function(synthesizerName, options) {
31614
31704
  await runRunCommand({
31615
31705
  databaseUrl: options.databaseUrl,
@@ -31652,4 +31742,5 @@ runCli().catch((error) => {
31652
31742
 
31653
31743
  //#endregion
31654
31744
  export { createProgram, resolveRepoContext, resolveRuntimePaths, runCli };
31655
- //# sourceMappingURL=cli.mjs.map
31745
+ //# sourceMappingURL=cli.mjs.map
31746
+ //# debugId=d97c9b53-4423-5a49-9ffa-bd79394a4775