@usecontextlayer/ctxe 0.4.1 → 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,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
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]="b91f2a1b-d2ef-5d42-a3e9-b2e7ffe81cc4")}catch(e){}}();
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){}}();
4
4
  import { createRequire } from "node:module";
5
5
  import * as Sentry from "@sentry/node";
6
6
  import * as xi from "node:fs";
@@ -59,7 +59,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
59
59
 
60
60
  //#endregion
61
61
  //#region package.json
62
- var version$1 = "0.4.1";
62
+ var version$1 = "0.4.2";
63
63
 
64
64
  //#endregion
65
65
  //#region sentry.ts
@@ -29490,7 +29490,7 @@ function validate(raw, sourcePath) {
29490
29490
  }
29491
29491
  function applyDefaults(input) {
29492
29492
  return {
29493
- synthesizerImage: input.synthesizerImage ?? "ghcr.io/usecontextlayer/ctx-sandbox:0.4.1",
29493
+ synthesizerImage: input.synthesizerImage ?? "ghcr.io/usecontextlayer/ctx-sandbox:0.4.2",
29494
29494
  ...input.microsandbox !== void 0 ? { microsandbox: input.microsandbox } : {},
29495
29495
  ...input.oldestConsideredPoint !== void 0 ? { oldestConsideredPoint: input.oldestConsideredPoint } : {},
29496
29496
  maxSliceSize: input.maxSliceSize ?? 864e5,
@@ -29663,6 +29663,9 @@ async function commitSynthesizerTransaction(repo, input) {
29663
29663
  async function commitRootRepair(repo, input) {
29664
29664
  return await createCommit(repo, buildRootRepairCommitMessage(input));
29665
29665
  }
29666
+ async function commitRootReset(repo, input) {
29667
+ return await createCommit(repo, buildRootResetCommitMessage(input));
29668
+ }
29666
29669
  async function pushToOrigin(repo) {
29667
29670
  if (repo.mode !== "remote") return;
29668
29671
  await runGit(repo, [
@@ -29792,6 +29795,14 @@ function buildRootRepairCommitMessage(input) {
29792
29795
  ""
29793
29796
  ].join("\n");
29794
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
+ }
29795
29806
  function parsePorcelainV1Z(stdout) {
29796
29807
  const entries = stdout.split("\0").filter((entry) => entry.length > 0);
29797
29808
  const paths = [];
@@ -30160,7 +30171,7 @@ engine has prepared three files in your working directory:
30160
30171
  - \`./output/\` — the only path that persists back to the host. Anything written
30161
30172
  elsewhere is lost when the sandbox exits.
30162
30173
 
30163
- 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
30164
30175
  synthesize well. Then do the work in \`./synthesizer.md\` and exit.
30165
30176
 
30166
30177
  A clean exit is success; the engine records the run from its own metadata. Do
@@ -31335,6 +31346,53 @@ function formatCombinedRepairError(repo, branch, tree) {
31335
31346
  "Operator must inspect and choose the order manually."
31336
31347
  ].join("\n");
31337
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
+ }
31338
31396
  const SOURCE_UPDATED_AT_COLUMN = "_ctx_source_updated_at";
31339
31397
  async function captureWatermark(input) {
31340
31398
  const sql = src_default(input.databaseUrl);
@@ -31510,6 +31568,29 @@ async function runRepairCommand(repo) {
31510
31568
  process.stdout.write(`${formatJsonOutput(result)}\n`);
31511
31569
  }
31512
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
+
31513
31594
  //#endregion
31514
31595
  //#region commands/run.ts
31515
31596
  async function runRunCommand(input) {
@@ -31612,6 +31693,13 @@ function createProgram() {
31612
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() {
31613
31694
  await runRepairCommand(resolveRepoContext(this));
31614
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
+ });
31615
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) {
31616
31704
  await runRunCommand({
31617
31705
  databaseUrl: options.databaseUrl,
@@ -31655,4 +31743,4 @@ runCli().catch((error) => {
31655
31743
  //#endregion
31656
31744
  export { createProgram, resolveRepoContext, resolveRuntimePaths, runCli };
31657
31745
  //# sourceMappingURL=cli.mjs.map
31658
- //# debugId=b91f2a1b-d2ef-5d42-a3e9-b2e7ffe81cc4
31746
+ //# debugId=d97c9b53-4423-5a49-9ffa-bd79394a4775