@optique/core 1.3.0-dev.2381 → 1.3.0-dev.2383

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.
@@ -130,7 +130,8 @@ function isDeferredCompletionResult(result) {
130
130
  function settledPreCompletedKeys(preCompleted) {
131
131
  const keys = /* @__PURE__ */ new Set();
132
132
  for (const [key, result] of preCompleted) {
133
- if (isDeferredCompletionResult(result)) continue;
133
+ const completion = require_internal_dependency.isDependencySourceState(result) ? result.result : result;
134
+ if (isDeferredCompletionResult(completion)) continue;
134
135
  keys.add(key);
135
136
  }
136
137
  return keys;
@@ -145,7 +146,10 @@ function settledPreCompletedKeys(preCompleted) {
145
146
  * immediately.
146
147
  */
147
148
  function firstPreCompletedFailure(preCompleted) {
148
- for (const result of preCompleted.values()) if (typeof result === "object" && result !== null && "success" in result && result.success === false && "error" in result) return result.error;
149
+ for (const result of preCompleted.values()) {
150
+ const completion = require_internal_dependency.isDependencySourceState(result) ? result.result : result;
151
+ if (typeof completion === "object" && completion !== null && "success" in completion && completion.success === false && "error" in completion) return completion.error;
152
+ }
149
153
  return void 0;
150
154
  }
151
155
  async function scheduleEffectfulSourceCompletions(nodes, state, runtime, exec, preCompleted, demandNodes) {
@@ -130,7 +130,8 @@ function isDeferredCompletionResult(result) {
130
130
  function settledPreCompletedKeys(preCompleted) {
131
131
  const keys = /* @__PURE__ */ new Set();
132
132
  for (const [key, result] of preCompleted) {
133
- if (isDeferredCompletionResult(result)) continue;
133
+ const completion = isDependencySourceState(result) ? result.result : result;
134
+ if (isDeferredCompletionResult(completion)) continue;
134
135
  keys.add(key);
135
136
  }
136
137
  return keys;
@@ -145,7 +146,10 @@ function settledPreCompletedKeys(preCompleted) {
145
146
  * immediately.
146
147
  */
147
148
  function firstPreCompletedFailure(preCompleted) {
148
- for (const result of preCompleted.values()) if (typeof result === "object" && result !== null && "success" in result && result.success === false && "error" in result) return result.error;
149
+ for (const result of preCompleted.values()) {
150
+ const completion = isDependencySourceState(result) ? result.result : result;
151
+ if (typeof completion === "object" && completion !== null && "success" in completion && completion.success === false && "error" in completion) return completion.error;
152
+ }
149
153
  return void 0;
150
154
  }
151
155
  async function scheduleEffectfulSourceCompletions(nodes, state, runtime, exec, preCompleted, demandNodes) {
@@ -679,15 +679,7 @@ async function completeEffectfulSourcesAsync(nodes, state, runtime, exec, option
679
679
  * length-prefixed segments so no separator escaping is needed.
680
680
  */
681
681
  function serializeSchedulingPath(path) {
682
- return path.map((segment) => {
683
- if (typeof segment === "symbol") {
684
- const key = stableSymbolKey(segment);
685
- return `y${key.length}:${key}`;
686
- }
687
- const tag = typeof segment === "number" ? "n" : "s";
688
- const text = String(segment);
689
- return `${tag}${text.length}:${text}`;
690
- }).join("");
682
+ return path.map(serializePathSegment).join("");
691
683
  }
692
684
  /**
693
685
  * Checks if a value is a plain object (not a class instance) for the
@@ -679,15 +679,7 @@ async function completeEffectfulSourcesAsync(nodes, state, runtime, exec, option
679
679
  * length-prefixed segments so no separator escaping is needed.
680
680
  */
681
681
  function serializeSchedulingPath(path) {
682
- return path.map((segment) => {
683
- if (typeof segment === "symbol") {
684
- const key = stableSymbolKey(segment);
685
- return `y${key.length}:${key}`;
686
- }
687
- const tag = typeof segment === "number" ? "n" : "s";
688
- const text = String(segment);
689
- return `${tag}${text.length}:${text}`;
690
- }).join("");
682
+ return path.map(serializePathSegment).join("");
691
683
  }
692
684
  /**
693
685
  * Checks if a value is a plain object (not a class instance) for the
package/dist/facade.cjs CHANGED
@@ -126,6 +126,31 @@ function withEffectfulSessionOption(options, session) {
126
126
  [effectfulSessionOptionsKey]: session
127
127
  };
128
128
  }
129
+ /**
130
+ * Creates the run-scoped effectful completion sessions shared by a
131
+ * `runWith()` two-phase run, so an effectful source (e.g., a prompt)
132
+ * runs at most once per invocation. The seed pass uses the demand-only
133
+ * policy: an effectful source completes there only when a phase-one
134
+ * consumer demands its value; others defer to the final pass. The
135
+ * final pass shares the run-scoped results cache and demand set, but
136
+ * recomputes structural precedence from scratch: phase-two annotations
137
+ * may introduce environment/configuration values that must win over a
138
+ * cached seed prompt answer, so the effectful-source markers do not
139
+ * carry over.
140
+ */
141
+ function createRunWithSessions() {
142
+ const seedSession = require_internal_parser.createEffectfulCompletionSession("demand-only");
143
+ const finalSession = {
144
+ ...seedSession,
145
+ policy: "eager",
146
+ effectfulSources: /* @__PURE__ */ new Set(),
147
+ completedByPath: /* @__PURE__ */ new Map()
148
+ };
149
+ return {
150
+ seedSession,
151
+ finalSession
152
+ };
153
+ }
129
154
  function createCompleteExec(exec, context, session) {
130
155
  const runtime = require_dependency_runtime.createDependencyRuntimeContext();
131
156
  return {
@@ -1615,13 +1640,7 @@ async function runWithBody(parser, programName, contexts, args, options) {
1615
1640
  if (parser.mode === "async") return runParser(augmentedParser1, programName, args, options);
1616
1641
  return Promise.resolve(runParser(augmentedParser1, programName, args, options));
1617
1642
  }
1618
- const seedSession = require_internal_parser.createEffectfulCompletionSession("demand-only");
1619
- const finalSession = {
1620
- ...seedSession,
1621
- policy: "eager",
1622
- effectfulSources: /* @__PURE__ */ new Set(),
1623
- completedByPath: /* @__PURE__ */ new Map()
1624
- };
1643
+ const { seedSession, finalSession } = createRunWithSessions();
1625
1644
  const sessionOptions = withEffectfulSessionOption(options, finalSession);
1626
1645
  const firstPassSeed = await require_mode_dispatch.dispatchByMode(parser.mode, () => extractPhase2SeedSync(augmentedParser1, args, seedSession), () => extractPhase2SeedAsync(augmentedParser1, args, seedSession));
1627
1646
  if (firstPassSeed == null) {
@@ -1738,13 +1757,7 @@ function runWithSyncBody(parser, programName, contexts, args, options) {
1738
1757
  }
1739
1758
  const augmentedParser1 = injectAnnotationsIntoParser(parser, phase1Annotations);
1740
1759
  if (!needsTwoPhase) return runParser(augmentedParser1, programName, args, options);
1741
- const seedSession = require_internal_parser.createEffectfulCompletionSession("demand-only");
1742
- const finalSession = {
1743
- ...seedSession,
1744
- policy: "eager",
1745
- effectfulSources: /* @__PURE__ */ new Set(),
1746
- completedByPath: /* @__PURE__ */ new Map()
1747
- };
1760
+ const { seedSession, finalSession } = createRunWithSessions();
1748
1761
  const sessionOptions = withEffectfulSessionOption(options, finalSession);
1749
1762
  const firstPassSeed = extractPhase2SeedSync(augmentedParser1, args, seedSession);
1750
1763
  if (firstPassSeed == null) {
package/dist/facade.js CHANGED
@@ -126,6 +126,31 @@ function withEffectfulSessionOption(options, session) {
126
126
  [effectfulSessionOptionsKey]: session
127
127
  };
128
128
  }
129
+ /**
130
+ * Creates the run-scoped effectful completion sessions shared by a
131
+ * `runWith()` two-phase run, so an effectful source (e.g., a prompt)
132
+ * runs at most once per invocation. The seed pass uses the demand-only
133
+ * policy: an effectful source completes there only when a phase-one
134
+ * consumer demands its value; others defer to the final pass. The
135
+ * final pass shares the run-scoped results cache and demand set, but
136
+ * recomputes structural precedence from scratch: phase-two annotations
137
+ * may introduce environment/configuration values that must win over a
138
+ * cached seed prompt answer, so the effectful-source markers do not
139
+ * carry over.
140
+ */
141
+ function createRunWithSessions() {
142
+ const seedSession = createEffectfulCompletionSession("demand-only");
143
+ const finalSession = {
144
+ ...seedSession,
145
+ policy: "eager",
146
+ effectfulSources: /* @__PURE__ */ new Set(),
147
+ completedByPath: /* @__PURE__ */ new Map()
148
+ };
149
+ return {
150
+ seedSession,
151
+ finalSession
152
+ };
153
+ }
129
154
  function createCompleteExec(exec, context, session) {
130
155
  const runtime = createDependencyRuntimeContext();
131
156
  return {
@@ -1615,13 +1640,7 @@ async function runWithBody(parser, programName, contexts, args, options) {
1615
1640
  if (parser.mode === "async") return runParser(augmentedParser1, programName, args, options);
1616
1641
  return Promise.resolve(runParser(augmentedParser1, programName, args, options));
1617
1642
  }
1618
- const seedSession = createEffectfulCompletionSession("demand-only");
1619
- const finalSession = {
1620
- ...seedSession,
1621
- policy: "eager",
1622
- effectfulSources: /* @__PURE__ */ new Set(),
1623
- completedByPath: /* @__PURE__ */ new Map()
1624
- };
1643
+ const { seedSession, finalSession } = createRunWithSessions();
1625
1644
  const sessionOptions = withEffectfulSessionOption(options, finalSession);
1626
1645
  const firstPassSeed = await dispatchByMode(parser.mode, () => extractPhase2SeedSync(augmentedParser1, args, seedSession), () => extractPhase2SeedAsync(augmentedParser1, args, seedSession));
1627
1646
  if (firstPassSeed == null) {
@@ -1738,13 +1757,7 @@ function runWithSyncBody(parser, programName, contexts, args, options) {
1738
1757
  }
1739
1758
  const augmentedParser1 = injectAnnotationsIntoParser(parser, phase1Annotations);
1740
1759
  if (!needsTwoPhase) return runParser(augmentedParser1, programName, args, options);
1741
- const seedSession = createEffectfulCompletionSession("demand-only");
1742
- const finalSession = {
1743
- ...seedSession,
1744
- policy: "eager",
1745
- effectfulSources: /* @__PURE__ */ new Set(),
1746
- completedByPath: /* @__PURE__ */ new Map()
1747
- };
1760
+ const { seedSession, finalSession } = createRunWithSessions();
1748
1761
  const sessionOptions = withEffectfulSessionOption(options, finalSession);
1749
1762
  const firstPassSeed = extractPhase2SeedSync(augmentedParser1, args, seedSession);
1750
1763
  if (firstPassSeed == null) {
@@ -419,9 +419,9 @@ type ExecutionPhase = "parse" | "precomplete" | "resolve" | "complete" | "sugges
419
419
  * run, shared by the phase-two seed pass and the final pass) and threaded
420
420
  * through {@link ExecutionContext}. It guarantees that an effectful source
421
421
  * completion runs at most once per run: the completion result is cached by
422
- * dependency source ID, and a cache hit is returned without repeating the
423
- * effect. Results never leak between runs because the session is discarded
424
- * when the run ends.
422
+ * completion occurrence (see {@link EffectfulCompletionSession.results}),
423
+ * and a cache hit is returned without repeating the effect. Results never
424
+ * leak between runs because the session is discarded when the run ends.
425
425
  *
426
426
  * @internal
427
427
  * @since 1.3.0
@@ -419,9 +419,9 @@ type ExecutionPhase = "parse" | "precomplete" | "resolve" | "complete" | "sugges
419
419
  * run, shared by the phase-two seed pass and the final pass) and threaded
420
420
  * through {@link ExecutionContext}. It guarantees that an effectful source
421
421
  * completion runs at most once per run: the completion result is cached by
422
- * dependency source ID, and a cache hit is returned without repeating the
423
- * effect. Results never leak between runs because the session is discarded
424
- * when the run ends.
422
+ * completion occurrence (see {@link EffectfulCompletionSession.results}),
423
+ * and a cache hit is returned without repeating the effect. Results never
424
+ * leak between runs because the session is discarded when the run ends.
425
425
  *
426
426
  * @internal
427
427
  * @since 1.3.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.3.0-dev.2381",
3
+ "version": "1.3.0-dev.2383",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -221,7 +221,7 @@
221
221
  },
222
222
  "sideEffects": false,
223
223
  "devDependencies": {
224
- "@optique/env": "1.3.0-dev.2381+b37c0393",
224
+ "@optique/env": "1.3.0-dev.2383+4053ebf3",
225
225
  "@types/node": "^24.0.0",
226
226
  "fast-check": "^4.7.0",
227
227
  "tsdown": "^0.13.0",