@lamplitisles/codex-for-love 0.4.1 → 0.4.3

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.
@@ -13,12 +13,11 @@ import { randomUUID as randomUUID$1 } from "crypto";
13
13
  import { createInterface } from "readline";
14
14
  import { homedir } from "os";
15
15
  import { createConnection, isIP } from "net";
16
- import * as fs from "node:fs";
17
- import { constants, createReadStream } from "node:fs";
18
16
  import { DatabaseSync } from "node:sqlite";
19
17
  import { execFile } from "node:child_process";
20
18
  import { promisify } from "node:util";
21
19
  import { createServer } from "node:http";
20
+ import * as fs from "node:fs";
22
21
  import * as qs from "node:querystring";
23
22
  //#region \0rolldown/runtime.js
24
23
  var __create = Object.create;
@@ -6202,13 +6201,14 @@ const schema = object({
6202
6201
  model: string().min(1).default(DEFAULT_CODEX_MODEL),
6203
6202
  version: literal(SUPPORTED_CODEX_VERSION).default(SUPPORTED_CODEX_VERSION),
6204
6203
  home: string().min(1).optional(),
6205
- provenance: string().min(1).optional(),
6206
- local_compaction: boolean().default(false)
6204
+ local_compaction: boolean().default(false),
6205
+ context_round_limit: number$1().int().min(0).default(10)
6207
6206
  }).strict().default({
6208
6207
  command: "codex-app-server",
6209
6208
  model: DEFAULT_CODEX_MODEL,
6210
6209
  version: SUPPORTED_CODEX_VERSION,
6211
- local_compaction: false
6210
+ local_compaction: false,
6211
+ context_round_limit: 10
6212
6212
  }),
6213
6213
  speech: object({
6214
6214
  endpoint: url().default("https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation"),
@@ -6235,8 +6235,7 @@ async function loadConfig(path) {
6235
6235
  } : void 0,
6236
6236
  codex: {
6237
6237
  ...config.codex,
6238
- home: config.codex.home ? resolve(base, config.codex.home) : void 0,
6239
- provenance: config.codex.provenance ? resolve(base, config.codex.provenance) : void 0
6238
+ home: config.codex.home ? resolve(base, config.codex.home) : void 0
6240
6239
  },
6241
6240
  keet: config.keet ? {
6242
6241
  ...config.keet.endpoint ? { endpoint: keetEndpoint(config.keet.endpoint) } : {},
@@ -62601,6 +62600,8 @@ function partnerPaths(workspace) {
62601
62600
  audio: join(managedRoot, "audio")
62602
62601
  };
62603
62602
  }
62603
+ //#endregion
62604
+ //#region apps/partner/runtime/context-bootstrap.ts
62604
62605
  const CONTEXT_TOKEN_BUDGET = 4e3;
62605
62606
  const hookFileName = "session-start-hook.mjs";
62606
62607
  const companionMcpFileName = import.meta.url.endsWith(".mjs") ? "companion-mcp.mjs" : "companion-mcp.ts";
@@ -62621,7 +62622,7 @@ function finalAgentText(items) {
62621
62622
  return texts.length ? texts.join("\n\n").trim() : void 0;
62622
62623
  }
62623
62624
  /** Select newest completed conversational sides without copying tool or image payloads. */
62624
- function selectTextRounds(turns, budget = CONTEXT_TOKEN_BUDGET, limit = 5) {
62625
+ function selectTextRounds(turns, budget = CONTEXT_TOKEN_BUDGET, limit = 10) {
62625
62626
  const candidates = [];
62626
62627
  for (const turn of turns) {
62627
62628
  if (turn.status !== "completed" || !turn.items) continue;
@@ -62681,6 +62682,10 @@ function shellQuote(value) {
62681
62682
  function hookCommand(contextPath) {
62682
62683
  return `${shellQuote(process.execPath)} ${shellQuote(fileURLToPath(new URL(`./${hookFileName}`, import.meta.url)))} ${shellQuote(contextPath)}`;
62683
62684
  }
62685
+ /** A release path changes, but a hook targeting this internal bootstrap remains CFL-owned. */
62686
+ function ownsBootstrapHook(value, contextPath) {
62687
+ return isRecord$1(value) && value.type === "command" && typeof value.command === "string" && value.command.includes(hookFileName) && value.command.includes(shellQuote(contextPath));
62688
+ }
62684
62689
  function isRecord$1(value) {
62685
62690
  return typeof value === "object" && value !== null && !Array.isArray(value);
62686
62691
  }
@@ -62759,31 +62764,21 @@ async function ensureHookDeclaration(workspace, contextPath, partnerConfigPath,
62759
62764
  const sessionStart = Array.isArray(hooks.SessionStart) ? hooks.SessionStart : [];
62760
62765
  let changed = ensureCompanionMcp(config, workspace, partnerConfigPath);
62761
62766
  changed = ensureKeetMcp(config, keetEndpoint) || changed;
62762
- let own = false;
62763
- const normalizedGroups = sessionStart.map((group) => {
62764
- if (!isRecord$1(group) || !Array.isArray(group.hooks)) return group;
62765
- let groupChanged = false;
62766
- const handlers = group.hooks.map((handler) => {
62767
- if (!isRecord$1(handler) || handler.type !== "command" || handler.command !== command) return handler;
62768
- own = true;
62769
- if (group.matcher === "startup|compact" && handler.additionalContextLimit === 0) return handler;
62770
- groupChanged = true;
62771
- return {
62772
- ...handler,
62773
- type: "command",
62774
- command,
62775
- additionalContextLimit: 0
62776
- };
62767
+ const own = sessionStart.flatMap((group) => isRecord$1(group) && Array.isArray(group.hooks) ? group.hooks.filter((handler) => ownsBootstrapHook(handler, contextPath)).map((handler) => ({
62768
+ group,
62769
+ handler
62770
+ })) : []);
62771
+ const canonical = own.length === 1 && own[0].group.matcher === "startup|compact" && own[0].handler.command === command && own[0].handler.additionalContextLimit === 0;
62772
+ let normalizedGroups = sessionStart;
62773
+ if (!canonical) {
62774
+ normalizedGroups = sessionStart.flatMap((group) => {
62775
+ if (!isRecord$1(group) || !Array.isArray(group.hooks)) return [group];
62776
+ const handlers = group.hooks.filter((handler) => !ownsBootstrapHook(handler, contextPath));
62777
+ return handlers.length ? [{
62778
+ ...group,
62779
+ hooks: handlers
62780
+ }] : [];
62777
62781
  });
62778
- if (!groupChanged) return group;
62779
- changed = true;
62780
- return {
62781
- ...group,
62782
- matcher: "startup|compact",
62783
- hooks: handlers
62784
- };
62785
- });
62786
- if (!own) {
62787
62782
  normalizedGroups.push({
62788
62783
  matcher: "startup|compact",
62789
62784
  hooks: [{
@@ -62892,72 +62887,6 @@ const compactionPrompt = [
62892
62887
  "- Output checkpoint text only. Do not call Tools, take actions, or mention compaction."
62893
62888
  ].join("\n");
62894
62889
  //#endregion
62895
- //#region apps/partner/runtime/provenance.ts
62896
- const CFL_FORK_REPOSITORY = "https://github.com/lamplitisles/codex";
62897
- const CFL_FORK_SOURCE_REVISION = "445477b6a83514611ac206d2ab04b79374555a4c";
62898
- const provenanceSchema = object({
62899
- schemaVersion: literal(1),
62900
- forkRepository: literal(CFL_FORK_REPOSITORY),
62901
- sourceRevision: string(),
62902
- releaseTag: string(),
62903
- codexVersion: literal(SUPPORTED_CODEX_VERSION),
62904
- target: _enum(["x86_64-unknown-linux-musl", "aarch64-apple-darwin"]),
62905
- executables: object({
62906
- "bin/codex-app-server": string().regex(/^[a-f0-9]{64}$/u),
62907
- "bin/codex-code-mode-host": string().regex(/^[a-f0-9]{64}$/u)
62908
- }).strict()
62909
- }).strict().superRefine((value, context) => {
62910
- const mac = value.target === "aarch64-apple-darwin";
62911
- const revision = mac ? "c1139f7b2793e94c14243689d756b09c0186708d" : CFL_FORK_SOURCE_REVISION;
62912
- const tag = mac ? /^cfl\/v0\.154\.0-app-server-darwin\.[0-9]+$/u : /^cfl\/v0\.154\.0-app-server-musl\.[0-9]+$/u;
62913
- if (value.sourceRevision !== revision || !tag.test(value.releaseTag)) context.addIssue({
62914
- code: "custom",
62915
- message: "Source revision/release identity does not match the selected platform"
62916
- });
62917
- });
62918
- async function sha256(path) {
62919
- const hash = createHash("sha256");
62920
- for await (const chunk of createReadStream(path)) hash.update(chunk);
62921
- return hash.digest("hex");
62922
- }
62923
- function provenanceError(path, message) {
62924
- return /* @__PURE__ */ new Error(`Invalid Codex provenance at ${path}: ${message}`);
62925
- }
62926
- /**
62927
- * Verifies the exact executable selected for local compaction before the SDK
62928
- * starts it. The app-server handshake still verifies the runtime version;
62929
- * this sidecar binds the selected path to the pinned source and patch set.
62930
- */
62931
- async function verifyCodexArtifact(command, provenancePath) {
62932
- if (!isAbsolute(command)) throw new Error("Local compaction requires an absolute codex.command so the selected build can be verified");
62933
- const selectedPath = resolve(command);
62934
- let raw;
62935
- try {
62936
- raw = await readFile(provenancePath, "utf8");
62937
- } catch (error) {
62938
- throw new Error(`Codex provenance is required and could not be read at ${provenancePath}: ${String(error)}`);
62939
- }
62940
- let provenance;
62941
- try {
62942
- provenance = provenanceSchema.parse(JSON.parse(raw));
62943
- } catch (error) {
62944
- throw provenanceError(provenancePath, error instanceof Error ? error.message : String(error));
62945
- }
62946
- await verifyExecutableHashes(selectedPath, provenancePath, provenance.executables["bin/codex-app-server"], provenance.executables["bin/codex-code-mode-host"]);
62947
- }
62948
- async function verifyExecutableHashes(selectedPath, provenancePath, expectedBinaryHash, expectedHelperHash) {
62949
- try {
62950
- if (!(await stat(selectedPath)).isFile()) throw new Error("selected path is not a regular file");
62951
- await access(selectedPath, constants.X_OK);
62952
- } catch (error) {
62953
- throw new Error(`Configured Codex executable cannot be verified at ${selectedPath}: ${String(error)}`);
62954
- }
62955
- if (await sha256(selectedPath) !== expectedBinaryHash) throw provenanceError(provenancePath, `binary hash mismatch for ${selectedPath}`);
62956
- const helper = join(dirname(selectedPath), "codex-code-mode-host");
62957
- await access(helper, constants.X_OK);
62958
- if (await sha256(helper) !== expectedHelperHash) throw provenanceError(provenancePath, "code-mode host hash does not match");
62959
- }
62960
- //#endregion
62961
62890
  //#region apps/partner/runtime/store.ts
62962
62891
  function identityConflict() {
62963
62892
  return Object.assign(/* @__PURE__ */ new Error("Message ID already belongs to different content"), { code: "MESSAGE_IDENTITY_CONFLICT" });
@@ -64725,8 +64654,6 @@ async function convertDshSession(config, inputPath, companionStatePath, attachme
64725
64654
  });
64726
64655
  const injected = dependencies.appServer ?? {};
64727
64656
  const selectedCodexPath = injected.codexPath ?? config.codex.command;
64728
- if (config.codex.local_compaction && !config.codex.provenance) throw new Error("Local compaction requires codex.provenance for the selected custom Codex build");
64729
- if (config.codex.provenance) await verifyCodexArtifact(selectedCodexPath, config.codex.provenance);
64730
64657
  const environment = {
64731
64658
  ...config.codex.home ? { CODEX_HOME: config.codex.home } : {},
64732
64659
  ...injected.env ?? {}
@@ -65939,7 +65866,7 @@ async function createPartner(config, credentials, dependencies = {}) {
65939
65866
  }
65940
65867
  async function refreshBootstrap() {
65941
65868
  const history = (await readRelationshipJournal(paths.relationshipJournal)).reverse();
65942
- const rounds = selectTextRounds([...turns.values()], CONTEXT_TOKEN_BUDGET, 5);
65869
+ const rounds = selectTextRounds([...turns.values()], CONTEXT_TOKEN_BUDGET, config.codex.context_round_limit);
65943
65870
  await writeBootstrapFile(bootstrapPath(paths.workspaceRoot), {
65944
65871
  startupPending,
65945
65872
  context: formatBootstrapContext(stateFromHistory(history)),
@@ -66729,8 +66656,6 @@ async function createPartner(config, credentials, dependencies = {}) {
66729
66656
  await refreshBootstrap();
66730
66657
  const injected = dependencies.appServer ?? {};
66731
66658
  const selectedCodexPath = injected.codexPath ?? config.codex.command;
66732
- if (config.codex.local_compaction && !config.codex.provenance) throw new Error("Local compaction requires codex.provenance for the selected custom Codex build");
66733
- if (config.codex.provenance) await verifyCodexArtifact(selectedCodexPath, config.codex.provenance);
66734
66659
  const environment = {
66735
66660
  ...config.codex.home ? { CODEX_HOME: config.codex.home } : {},
66736
66661
  ...keetEnabled ? { CFL_KEET_TOKEN: credentials.keet } : {},
@@ -68054,8 +67979,7 @@ if (nativePackageRoot) {
68054
67979
  ...config,
68055
67980
  codex: {
68056
67981
  ...config.codex,
68057
- command: join(root, "bin", "codex-app-server"),
68058
- provenance: join(root, "provenance.json")
67982
+ command: join(root, "bin", "codex-app-server")
68059
67983
  }
68060
67984
  };
68061
67985
  }
@@ -22693,13 +22693,14 @@ const schema = object({
22693
22693
  model: string().min(1).default(DEFAULT_CODEX_MODEL),
22694
22694
  version: literal(SUPPORTED_CODEX_VERSION).default(SUPPORTED_CODEX_VERSION),
22695
22695
  home: string().min(1).optional(),
22696
- provenance: string().min(1).optional(),
22697
- local_compaction: boolean().default(false)
22696
+ local_compaction: boolean().default(false),
22697
+ context_round_limit: number().int().min(0).default(10)
22698
22698
  }).strict().default({
22699
22699
  command: "codex-app-server",
22700
22700
  model: DEFAULT_CODEX_MODEL,
22701
22701
  version: SUPPORTED_CODEX_VERSION,
22702
- local_compaction: false
22702
+ local_compaction: false,
22703
+ context_round_limit: 10
22703
22704
  }),
22704
22705
  speech: object({
22705
22706
  endpoint: url().default("https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation"),
@@ -22726,8 +22727,7 @@ async function loadConfig(path) {
22726
22727
  } : void 0,
22727
22728
  codex: {
22728
22729
  ...config.codex,
22729
- home: config.codex.home ? resolve(base, config.codex.home) : void 0,
22730
- provenance: config.codex.provenance ? resolve(base, config.codex.provenance) : void 0
22730
+ home: config.codex.home ? resolve(base, config.codex.home) : void 0
22731
22731
  },
22732
22732
  keet: config.keet ? {
22733
22733
  ...config.keet.endpoint ? { endpoint: keetEndpoint(config.keet.endpoint) } : {},
@@ -1 +0,0 @@
1
- import{i as e,t}from"../chunks/Bg1Ry2sd.js";export{e as load_css,t as start};