@orkestrel/scaffold 0.0.117 → 0.0.119

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.
@@ -12,7 +12,13 @@ import {
12
12
  hasCanonicalSegments,
13
13
  resolveLink,
14
14
  } from '@orkestrel/guide'
15
- import { BASE_DEV_DEPENDENCIES, DISTRIBUTION_SETUP_PATH, HOST_PATHS } from '@orkestrel/scaffold'
15
+ import {
16
+ BASE_DEV_DEPENDENCIES,
17
+ DISTRIBUTION_SETUP_PATH,
18
+ HOST_INVENTORY_PATH,
19
+ HOST_PATHS,
20
+ } from '@orkestrel/scaffold'
21
+ import { MANIFEST_NAME, readSurfaceBaseline } from '@orkestrel/scaffold/server'
16
22
  import { spawnSync } from 'node:child_process'
17
23
  import { createRequire } from 'node:module'
18
24
  import {
@@ -3737,8 +3743,10 @@ export function readPolicySurface(root: string): PolicySurfacePopulation {
3737
3743
  * Inspects source and target-owned setup names against the hosted fleet guides.
3738
3744
  *
3739
3745
  * @remarks
3740
- * Source names claimed by the target's own hosted guide are grandfathered. Setup names have no
3741
- * grandfather. Catalog rows come from beside the guides: when reading installed guides, from the
3746
+ * Source names claimed by the target's own hosted guide are grandfathered, and so are source names
3747
+ * whose collision record names the target as an owner: the installed host's `manifest.json` in a
3748
+ * target, and the committed `host.json` in the scaffold checkout. A malformed record throws. Setup
3749
+ * names have no grandfather. Catalog rows come from beside the guides: when reading installed guides, from the
3742
3750
  * staged catalog and never from the target's own table, which can list a package without a guide in
3743
3751
  * that host. An absent installed host falls back to checkout guides only with catalog coverage.
3744
3752
  * Missing comparison evidence and unread barrel statements produce surface violations.
@@ -3804,9 +3812,13 @@ export function inspectPolicySurface(root: string): readonly PolicyViolation[] {
3804
3812
  ]
3805
3813
  },
3806
3814
  )
3807
- const grandfather = new Set(
3808
- guides.filter((guide) => guide.owner === own).flatMap(({ symbols }) => symbols),
3809
- )
3815
+ const record = readSurfaceBaseline(host, hosted ? MANIFEST_NAME : HOST_INVENTORY_PATH) ?? []
3816
+ const grandfather = new Set([
3817
+ ...guides.filter((guide) => guide.owner === own).flatMap(({ symbols }) => symbols),
3818
+ ...record
3819
+ .filter(({ owners }) => own !== undefined && owners.includes(own))
3820
+ .map(({ name }) => name),
3821
+ ])
3810
3822
  const claimed = Map.groupBy(
3811
3823
  guides
3812
3824
  .filter((guide) => guide.owner !== own)
@@ -4,7 +4,7 @@ let _orkestrel_template = require("@orkestrel/template");
4
4
  let _orkestrel_emitter = require("@orkestrel/emitter");
5
5
  var package_default = {
6
6
  name: "@orkestrel/scaffold",
7
- version: "0.0.117",
7
+ version: "0.0.119",
8
8
  description: "Scaffold workspaces with commands: new, audit, surface, repair, catalog, and overwrite.",
9
9
  keywords: [
10
10
  "audit",
@@ -364,6 +364,69 @@ var SEED_GUIDE_PATHS = Object.freeze(["guides/guide.md", "guides/scaffold.md"]);
364
364
  /** Names the repository-relative path where the committed vendored-file inventory is served. */
365
365
  var HOST_INVENTORY_PATH = "host.json";
366
366
  /**
367
+ * Lists the declared transfers of bare names to their ruled keepers, frozen.
368
+ *
369
+ * @remarks
370
+ * `stageHost` admits each keeper into its name's recorded owner set and refuses a transfer
371
+ * whose keeper alone claims the name. `.claude/rules/names.md` § Fleet name ownership rule 5
372
+ * governs when a transfer is declared and removed.
373
+ */
374
+ var SURFACE_TRANSFERS = Object.freeze([
375
+ ...["BOM"].map((name) => ({
376
+ name,
377
+ keeper: "codec",
378
+ item: 80
379
+ })),
380
+ ...[
381
+ "CHOICE_LIMIT",
382
+ "NAME_LIMIT",
383
+ "NODE_LIMIT",
384
+ "STRING_LIMIT",
385
+ "TEXT_LIMIT",
386
+ "errorToMessage",
387
+ "escapeRegExp",
388
+ "failure",
389
+ "isFailure",
390
+ "isSuccess",
391
+ "success"
392
+ ].map((name) => ({
393
+ name,
394
+ keeper: "contract",
395
+ item: 79
396
+ })),
397
+ ...[
398
+ "JSONRPCError",
399
+ "JSONRPCErrorResponse",
400
+ "JSONRPCId",
401
+ "JSONRPCInvocation",
402
+ "JSONRPCMessage",
403
+ "JSONRPCNotification",
404
+ "JSONRPCRequest",
405
+ "JSONRPCResponse",
406
+ "JSONRPCResultResponse",
407
+ "JSONRPC_INTERNAL_ERROR",
408
+ "JSONRPC_INVALID_PARAMS",
409
+ "JSONRPC_INVALID_REQUEST",
410
+ "JSONRPC_METHOD_NOT_FOUND",
411
+ "JSONRPC_PARSE_ERROR",
412
+ "buildJSONRPCError",
413
+ "buildJSONRPCResult",
414
+ "isJSONRPCError",
415
+ "isJSONRPCErrorResponse",
416
+ "isJSONRPCId",
417
+ "isJSONRPCInvocation",
418
+ "isJSONRPCMessage",
419
+ "isJSONRPCNotification",
420
+ "isJSONRPCRequest",
421
+ "isJSONRPCResponse",
422
+ "isJSONRPCResultResponse"
423
+ ].map((name) => ({
424
+ name,
425
+ keeper: "jsonrpc",
426
+ item: 81
427
+ }))
428
+ ].map((transfer) => Object.freeze(transfer)));
429
+ /**
367
430
  * Lists the vendored paths whose present bytes belong to each workspace, frozen.
368
431
  *
369
432
  * @remarks
@@ -600,6 +663,8 @@ var MAX_RANGE_LENGTH = 2048;
600
663
  var MAX_SCRIPT_LENGTH = 4096;
601
664
  /** Caps the length of one path, matching the longest a supported filesystem accepts. */
602
665
  var MAX_PATH_LENGTH = 32767;
666
+ /** Sets the shortest name length at which a one-edit neighbor counts as a near name. */
667
+ var SURFACE_EDIT_LENGTH = 6;
603
668
  /** Caps the items accepted in one public collection. */
604
669
  var MAX_COLLECTION_ITEMS = 1e3;
605
670
  /** Caps the columns one emitted line may occupy, matching `printWidth` in `.oxfmtrc.json`. */
@@ -5592,6 +5657,122 @@ function collectSurfaceConflicts(owner, exports) {
5592
5657
  });
5593
5658
  }
5594
5659
  /**
5660
+ * Infers how two different names resemble each other by spelling.
5661
+ *
5662
+ * @returns The first class that holds, or `undefined` when none does or the names are equal.
5663
+ *
5664
+ * @remarks
5665
+ * Reads, in order, a case-fold twin, a singular or plural form (`s`, `es`, or `y` to `ies`), and
5666
+ * one insertion, deletion, or substitution of a code unit when both names hold at least
5667
+ * `SURFACE_EDIT_LENGTH` characters. Never returns `signature`, which compares cells.
5668
+ *
5669
+ * @example
5670
+ * ```ts
5671
+ * import { inferSurfaceSimilarity } from '@orkestrel/scaffold'
5672
+ *
5673
+ * inferSurfaceSimilarity('Route', 'Routes') // 'plural'
5674
+ * ```
5675
+ */
5676
+ function inferSurfaceSimilarity(name, other) {
5677
+ const [short, long] = name.length <= other.length ? [name, other] : [other, name];
5678
+ if (name === other) return void 0;
5679
+ if (name.toLowerCase() === other.toLowerCase()) return "case";
5680
+ if (long === `${short}s` || long === `${short}es` || short.endsWith("y") && long === `${short.slice(0, -1)}ies`) return "plural";
5681
+ if (short.length < 6 || long.length - short.length > 1) return void 0;
5682
+ const found = short.split("").findIndex((character, position) => character !== long[position]);
5683
+ const index = found === -1 ? short.length : found;
5684
+ const rest = long.length === short.length ? short.slice(index + 1) : short.slice(index);
5685
+ return long.slice(index + 1) === rest ? "edit" : void 0;
5686
+ }
5687
+ /**
5688
+ * Checks whether an error is the `TARGET` refusal a surface reader raises for a guide its parser
5689
+ * refuses, which carries the parser's code in its context.
5690
+ *
5691
+ * @returns True if the error is that refusal; false otherwise.
5692
+ *
5693
+ * @example
5694
+ * ```ts
5695
+ * import { matchesGuideRefusal, ScaffoldError } from '@orkestrel/scaffold'
5696
+ *
5697
+ * matchesGuideRefusal(new ScaffoldError('TARGET', 'Refused', { code: 'header' })) // true
5698
+ * ```
5699
+ */
5700
+ function matchesGuideRefusal(error) {
5701
+ return isScaffoldError(error) && error.code === "TARGET" && (0, _orkestrel_contract.isRecord)(error.context) && (0, _orkestrel_contract.isString)(error.context.code);
5702
+ }
5703
+ /**
5704
+ * Checks whether a guide `Signature` cell spells a structure rather than a literal or a type name.
5705
+ *
5706
+ * @returns True if the cell is one code span that opens with a member list holding at least one
5707
+ * member, its array and union forms included; false otherwise.
5708
+ *
5709
+ * @remarks
5710
+ * A literal (`2000`, `" "`, `'live' | 'floor'`), a bare primitive (`string`), a type reference
5711
+ * (`RegExp`, `Guard<string>`, `readonly string[]`), a function type, an empty member list, and
5712
+ * prose are no structure: two names sharing one of those share a type, not a contract.
5713
+ *
5714
+ * @example
5715
+ * ```ts
5716
+ * import { matchesSurfaceStructure } from '@orkestrel/scaffold'
5717
+ *
5718
+ * matchesSurfaceStructure('`{ owner, names }`') // true
5719
+ * ```
5720
+ */
5721
+ function matchesSurfaceStructure(signature) {
5722
+ const code = /^`([^`]+)`$/u.exec(signature)?.[1]?.trim();
5723
+ return code !== void 0 && code.startsWith("{") && !/^\{\s*\}$/u.test(code);
5724
+ }
5725
+ /**
5726
+ * Collects the near names and equal contracts other owners claim beside each name a candidate adds.
5727
+ *
5728
+ * @param candidate - The candidate owner's contract.
5729
+ * @param published - The names the candidate owner's published guide claims; empty when none.
5730
+ * @param contracts - Every owner's contract; the candidate owner's own entry is skipped.
5731
+ * @returns One advisory per added name, peer, and class, sorted by added name, peer owner, and peer
5732
+ * name, with a spelling class before `signature`.
5733
+ *
5734
+ * @remarks
5735
+ * An added name is one `candidate` claims and `published` does not. A spelling class comes from
5736
+ * `inferSurfaceSimilarity`; `signature` holds when both names carry equal cells that
5737
+ * `matchesSurfaceStructure` accepts. A name equal to the added name is a collision, not an
5738
+ * advisory.
5739
+ *
5740
+ * @example
5741
+ * ```ts
5742
+ * import { collectSurfaceAdvisories } from '@orkestrel/scaffold'
5743
+ *
5744
+ * const advisories = collectSurfaceAdvisories(
5745
+ * { owner: 'alpha', names: ['Routes'], signatures: new Map() },
5746
+ * [],
5747
+ * [{ owner: 'router', names: ['Route'], signatures: new Map() }],
5748
+ * )
5749
+ * advisories[0]?.similarity // 'plural'
5750
+ * ```
5751
+ */
5752
+ function collectSurfaceAdvisories(candidate, published, contracts) {
5753
+ const known = new Set(published);
5754
+ const peers = contracts.filter(({ owner }) => owner !== candidate.owner).flatMap(({ owner, names, signatures }) => [...new Set(names)].map((name) => ({
5755
+ name,
5756
+ owner,
5757
+ signature: signatures.get(name)
5758
+ }))).sort((left, right) => (0, _orkestrel_contract.compareValues)(left.owner, right.owner) || (0, _orkestrel_contract.compareValues)(left.name, right.name));
5759
+ return [...new Set(candidate.names)].filter((name) => !known.has(name)).sort(_orkestrel_contract.compareValues).flatMap((name) => {
5760
+ const signature = candidate.signatures.get(name);
5761
+ const structure = signature !== void 0 && matchesSurfaceStructure(signature);
5762
+ return peers.flatMap((peer) => {
5763
+ return [inferSurfaceSimilarity(name, peer.name), structure && peer.name !== name && peer.signature === signature ? "signature" : void 0].flatMap((similarity) => similarity === void 0 ? [] : [{
5764
+ name,
5765
+ owner: candidate.owner,
5766
+ peer: {
5767
+ name: peer.name,
5768
+ owner: peer.owner
5769
+ },
5770
+ similarity
5771
+ }]);
5772
+ });
5773
+ });
5774
+ }
5775
+ /**
5595
5776
  * Encodes bytes as exact lowercase hexadecimal text.
5596
5777
  *
5597
5778
  * @param bytes - The bytes to encode.
@@ -9793,6 +9974,8 @@ exports.STUDIES_TEST_INCLUDE = STUDIES_TEST_INCLUDE;
9793
9974
  exports.STYLES_DEV_DEPENDENCIES = STYLES_DEV_DEPENDENCIES;
9794
9975
  exports.STYLES_ENTRY_PATH = STYLES_ENTRY_PATH;
9795
9976
  exports.SURFACES = SURFACES;
9977
+ exports.SURFACE_EDIT_LENGTH = SURFACE_EDIT_LENGTH;
9978
+ exports.SURFACE_TRANSFERS = SURFACE_TRANSFERS;
9796
9979
  exports.ScaffoldError = ScaffoldError;
9797
9980
  exports.TAB_WIDTH = TAB_WIDTH;
9798
9981
  exports.TARGET_SKILL_NAMES = TARGET_SKILL_NAMES;
@@ -9832,6 +10015,7 @@ exports.blueprintToWritableScripts = blueprintToWritableScripts;
9832
10015
  exports.bytesToHex = bytesToHex;
9833
10016
  exports.catalogToLayers = catalogToLayers;
9834
10017
  exports.cloneValue = cloneValue;
10018
+ exports.collectSurfaceAdvisories = collectSurfaceAdvisories;
9835
10019
  exports.collectSurfaceCollisions = collectSurfaceCollisions;
9836
10020
  exports.collectSurfaceConflicts = collectSurfaceConflicts;
9837
10021
  exports.compareSurfaceCollisions = compareSurfaceCollisions;
@@ -9846,6 +10030,7 @@ exports.extractRangeMajor = extractRangeMajor;
9846
10030
  exports.extractVersion = extractVersion;
9847
10031
  exports.inferDrift = inferDrift;
9848
10032
  exports.inferGroup = inferGroup;
10033
+ exports.inferSurfaceSimilarity = inferSurfaceSimilarity;
9849
10034
  exports.insertManifestDependencies = insertManifestDependencies;
9850
10035
  exports.insertManifestSection = insertManifestSection;
9851
10036
  exports.isArtifact = isArtifact;
@@ -9885,9 +10070,11 @@ exports.manifestToDependencies = manifestToDependencies;
9885
10070
  exports.manifestToName = manifestToName;
9886
10071
  exports.matchesDriftReachability = matchesDriftReachability;
9887
10072
  exports.matchesEngines = matchesEngines;
10073
+ exports.matchesGuideRefusal = matchesGuideRefusal;
9888
10074
  exports.matchesOrchestrationPath = matchesOrchestrationPath;
9889
10075
  exports.matchesPrintWidth = matchesPrintWidth;
9890
10076
  exports.matchesRange = matchesRange;
10077
+ exports.matchesSurfaceStructure = matchesSurfaceStructure;
9891
10078
  exports.nameToGuide = nameToGuide;
9892
10079
  exports.overridesToQuestions = overridesToQuestions;
9893
10080
  exports.parseBlueprint = parseBlueprint;