@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.
@@ -19,7 +19,6 @@ import { ObjectShape } from '@orkestrel/contract';
19
19
  import { OptionalShape } from '@orkestrel/contract';
20
20
  import { ReasonInterface } from '@orkestrel/reason';
21
21
  import { ReasonValidationResult } from '@orkestrel/reason';
22
- import { RuleResult } from '@orkestrel/reason';
23
22
  import { StringShape } from '@orkestrel/contract';
24
23
  import { Subject } from '@orkestrel/reason';
25
24
 
@@ -180,11 +179,11 @@ import { Subject } from '@orkestrel/reason';
180
179
  * - Every value a borrowed engine returns is OWNED AT ARRIVAL — copied where the value
181
180
  * permits it, sealed in place where it does not — and then read exactly once. What the
182
181
  * engine does with its own object afterwards cannot reach a `Briefing`.
183
- * - Only the VERDICT is shape-checked, because `ReasonInterface.reason` publishes a union
184
- * this package must narrow. The `Interpretation` is owned and not validated: it is a
185
- * 14-member foreign interface with no published guard, and only four of its members are
186
- * read, inside contained code. That asymmetry is deliberate guarding it would trade a
187
- * contained failure for a wrong refusal against a valid engine.
182
+ * - Both returns are shape-checked with their packages' published guards — reasons' logical
183
+ * result guard for the verdict, interprets' interpretation guard at both of the interpret
184
+ * stage's doors. A malformed value at either door records `INTERPRET_FAILED` instead of
185
+ * escaping `compile` as a raw throw, and a supplied interpretation whose snapshot copy
186
+ * loses prototype-carried members is sealed live rather than refused.
188
187
  * - Neither engine is narrowed past its published contract. `Entity.value` is `unknown` and
189
188
  * `LogicalResult` is an interface a class instance satisfies, so a value JSON cannot
190
189
  * express is on-contract and is sealed rather than refused.
@@ -1371,31 +1370,6 @@ import { Subject } from '@orkestrel/reason';
1371
1370
  /** `true` when the value is a non-empty string holding no line terminator. */
1372
1371
  export declare const isLine: Guard<string>;
1373
1372
 
1374
- /**
1375
- * `true` when the value is a well-formed reasons `LogicalResult`.
1376
- *
1377
- * @remarks
1378
- * The gate's reasoner is supplied by the caller through `BriefCompilerOptions.reason`, so its
1379
- * return value is FOREIGN data no matter how well-typed the interface is. `BriefCompiler`
1380
- * dereferences `reasoning`, `conclusion`, and `rules`; checking one field left a malformed
1381
- * result to throw a raw `TypeError` out of `compile`, from the very code that contains stage
1382
- * failures. Total: returns `false` for `undefined`, `null`, and every off-shape value.
1383
- *
1384
- * Checks the WHOLE published shape rather than only the three members read today, because a
1385
- * guard that narrows to `LogicalResult` while ignoring four of its members is unsound.
1386
- *
1387
- * OPEN on unknown keys, deliberately. The exact-record combinator this file uses elsewhere
1388
- * refuses a value a FOREIGN interface permits: `LogicalResult` is a TypeScript interface,
1389
- * so a conforming reasoner returning a richer result is still returning a `LogicalResult`. An
1390
- * exact check refused it and failed the gate closed on a valid engine — trading a loud crash
1391
- * for a wrong refusal, which is the worse of the two. Exactness belongs on records this
1392
- * package OWNS, where an extra key means the caller misunderstood the contract.
1393
- *
1394
- * `count` is checked as a number rather than an integer for the same reason: the published
1395
- * type says `number`, and narrowing past a foreign contract is the same mistake.
1396
- */
1397
- export declare const isLogicalVerdict: Guard<LogicalResult>;
1398
-
1399
1373
  /**
1400
1374
  * `true` when the value is a well-formed `Manifest`.
1401
1375
  *
@@ -1404,22 +1378,6 @@ import { Subject } from '@orkestrel/reason';
1404
1378
  */
1405
1379
  export declare const isManifest: Guard<Manifest>;
1406
1380
 
1407
- /**
1408
- * `true` when the value is a non-null object whose named members can be read.
1409
- *
1410
- * @remarks
1411
- * Wider than the contract package's plain-record guard, which refuses any object carrying its
1412
- * own prototype — a class instance among them. The verdict guards below narrow FOREIGN
1413
- * interfaces, and an
1414
- * interface is satisfied by a class instance as readily as by a literal — refusing one is the
1415
- * same narrowing-past-the-contract mistake that made an exact-record verdict guard fail the
1416
- * gate closed on a valid engine.
1417
- *
1418
- * Arrays are excluded because no interface this narrows is an array, and admitting one would
1419
- * let index access stand in for member access.
1420
- */
1421
- export declare const isObject: Guard<Record<string, unknown>>;
1422
-
1423
1381
  /** `true` when the value is a well-formed `Outcome` — `rank` a positive integer. */
1424
1382
  export declare const isOutcome: Guard<Outcome>;
1425
1383
 
@@ -1441,15 +1399,6 @@ import { Subject } from '@orkestrel/reason';
1441
1399
  /** `true` when the value is one of the three `RiskSeverity` literals. */
1442
1400
  export declare const isRiskSeverity: Guard<RiskSeverity>;
1443
1401
 
1444
- /**
1445
- * `true` when the value is a well-formed reasons `RuleResult`.
1446
- *
1447
- * @remarks
1448
- * `@orkestrel/reason` publishes the type but no guard for it, and `BriefCompiler` reads these
1449
- * off a BORROWED engine's return value, so the shape has to be checked rather than trusted.
1450
- */
1451
- export declare const isRuleVerdict: Guard<RuleResult>;
1452
-
1453
1402
  /** `true` when the value is a well-formed `Task` — both vocabularies closed, statement one line. */
1454
1403
  export declare const isTask: Guard<Task>;
1455
1404
 
@@ -19,7 +19,6 @@ import { ObjectShape } from '@orkestrel/contract';
19
19
  import { OptionalShape } from '@orkestrel/contract';
20
20
  import { ReasonInterface } from '@orkestrel/reason';
21
21
  import { ReasonValidationResult } from '@orkestrel/reason';
22
- import { RuleResult } from '@orkestrel/reason';
23
22
  import { StringShape } from '@orkestrel/contract';
24
23
  import { Subject } from '@orkestrel/reason';
25
24
 
@@ -180,11 +179,11 @@ import { Subject } from '@orkestrel/reason';
180
179
  * - Every value a borrowed engine returns is OWNED AT ARRIVAL — copied where the value
181
180
  * permits it, sealed in place where it does not — and then read exactly once. What the
182
181
  * engine does with its own object afterwards cannot reach a `Briefing`.
183
- * - Only the VERDICT is shape-checked, because `ReasonInterface.reason` publishes a union
184
- * this package must narrow. The `Interpretation` is owned and not validated: it is a
185
- * 14-member foreign interface with no published guard, and only four of its members are
186
- * read, inside contained code. That asymmetry is deliberate guarding it would trade a
187
- * contained failure for a wrong refusal against a valid engine.
182
+ * - Both returns are shape-checked with their packages' published guards — reasons' logical
183
+ * result guard for the verdict, interprets' interpretation guard at both of the interpret
184
+ * stage's doors. A malformed value at either door records `INTERPRET_FAILED` instead of
185
+ * escaping `compile` as a raw throw, and a supplied interpretation whose snapshot copy
186
+ * loses prototype-carried members is sealed live rather than refused.
188
187
  * - Neither engine is narrowed past its published contract. `Entity.value` is `unknown` and
189
188
  * `LogicalResult` is an interface a class instance satisfies, so a value JSON cannot
190
189
  * express is on-contract and is sealed rather than refused.
@@ -1371,31 +1370,6 @@ import { Subject } from '@orkestrel/reason';
1371
1370
  /** `true` when the value is a non-empty string holding no line terminator. */
1372
1371
  export declare const isLine: Guard<string>;
1373
1372
 
1374
- /**
1375
- * `true` when the value is a well-formed reasons `LogicalResult`.
1376
- *
1377
- * @remarks
1378
- * The gate's reasoner is supplied by the caller through `BriefCompilerOptions.reason`, so its
1379
- * return value is FOREIGN data no matter how well-typed the interface is. `BriefCompiler`
1380
- * dereferences `reasoning`, `conclusion`, and `rules`; checking one field left a malformed
1381
- * result to throw a raw `TypeError` out of `compile`, from the very code that contains stage
1382
- * failures. Total: returns `false` for `undefined`, `null`, and every off-shape value.
1383
- *
1384
- * Checks the WHOLE published shape rather than only the three members read today, because a
1385
- * guard that narrows to `LogicalResult` while ignoring four of its members is unsound.
1386
- *
1387
- * OPEN on unknown keys, deliberately. The exact-record combinator this file uses elsewhere
1388
- * refuses a value a FOREIGN interface permits: `LogicalResult` is a TypeScript interface,
1389
- * so a conforming reasoner returning a richer result is still returning a `LogicalResult`. An
1390
- * exact check refused it and failed the gate closed on a valid engine — trading a loud crash
1391
- * for a wrong refusal, which is the worse of the two. Exactness belongs on records this
1392
- * package OWNS, where an extra key means the caller misunderstood the contract.
1393
- *
1394
- * `count` is checked as a number rather than an integer for the same reason: the published
1395
- * type says `number`, and narrowing past a foreign contract is the same mistake.
1396
- */
1397
- export declare const isLogicalVerdict: Guard<LogicalResult>;
1398
-
1399
1373
  /**
1400
1374
  * `true` when the value is a well-formed `Manifest`.
1401
1375
  *
@@ -1404,22 +1378,6 @@ import { Subject } from '@orkestrel/reason';
1404
1378
  */
1405
1379
  export declare const isManifest: Guard<Manifest>;
1406
1380
 
1407
- /**
1408
- * `true` when the value is a non-null object whose named members can be read.
1409
- *
1410
- * @remarks
1411
- * Wider than the contract package's plain-record guard, which refuses any object carrying its
1412
- * own prototype — a class instance among them. The verdict guards below narrow FOREIGN
1413
- * interfaces, and an
1414
- * interface is satisfied by a class instance as readily as by a literal — refusing one is the
1415
- * same narrowing-past-the-contract mistake that made an exact-record verdict guard fail the
1416
- * gate closed on a valid engine.
1417
- *
1418
- * Arrays are excluded because no interface this narrows is an array, and admitting one would
1419
- * let index access stand in for member access.
1420
- */
1421
- export declare const isObject: Guard<Record<string, unknown>>;
1422
-
1423
1381
  /** `true` when the value is a well-formed `Outcome` — `rank` a positive integer. */
1424
1382
  export declare const isOutcome: Guard<Outcome>;
1425
1383
 
@@ -1441,15 +1399,6 @@ import { Subject } from '@orkestrel/reason';
1441
1399
  /** `true` when the value is one of the three `RiskSeverity` literals. */
1442
1400
  export declare const isRiskSeverity: Guard<RiskSeverity>;
1443
1401
 
1444
- /**
1445
- * `true` when the value is a well-formed reasons `RuleResult`.
1446
- *
1447
- * @remarks
1448
- * `@orkestrel/reason` publishes the type but no guard for it, and `BriefCompiler` reads these
1449
- * off a BORROWED engine's return value, so the shape has to be checked rather than trusted.
1450
- */
1451
- export declare const isRuleVerdict: Guard<RuleResult>;
1452
-
1453
1402
  /** `true` when the value is a well-formed `Task` — both vocabularies closed, statement one line. */
1454
1403
  export declare const isTask: Guard<Task>;
1455
1404
 
@@ -1,6 +1,6 @@
1
- import { andOf, arrayOf, arrayShape, attempt, booleanShape, boundsOf, cloneJSONRecord, createContract, integerShape, isBoolean, isInteger, isNonEmptyString, isNumber, isString, literalOf, literalShape, objectShape, optionalShape, parseJSONAs, recordOf, stringShape } from "@orkestrel/contract";
2
- import { canonicalize, collapseWhitespace, createInterpret, digestValue } from "@orkestrel/interpret";
3
- import { atom, compound, createLogicalReasoner, createReason, formatField, logicalDefinition, rule } from "@orkestrel/reason";
1
+ import { andOf, arrayOf, arrayShape, attempt, booleanShape, boundsOf, cloneJSONRecord, createContract, integerShape, isBoolean, isInteger, isNonEmptyString, isString, literalOf, literalShape, objectShape, optionalShape, parseJSONAs, recordOf, stringShape } from "@orkestrel/contract";
2
+ import { canonicalize, collapseWhitespace, createInterpret, digestValue, isInterpretation } from "@orkestrel/interpret";
3
+ import { atom, compound, createLogicalReasoner, createReason, formatField, isLogicalResult, logicalDefinition, rule } from "@orkestrel/reason";
4
4
  import { Emitter } from "@orkestrel/emitter";
5
5
  //#region src/core/constants.ts
6
6
  /** The twelve `TaskOperation` values, frozen. */
@@ -259,53 +259,6 @@ var isTaskDomain = literalOf(TASK_DOMAINS);
259
259
  var isOutputFormat = literalOf(OUTPUT_FORMATS);
260
260
  /** `true` when the value is one of the three `RiskSeverity` literals. */
261
261
  var isRiskSeverity = literalOf(RISK_SEVERITIES);
262
- /**
263
- * `true` when the value is a non-null object whose named members can be read.
264
- *
265
- * @remarks
266
- * Wider than the contract package's plain-record guard, which refuses any object carrying its
267
- * own prototype — a class instance among them. The verdict guards below narrow FOREIGN
268
- * interfaces, and an
269
- * interface is satisfied by a class instance as readily as by a literal — refusing one is the
270
- * same narrowing-past-the-contract mistake that made an exact-record verdict guard fail the
271
- * gate closed on a valid engine.
272
- *
273
- * Arrays are excluded because no interface this narrows is an array, and admitting one would
274
- * let index access stand in for member access.
275
- */
276
- var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
277
- /**
278
- * `true` when the value is a well-formed reasons `RuleResult`.
279
- *
280
- * @remarks
281
- * `@orkestrel/reason` publishes the type but no guard for it, and `BriefCompiler` reads these
282
- * off a BORROWED engine's return value, so the shape has to be checked rather than trusted.
283
- */
284
- var isRuleVerdict = (value) => isObject(value) && isNonEmptyString(value["id"]) && isBoolean(value["applied"]) && arrayOf(isBoolean)(value["premises"]) && isBoolean(value["conclusion"]);
285
- /**
286
- * `true` when the value is a well-formed reasons `LogicalResult`.
287
- *
288
- * @remarks
289
- * The gate's reasoner is supplied by the caller through `BriefCompilerOptions.reason`, so its
290
- * return value is FOREIGN data no matter how well-typed the interface is. `BriefCompiler`
291
- * dereferences `reasoning`, `conclusion`, and `rules`; checking one field left a malformed
292
- * result to throw a raw `TypeError` out of `compile`, from the very code that contains stage
293
- * failures. Total: returns `false` for `undefined`, `null`, and every off-shape value.
294
- *
295
- * Checks the WHOLE published shape rather than only the three members read today, because a
296
- * guard that narrows to `LogicalResult` while ignoring four of its members is unsound.
297
- *
298
- * OPEN on unknown keys, deliberately. The exact-record combinator this file uses elsewhere
299
- * refuses a value a FOREIGN interface permits: `LogicalResult` is a TypeScript interface,
300
- * so a conforming reasoner returning a richer result is still returning a `LogicalResult`. An
301
- * exact check refused it and failed the gate closed on a valid engine — trading a loud crash
302
- * for a wrong refusal, which is the worse of the two. Exactness belongs on records this
303
- * package OWNS, where an extra key means the caller misunderstood the contract.
304
- *
305
- * `count` is checked as a number rather than an integer for the same reason: the published
306
- * type says `number`, and narrowing past a foreign contract is the same mistake.
307
- */
308
- var isLogicalVerdict = (value) => isObject(value) && value["reasoning"] === "logical" && isBoolean(value["conclusion"]) && arrayOf(isRuleVerdict)(value["rules"]) && isNumber(value["count"]) && isBoolean(value["success"]) && arrayOf(isString)(value["trace"]) && arrayOf(isString)(value["errors"]);
309
262
  /** `true` when the value is a well-formed `Task` — both vocabularies closed, statement one line. */
310
263
  var isTask = recordOf({
311
264
  operation: isTaskOperation,
@@ -1834,7 +1787,7 @@ var BriefCompiler = class {
1834
1787
  return this.#refuse(void 0, void 0, [], void 0, stages, failures);
1835
1788
  }
1836
1789
  const owned = taken.value;
1837
- const interpretation = this.#read(owned, stages, failures);
1790
+ const interpretation = this.#read(owned, input, stages, failures);
1838
1791
  const drafted = attempt(() => this.#draft(owned, interpretation, this.#unresolved(interpretation, failures)));
1839
1792
  if (!drafted.success) {
1840
1793
  const message = errorToMessage(drafted.error);
@@ -1932,7 +1885,7 @@ var BriefCompiler = class {
1932
1885
  field: "reason"
1933
1886
  });
1934
1887
  const verdict = ruled.value;
1935
- if (!isLogicalVerdict(verdict)) throw new BriefError("GATE_FAILED", "The gate reasoner returned a non-logical result", {
1888
+ if (!isLogicalResult(verdict)) throw new BriefError("GATE_FAILED", "The gate reasoner returned a non-logical result", {
1936
1889
  stage: "gate",
1937
1890
  field: "reasoning"
1938
1891
  });
@@ -1953,22 +1906,39 @@ var BriefCompiler = class {
1953
1906
  const cloned = attempt(() => structuredClone(value));
1954
1907
  return freezeDeep(cloned.success ? cloned.value : value);
1955
1908
  }
1956
- #read(input, stages, failures) {
1909
+ #read(input, raw, stages, failures) {
1957
1910
  const text = input.text;
1958
- if (text === void 0) return input.interpretation;
1959
- const read = attempt(() => this.#own(this.#interpret.interpret(text)));
1960
- if (read.success) {
1911
+ if (text !== void 0) {
1912
+ const read = attempt(() => this.#own(this.#interpret.interpret(text)));
1913
+ if (read.success && isInterpretation(read.value)) {
1914
+ stages.push(Object.freeze({
1915
+ stage: "interpret",
1916
+ input: text,
1917
+ output: read.value
1918
+ }));
1919
+ return read.value;
1920
+ }
1921
+ const message = read.success ? "The interpret engine returned a non-interpretation result" : errorToMessage(read.error);
1961
1922
  stages.push(Object.freeze({
1962
1923
  stage: "interpret",
1963
1924
  input: text,
1964
- output: read.value
1925
+ error: message
1926
+ }));
1927
+ failures.push(Object.freeze({
1928
+ stage: "interpret",
1929
+ code: "INTERPRET_FAILED",
1930
+ message
1965
1931
  }));
1966
- return read.value;
1932
+ this.#emitter.emit("error", read.success ? new BriefError("INTERPRET_FAILED", message, { stage: "interpret" }) : read.error);
1967
1933
  }
1968
- const message = errorToMessage(read.error);
1934
+ const supplied = input.interpretation;
1935
+ if (supplied === void 0 || isInterpretation(supplied)) return supplied;
1936
+ const live = raw.interpretation;
1937
+ if (live !== void 0 && isInterpretation(live)) return freezeDeep(live);
1938
+ const message = "The supplied interpretation does not satisfy the published shape";
1969
1939
  stages.push(Object.freeze({
1970
1940
  stage: "interpret",
1971
- input: text,
1941
+ input: "interpretation",
1972
1942
  error: message
1973
1943
  }));
1974
1944
  failures.push(Object.freeze({
@@ -1976,8 +1946,6 @@ var BriefCompiler = class {
1976
1946
  code: "INTERPRET_FAILED",
1977
1947
  message
1978
1948
  }));
1979
- this.#emitter.emit("error", read.error);
1980
- return input.interpretation;
1981
1949
  }
1982
1950
  #blockage(questions, unready, verdict) {
1983
1951
  if (questions.length > 0) return {
@@ -1990,7 +1958,7 @@ var BriefCompiler = class {
1990
1958
  code: "BLOCKED",
1991
1959
  message: `Gate refused: ${unready.join(", ")}`
1992
1960
  };
1993
- if (!isLogicalVerdict(verdict)) return void 0;
1961
+ if (!isLogicalResult(verdict)) return void 0;
1994
1962
  const refused = verdict.rules.filter((entry) => !entry.conclusion).map((entry) => entry.id).join(", ");
1995
1963
  if (refused.length === 0) return {
1996
1964
  stage: "gate",
@@ -2124,6 +2092,6 @@ function createBriefContract() {
2124
2092
  return createContract(briefShape);
2125
2093
  }
2126
2094
  //#endregion
2127
- export { BLANK_PATTERN, BriefCompiler, BriefError, BriefManager, DEFAULT_BRIEF_TURNS, GATE_ID, LINE_BREAK_PATTERN, OUTPUT_FORMATS, RISK_SEVERITIES, SINGLE_LINE_PATTERN, TASK_DOMAINS, TASK_OPERATIONS, assertBrief, brief, briefShape, briefToContent, briefToDispatch, briefToGoal, briefToHash, briefToMarkdown, briefToSubject, briefToTrace, citation, citationShape, countSentences, createBriefCompiler, createBriefContract, createBriefManager, deriveGaps, deriveGivens, deriveStatement, deriveTask, errorToMessage, example, exampleShape, exampleToLines, findBlockingGaps, findManifestOverlaps, findUngrantedAuthority, findUnmetRules, findUnpairedGaps, freezeBranch, freezeDeep, gap, gapShape, gateDefinition, given, givenShape, isBrief, isBriefError, isCitation, isExample, isGap, isGiven, isLine, isLogicalVerdict, isManifest, isObject, isOutcome, isOutput, isOutputFormat, isProof, isReference, isRisk, isRiskSeverity, isRuleVerdict, isTask, isTaskDomain, isTaskOperation, isText, lineShape, manifest, manifestShape, outcome, outcomeShape, output, outputShape, parseBrief, pinBrief, proof, proofShape, reference, referenceShape, risk, riskShape, snapshotBrief, task, taskShape, textShape, validateBrief };
2095
+ export { BLANK_PATTERN, BriefCompiler, BriefError, BriefManager, DEFAULT_BRIEF_TURNS, GATE_ID, LINE_BREAK_PATTERN, OUTPUT_FORMATS, RISK_SEVERITIES, SINGLE_LINE_PATTERN, TASK_DOMAINS, TASK_OPERATIONS, assertBrief, brief, briefShape, briefToContent, briefToDispatch, briefToGoal, briefToHash, briefToMarkdown, briefToSubject, briefToTrace, citation, citationShape, countSentences, createBriefCompiler, createBriefContract, createBriefManager, deriveGaps, deriveGivens, deriveStatement, deriveTask, errorToMessage, example, exampleShape, exampleToLines, findBlockingGaps, findManifestOverlaps, findUngrantedAuthority, findUnmetRules, findUnpairedGaps, freezeBranch, freezeDeep, gap, gapShape, gateDefinition, given, givenShape, isBrief, isBriefError, isCitation, isExample, isGap, isGiven, isLine, isManifest, isOutcome, isOutput, isOutputFormat, isProof, isReference, isRisk, isRiskSeverity, isTask, isTaskDomain, isTaskOperation, isText, lineShape, manifest, manifestShape, outcome, outcomeShape, output, outputShape, parseBrief, pinBrief, proof, proofShape, reference, referenceShape, risk, riskShape, snapshotBrief, task, taskShape, textShape, validateBrief };
2128
2096
 
2129
2097
  //# sourceMappingURL=index.js.map