@orkestrel/brief 0.0.1 → 0.0.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.
@@ -260,53 +260,6 @@ var isTaskDomain = (0, _orkestrel_contract.literalOf)(TASK_DOMAINS);
260
260
  var isOutputFormat = (0, _orkestrel_contract.literalOf)(OUTPUT_FORMATS);
261
261
  /** `true` when the value is one of the three `RiskSeverity` literals. */
262
262
  var isRiskSeverity = (0, _orkestrel_contract.literalOf)(RISK_SEVERITIES);
263
- /**
264
- * `true` when the value is a non-null object whose named members can be read.
265
- *
266
- * @remarks
267
- * Wider than the contract package's plain-record guard, which refuses any object carrying its
268
- * own prototype — a class instance among them. The verdict guards below narrow FOREIGN
269
- * interfaces, and an
270
- * interface is satisfied by a class instance as readily as by a literal — refusing one is the
271
- * same narrowing-past-the-contract mistake that made an exact-record verdict guard fail the
272
- * gate closed on a valid engine.
273
- *
274
- * Arrays are excluded because no interface this narrows is an array, and admitting one would
275
- * let index access stand in for member access.
276
- */
277
- var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
278
- /**
279
- * `true` when the value is a well-formed reasons `RuleResult`.
280
- *
281
- * @remarks
282
- * `@orkestrel/reason` publishes the type but no guard for it, and `BriefCompiler` reads these
283
- * off a BORROWED engine's return value, so the shape has to be checked rather than trusted.
284
- */
285
- var isRuleVerdict = (value) => isObject(value) && (0, _orkestrel_contract.isNonEmptyString)(value["id"]) && (0, _orkestrel_contract.isBoolean)(value["applied"]) && (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isBoolean)(value["premises"]) && (0, _orkestrel_contract.isBoolean)(value["conclusion"]);
286
- /**
287
- * `true` when the value is a well-formed reasons `LogicalResult`.
288
- *
289
- * @remarks
290
- * The gate's reasoner is supplied by the caller through `BriefCompilerOptions.reason`, so its
291
- * return value is FOREIGN data no matter how well-typed the interface is. `BriefCompiler`
292
- * dereferences `reasoning`, `conclusion`, and `rules`; checking one field left a malformed
293
- * result to throw a raw `TypeError` out of `compile`, from the very code that contains stage
294
- * failures. Total: returns `false` for `undefined`, `null`, and every off-shape value.
295
- *
296
- * Checks the WHOLE published shape rather than only the three members read today, because a
297
- * guard that narrows to `LogicalResult` while ignoring four of its members is unsound.
298
- *
299
- * OPEN on unknown keys, deliberately. The exact-record combinator this file uses elsewhere
300
- * refuses a value a FOREIGN interface permits: `LogicalResult` is a TypeScript interface,
301
- * so a conforming reasoner returning a richer result is still returning a `LogicalResult`. An
302
- * exact check refused it and failed the gate closed on a valid engine — trading a loud crash
303
- * for a wrong refusal, which is the worse of the two. Exactness belongs on records this
304
- * package OWNS, where an extra key means the caller misunderstood the contract.
305
- *
306
- * `count` is checked as a number rather than an integer for the same reason: the published
307
- * type says `number`, and narrowing past a foreign contract is the same mistake.
308
- */
309
- var isLogicalVerdict = (value) => isObject(value) && value["reasoning"] === "logical" && (0, _orkestrel_contract.isBoolean)(value["conclusion"]) && (0, _orkestrel_contract.arrayOf)(isRuleVerdict)(value["rules"]) && (0, _orkestrel_contract.isNumber)(value["count"]) && (0, _orkestrel_contract.isBoolean)(value["success"]) && (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isString)(value["trace"]) && (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isString)(value["errors"]);
310
263
  /** `true` when the value is a well-formed `Task` — both vocabularies closed, statement one line. */
311
264
  var isTask = (0, _orkestrel_contract.recordOf)({
312
265
  operation: isTaskOperation,
@@ -1835,7 +1788,7 @@ var BriefCompiler = class {
1835
1788
  return this.#refuse(void 0, void 0, [], void 0, stages, failures);
1836
1789
  }
1837
1790
  const owned = taken.value;
1838
- const interpretation = this.#read(owned, stages, failures);
1791
+ const interpretation = this.#read(owned, input, stages, failures);
1839
1792
  const drafted = (0, _orkestrel_contract.attempt)(() => this.#draft(owned, interpretation, this.#unresolved(interpretation, failures)));
1840
1793
  if (!drafted.success) {
1841
1794
  const message = errorToMessage(drafted.error);
@@ -1933,7 +1886,7 @@ var BriefCompiler = class {
1933
1886
  field: "reason"
1934
1887
  });
1935
1888
  const verdict = ruled.value;
1936
- if (!isLogicalVerdict(verdict)) throw new BriefError("GATE_FAILED", "The gate reasoner returned a non-logical result", {
1889
+ if (!(0, _orkestrel_reason.isLogicalResult)(verdict)) throw new BriefError("GATE_FAILED", "The gate reasoner returned a non-logical result", {
1937
1890
  stage: "gate",
1938
1891
  field: "reasoning"
1939
1892
  });
@@ -1954,22 +1907,39 @@ var BriefCompiler = class {
1954
1907
  const cloned = (0, _orkestrel_contract.attempt)(() => structuredClone(value));
1955
1908
  return freezeDeep(cloned.success ? cloned.value : value);
1956
1909
  }
1957
- #read(input, stages, failures) {
1910
+ #read(input, raw, stages, failures) {
1958
1911
  const text = input.text;
1959
- if (text === void 0) return input.interpretation;
1960
- const read = (0, _orkestrel_contract.attempt)(() => this.#own(this.#interpret.interpret(text)));
1961
- if (read.success) {
1912
+ if (text !== void 0) {
1913
+ const read = (0, _orkestrel_contract.attempt)(() => this.#own(this.#interpret.interpret(text)));
1914
+ if (read.success && (0, _orkestrel_interpret.isInterpretation)(read.value)) {
1915
+ stages.push(Object.freeze({
1916
+ stage: "interpret",
1917
+ input: text,
1918
+ output: read.value
1919
+ }));
1920
+ return read.value;
1921
+ }
1922
+ const message = read.success ? "The interpret engine returned a non-interpretation result" : errorToMessage(read.error);
1962
1923
  stages.push(Object.freeze({
1963
1924
  stage: "interpret",
1964
1925
  input: text,
1965
- output: read.value
1926
+ error: message
1927
+ }));
1928
+ failures.push(Object.freeze({
1929
+ stage: "interpret",
1930
+ code: "INTERPRET_FAILED",
1931
+ message
1966
1932
  }));
1967
- return read.value;
1933
+ this.#emitter.emit("error", read.success ? new BriefError("INTERPRET_FAILED", message, { stage: "interpret" }) : read.error);
1968
1934
  }
1969
- const message = errorToMessage(read.error);
1935
+ const supplied = input.interpretation;
1936
+ if (supplied === void 0 || (0, _orkestrel_interpret.isInterpretation)(supplied)) return supplied;
1937
+ const live = raw.interpretation;
1938
+ if (live !== void 0 && (0, _orkestrel_interpret.isInterpretation)(live)) return freezeDeep(live);
1939
+ const message = "The supplied interpretation does not satisfy the published shape";
1970
1940
  stages.push(Object.freeze({
1971
1941
  stage: "interpret",
1972
- input: text,
1942
+ input: "interpretation",
1973
1943
  error: message
1974
1944
  }));
1975
1945
  failures.push(Object.freeze({
@@ -1977,8 +1947,6 @@ var BriefCompiler = class {
1977
1947
  code: "INTERPRET_FAILED",
1978
1948
  message
1979
1949
  }));
1980
- this.#emitter.emit("error", read.error);
1981
- return input.interpretation;
1982
1950
  }
1983
1951
  #blockage(questions, unready, verdict) {
1984
1952
  if (questions.length > 0) return {
@@ -1991,7 +1959,7 @@ var BriefCompiler = class {
1991
1959
  code: "BLOCKED",
1992
1960
  message: `Gate refused: ${unready.join(", ")}`
1993
1961
  };
1994
- if (!isLogicalVerdict(verdict)) return void 0;
1962
+ if (!(0, _orkestrel_reason.isLogicalResult)(verdict)) return void 0;
1995
1963
  const refused = verdict.rules.filter((entry) => !entry.conclusion).map((entry) => entry.id).join(", ");
1996
1964
  if (refused.length === 0) return {
1997
1965
  stage: "gate",
@@ -2180,9 +2148,7 @@ exports.isExample = isExample;
2180
2148
  exports.isGap = isGap;
2181
2149
  exports.isGiven = isGiven;
2182
2150
  exports.isLine = isLine;
2183
- exports.isLogicalVerdict = isLogicalVerdict;
2184
2151
  exports.isManifest = isManifest;
2185
- exports.isObject = isObject;
2186
2152
  exports.isOutcome = isOutcome;
2187
2153
  exports.isOutput = isOutput;
2188
2154
  exports.isOutputFormat = isOutputFormat;
@@ -2190,7 +2156,6 @@ exports.isProof = isProof;
2190
2156
  exports.isReference = isReference;
2191
2157
  exports.isRisk = isRisk;
2192
2158
  exports.isRiskSeverity = isRiskSeverity;
2193
- exports.isRuleVerdict = isRuleVerdict;
2194
2159
  exports.isTask = isTask;
2195
2160
  exports.isTaskDomain = isTaskDomain;
2196
2161
  exports.isTaskOperation = isTaskOperation;