arkaik 0.11.1 → 0.13.0

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.
package/dist/index.js CHANGED
@@ -3055,13 +3055,13 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
3055
3055
  }
3056
3056
  return propValues;
3057
3057
  });
3058
- const isObject2 = isObject;
3058
+ const isObject4 = isObject;
3059
3059
  const catchall = def.catchall;
3060
3060
  let value;
3061
3061
  inst._zod.parse = (payload, ctx) => {
3062
3062
  value ?? (value = _normalized.value);
3063
3063
  const input = payload.value;
3064
- if (!isObject2(input)) {
3064
+ if (!isObject4(input)) {
3065
3065
  payload.issues.push({
3066
3066
  expected: "object",
3067
3067
  code: "invalid_type",
@@ -3188,7 +3188,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
3188
3188
  return (payload, ctx) => fn(shape, payload, ctx);
3189
3189
  };
3190
3190
  let fastpass;
3191
- const isObject2 = isObject;
3191
+ const isObject4 = isObject;
3192
3192
  const jit = !globalConfig.jitless;
3193
3193
  const allowsEval2 = allowsEval;
3194
3194
  const fastEnabled = jit && allowsEval2.value;
@@ -3197,7 +3197,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
3197
3197
  inst._zod.parse = (payload, ctx) => {
3198
3198
  value ?? (value = _normalized.value);
3199
3199
  const input = payload.value;
3200
- if (!isObject2(input)) {
3200
+ if (!isObject4(input)) {
3201
3201
  payload.issues.push({
3202
3202
  expected: "object",
3203
3203
  code: "invalid_type",
@@ -14621,6 +14621,38 @@ var VALUE_IDS = [
14621
14621
  // social-impact (1)
14622
14622
  "self-transcendence"
14623
14623
  ];
14624
+ var VALUE_TIERS = {
14625
+ "saves-time": "functional",
14626
+ simplifies: "functional",
14627
+ "makes-money": "functional",
14628
+ "reduces-risk": "functional",
14629
+ organizes: "functional",
14630
+ integrates: "functional",
14631
+ connects: "functional",
14632
+ "reduces-effort": "functional",
14633
+ "avoids-hassles": "functional",
14634
+ "reduces-cost": "functional",
14635
+ quality: "functional",
14636
+ variety: "functional",
14637
+ "sensory-appeal": "functional",
14638
+ informs: "functional",
14639
+ "reduces-anxiety": "emotional",
14640
+ "rewards-me": "emotional",
14641
+ nostalgia: "emotional",
14642
+ "design-aesthetics": "emotional",
14643
+ "badge-value": "emotional",
14644
+ wellness: "emotional",
14645
+ "therapeutic-value": "emotional",
14646
+ "fun-entertainment": "emotional",
14647
+ attractiveness: "emotional",
14648
+ "provides-access": "emotional",
14649
+ "provides-hope": "life-changing",
14650
+ "self-actualization": "life-changing",
14651
+ motivation: "life-changing",
14652
+ heirloom: "life-changing",
14653
+ "affiliation-belonging": "life-changing",
14654
+ "self-transcendence": "social-impact"
14655
+ };
14624
14656
 
14625
14657
  // ../schema/src/legacy-status.ts
14626
14658
  var LEGACY_STATUS_IDS = ["prioritized", "blocked"];
@@ -15207,6 +15239,84 @@ function missingProvenanceNodeIds(snapshotNodeIds, events) {
15207
15239
  return missing;
15208
15240
  }
15209
15241
 
15242
+ // ../schema/src/weighing-schemas.ts
15243
+ var documented = (schema) => external_exports.union([schema, external_exports.unknown()]);
15244
+ var leaf = (description) => external_exports.unknown().optional().meta({ description });
15245
+ var WeighingConfidenceSchema = external_exports.unknown().meta({ description: "0 guess \xB7 1 inferred \xB7 2 evidenced \xB7 3 verified." });
15246
+ var WeighingScorerSchema = external_exports.object({
15247
+ kind: leaf("Who judged: human, agent or rule. A human's level beats an agent's, which beats a rule's. Any value parses; the validator warns on another kind."),
15248
+ id: leaf("A person's handle, an agent's name, or a seeding rule's id."),
15249
+ model: leaf("The model behind an agent, when it says."),
15250
+ on_behalf_of: leaf("Whom the scorer acts for: a user id, a handle or a display name, never an email. Stamped by the writer where identity is known.")
15251
+ }).catchall(external_exports.unknown()).meta({ id: "WeighingScorer", description: "Provenance of one assessment." });
15252
+ var WeighingScaleSchema = external_exports.object({
15253
+ min: leaf("The lowest level, e.g. -3."),
15254
+ max: leaf("The highest level, e.g. 3."),
15255
+ anchors: leaf("Every level described in words, keyed by the level as a string.")
15256
+ }).catchall(external_exports.unknown()).meta({ id: "WeighingScale", description: "A criteria set's scale: its bounds and every level's anchor." });
15257
+ var WeighingGroupSchema = external_exports.object({ id: leaf("The group's id."), title: leaf("The group's title.") }).catchall(external_exports.unknown()).meta({ id: "WeighingGroup", description: "A grouping of criteria \u2014 the tiers, for the value set." });
15258
+ var WeighingCriterionSchema = external_exports.object({
15259
+ id: leaf("Stable identifier. Never redefined \u2014 retired via superseded_by."),
15260
+ group: leaf("A group id \u2014 for the value set, the tier."),
15261
+ name: leaf("A short name."),
15262
+ question: leaf("The question a scorer answers."),
15263
+ definition: leaf("What the criterion means."),
15264
+ anchors: leaf("This criterion's own wording of each level \u2014 on a positioning, in the product's words."),
15265
+ weight: leaf("On a positioning: how much the product stands on it, a number above 0. Absent means 1."),
15266
+ superseded_by: leaf("The id of the criterion that replaces this one.")
15267
+ }).catchall(external_exports.unknown()).meta({ id: "WeighingCriterion", description: "One question on a scale where every level is described." });
15268
+ var WeighingCriteriaSetSchema = external_exports.object({
15269
+ id: leaf("The set's id."),
15270
+ version: leaf("Semver. Levels are comparable only within a major."),
15271
+ title: leaf("A human title."),
15272
+ subject: leaf("What the set judges: acceptance today."),
15273
+ scale: documented(WeighingScaleSchema).optional().meta({ description: "The scale. A positioning may leave it out and use its ruler's." }),
15274
+ groups: documented(external_exports.array(documented(WeighingGroupSchema))).optional(),
15275
+ criteria: documented(external_exports.array(documented(WeighingCriterionSchema))).optional(),
15276
+ role: leaf("positioning marks the set a project writes about itself."),
15277
+ status: leaf("Absent or active is active; anything else is a draft, which feeds no roll-up."),
15278
+ extends: leaf("A positioning's ruler, e.g. value-contribution@2.")
15279
+ }).catchall(external_exports.unknown()).meta({ id: "WeighingCriteriaSet", description: "A versioned list of criteria for one kind of subject. The 30 elements of value are one; a positioning is another." });
15280
+ var WeighingMatrixSchema = external_exports.object({
15281
+ id: leaf("The matrix's id."),
15282
+ title: leaf("A human title."),
15283
+ set: leaf("The set's id and major, e.g. value-contribution@2."),
15284
+ subjects: documented(
15285
+ external_exports.object({ kind: leaf("query or list."), species: leaf("For a query: the species judged."), items: leaf("For a list: the subjects.") }).catchall(external_exports.unknown())
15286
+ ).optional().meta({ description: "What the matrix judges: { kind: query, species } or { kind: list, items }." }),
15287
+ positioning: leaf("The id of the positioning set that re-weights this matrix."),
15288
+ context: leaf("The node the matrix is about, as { node_id }."),
15289
+ status: leaf("Absent or active is active; anything else is a draft.")
15290
+ }).catchall(external_exports.unknown()).meta({ id: "WeighingMatrix", description: "A criteria set applied to a list of subjects." });
15291
+ var WeighingAssessmentBasisSchema = external_exports.object({
15292
+ fingerprint: leaf("A hash of the subject's judged fields."),
15293
+ commit: leaf("The commit the scorer was looking at."),
15294
+ set_version: leaf("The full version of the set the level was read against.")
15295
+ }).catchall(external_exports.unknown());
15296
+ var WeighingAssessmentSchema = external_exports.object({
15297
+ matrix: leaf("The matrix's id. A row without it cannot be addressed: readers skip it and the validator warns."),
15298
+ subject: leaf("A node id for the value matrix."),
15299
+ criterion: leaf("A criterion id."),
15300
+ level: leaf("A whole number on the set's scale. 0 means unrelated. No half points \u2014 but any value parses; the validator warns on one off the scale."),
15301
+ scorer: documented(WeighingScorerSchema).optional().meta({ description: "Who judged. Required in practice: without it a human, an agent and a rule are indistinguishable, so the validator warns." }),
15302
+ confidence: leaf("0 guess \xB7 1 inferred \xB7 2 evidenced \xB7 3 verified."),
15303
+ evidence: leaf("Markdown."),
15304
+ refs: leaf("Ids cited: nodes, journal events, findings."),
15305
+ basis: documented(WeighingAssessmentBasisSchema).optional().meta({ description: "What the scorer was looking at, so a re-read can tell the score went stale." }),
15306
+ run: leaf("The audit or plan the score belongs to."),
15307
+ p_serves: leaf("Optional: a probabilistic scorer's certainty (0 to 1) that the subject serves the element. Certainty, not size. Any value parses; the validator warns on one outside 0..1."),
15308
+ p_costs: leaf("Optional: the same for costs, asked independently, so both can be high."),
15309
+ ts: leaf("ISO 8601.")
15310
+ }).catchall(external_exports.unknown()).meta({ id: "WeighingAssessment", description: "One (matrix \xD7 subject \xD7 criterion) judgement \u2014 latest per scorer kind wins; history lives in the journal." });
15311
+ var WeighingSectionSchema = external_exports.object({
15312
+ sets: external_exports.array(documented(WeighingCriteriaSetSchema)).optional(),
15313
+ matrices: external_exports.array(documented(WeighingMatrixSchema)).optional(),
15314
+ assessments: external_exports.array(documented(WeighingAssessmentSchema)).optional()
15315
+ }).catchall(external_exports.unknown()).meta({
15316
+ id: "WeighingSection",
15317
+ description: "The project's weighing state (docs/rfcs/weighing.md) \u2014 its own criteria sets (a positioning), matrices and assessments. The built-in value set is library content, not stored; served, cost and kept share are derived, never stored. Each list may be absent; a reader treats it as empty."
15318
+ });
15319
+
15210
15320
  // ../schema/src/journal-events.ts
15211
15321
  var envelope = {
15212
15322
  id: external_exports.string().meta({ description: "ULID \u2014 sortable, collision-free without coordination." }),
@@ -15397,6 +15507,23 @@ var QualitySignalTrippedEventSchema = external_exports.object({
15397
15507
  commit: external_exports.string().optional(),
15398
15508
  detail: external_exports.string().optional()
15399
15509
  }).catchall(external_exports.unknown());
15510
+ var WeighingAssessmentRecordedEventSchema = external_exports.object({
15511
+ ...envelope,
15512
+ type: external_exports.literal("weighing.assessment.recorded"),
15513
+ matrix: external_exports.string(),
15514
+ subject: external_exports.string(),
15515
+ criterion: external_exports.string(),
15516
+ level: external_exports.number().int(),
15517
+ scorer: WeighingScorerSchema,
15518
+ confidence: WeighingConfidenceSchema,
15519
+ evidence: external_exports.string().optional(),
15520
+ refs: external_exports.array(external_exports.string()).optional(),
15521
+ basis: WeighingAssessmentBasisSchema.optional(),
15522
+ run: external_exports.string().optional(),
15523
+ p_serves: external_exports.number().min(0).max(1).optional(),
15524
+ p_costs: external_exports.number().min(0).max(1).optional()
15525
+ }).catchall(external_exports.unknown());
15526
+ var WeighingSetSavedEventSchema = external_exports.object({ ...envelope, type: external_exports.literal("weighing.set.saved"), set: WeighingCriteriaSetSchema }).catchall(external_exports.unknown());
15400
15527
  var JOURNAL_EVENT_SCHEMAS = {
15401
15528
  "node.created": NodeCreatedEventSchema,
15402
15529
  "node.updated": NodeUpdatedEventSchema,
@@ -15420,7 +15547,9 @@ var JOURNAL_EVENT_SCHEMAS = {
15420
15547
  "quality.finding.opened": QualityFindingOpenedEventSchema,
15421
15548
  "quality.finding.resolved": QualityFindingResolvedEventSchema,
15422
15549
  "quality.finding.accepted": QualityFindingAcceptedEventSchema,
15423
- "quality.signal.tripped": QualitySignalTrippedEventSchema
15550
+ "quality.signal.tripped": QualitySignalTrippedEventSchema,
15551
+ "weighing.assessment.recorded": WeighingAssessmentRecordedEventSchema,
15552
+ "weighing.set.saved": WeighingSetSavedEventSchema
15424
15553
  };
15425
15554
  var KnownJournalEventSchema = external_exports.union([
15426
15555
  NodeCreatedEventSchema,
@@ -15445,7 +15574,9 @@ var KnownJournalEventSchema = external_exports.union([
15445
15574
  QualityFindingOpenedEventSchema,
15446
15575
  QualityFindingResolvedEventSchema,
15447
15576
  QualityFindingAcceptedEventSchema,
15448
- QualitySignalTrippedEventSchema
15577
+ QualitySignalTrippedEventSchema,
15578
+ WeighingAssessmentRecordedEventSchema,
15579
+ WeighingSetSavedEventSchema
15449
15580
  ]);
15450
15581
 
15451
15582
  // ../schema/src/quality.ts
@@ -16669,6 +16800,9 @@ var ProjectBundleSchema = external_exports.object({
16669
16800
  }),
16670
16801
  quality: QualitySectionSchema.optional().meta({
16671
16802
  description: "Optional Kritik quality state (docs/rfcs/kritik.md \xA7 4.1) \u2014 the pinned pack version, the project's surface profile, its assessments and findings. Additive: a bundle without it is not an error, and the comparative matrix is derived from it (deriveQualityMatrix), never stored."
16803
+ }),
16804
+ weighing: WeighingSectionSchema.optional().meta({
16805
+ description: "Optional weighing state (docs/rfcs/weighing.md) \u2014 the project's own criteria sets (a positioning), matrices and assessments, each assessment carrying its scorer, confidence and basis. Additive: a bundle without it is not an error, and every weight, served and cost figure is derived from it, never stored."
16672
16806
  })
16673
16807
  }).catchall(external_exports.unknown()).meta({
16674
16808
  id: "ProjectBundle",
@@ -16702,6 +16836,673 @@ function isBuiltInMapId(id) {
16702
16836
  return BUILT_IN_MAP_IDS.includes(id);
16703
16837
  }
16704
16838
 
16839
+ // ../schema/src/weighing-ladders.ts
16840
+ var LADDERS = {
16841
+ "saves-time": {
16842
+ "-3": "Takes hours out of the person's life.",
16843
+ "-2": "Costs the person time on tasks they do regularly in this domain.",
16844
+ "-1": "Costs the person a little time on one task inside the product.",
16845
+ "1": "Saves a little time on one task inside the product.",
16846
+ "2": "Saves time on tasks the person does regularly in this domain.",
16847
+ "3": "Gives the person back hours of their life, the way online banking replaced trips to the bank."
16848
+ },
16849
+ simplifies: {
16850
+ "-3": "Makes a part of the person's life confusing or hard to manage.",
16851
+ "-2": "Makes a whole task in this domain clearly more complicated.",
16852
+ "-1": "Adds a step or a choice inside the product.",
16853
+ "1": "Removes a step or a choice inside the product.",
16854
+ "2": "Makes a whole task in this domain clearly simpler.",
16855
+ "3": "Makes a complicated part of the person's life simple, the way a single search box replaced browsing directories."
16856
+ },
16857
+ "makes-money": {
16858
+ "-3": "Costs the person a meaningful part of their income.",
16859
+ "-2": "Cuts a regular way the person earns in this domain.",
16860
+ "-1": "Makes earning slightly harder or costs the person a little income.",
16861
+ "1": "Helps the person earn a little, or makes earning slightly easier.",
16862
+ "2": "Gives the person a regular way to earn in this domain.",
16863
+ "3": "Provides a meaningful part of the person's income."
16864
+ },
16865
+ "reduces-risk": {
16866
+ "-3": "Exposes the person to a major loss in their life.",
16867
+ "-2": "Exposes the person to a serious loss or error in this domain.",
16868
+ "-1": "Exposes the person to a small mistake or loss inside the product.",
16869
+ "1": "Guards against a small mistake or loss inside the product.",
16870
+ "2": "Protects against a serious loss or error in this domain.",
16871
+ "3": "Protects against a major loss in the person's life, the way insurance or a full backup does."
16872
+ },
16873
+ organizes: {
16874
+ "-3": "Brings disorder to a large part of the person's life.",
16875
+ "-2": "Makes things in this domain hard to keep in order or to find.",
16876
+ "-1": "Leaves a few things in disorder inside the product.",
16877
+ "1": "Keeps a few things in order inside the product.",
16878
+ "2": "Keeps everything in this domain in order and easy to find.",
16879
+ "3": "Brings order to a large part of the person's life, the way a calendar does."
16880
+ },
16881
+ integrates: {
16882
+ "-3": "Pulls separate parts of the person's life further apart.",
16883
+ "-2": "Splits apart the several tools the person uses in this domain.",
16884
+ "-1": "Cuts the product off from one other tool the person uses.",
16885
+ "1": "Connects the product to one other tool the person uses.",
16886
+ "2": "Ties together the several tools the person uses in this domain.",
16887
+ "3": "Makes separate parts of the person's life work together as one."
16888
+ },
16889
+ connects: {
16890
+ "-3": "Separates the person from the people who matter most in their life.",
16891
+ "-2": "Makes it harder to build or keep relationships in this domain.",
16892
+ "-1": "Gets in the way of reaching someone through the product.",
16893
+ "1": "Lets the person reach someone through the product.",
16894
+ "2": "Helps the person build and keep relationships in this domain.",
16895
+ "3": "Brings the person together with the people who matter most in their life."
16896
+ },
16897
+ "reduces-effort": {
16898
+ "-3": "Puts a heavy burden of work on the person's life.",
16899
+ "-2": "Adds repetitive work to a task the person does regularly in this domain.",
16900
+ "-1": "Adds a little effort to one task inside the product.",
16901
+ "1": "Saves a little effort on one task inside the product.",
16902
+ "2": "Takes the repetitive work out of a task the person does regularly in this domain.",
16903
+ "3": "Lifts a heavy burden of work off the person's life."
16904
+ },
16905
+ "avoids-hassles": {
16906
+ "-3": "Brings a whole kind of annoyance into the person's life.",
16907
+ "-2": "Adds an annoyance that keeps coming back in this domain.",
16908
+ "-1": "Adds a small annoyance inside the product.",
16909
+ "1": "Avoids a small annoyance inside the product.",
16910
+ "2": "Avoids an annoyance that keeps coming back in this domain.",
16911
+ "3": "Takes a whole kind of annoyance out of the person's life, the way a GPS ended getting lost."
16912
+ },
16913
+ "reduces-cost": {
16914
+ "-3": "Costs the person a significant amount of money over their life.",
16915
+ "-2": "Costs the person money regularly in this domain.",
16916
+ "-1": "Costs the person a little money on one purchase.",
16917
+ "1": "Saves the person a little money on one purchase.",
16918
+ "2": "Saves the person money regularly in this domain.",
16919
+ "3": "Saves the person a significant amount of money over their life."
16920
+ },
16921
+ quality: {
16922
+ "-3": "Craft so poor the person would call it the worst they have used.",
16923
+ "-2": "The product does its job in this domain clearly worse than the usual alternatives.",
16924
+ "-1": "Something inside the product works noticeably badly.",
16925
+ "1": "Something inside the product works noticeably well.",
16926
+ "2": "The product does its job in this domain clearly better than the usual alternatives.",
16927
+ "3": "Craft so good the person would call it the best they have used."
16928
+ },
16929
+ variety: {
16930
+ "-3": "Closes off a breadth of choice the person had elsewhere.",
16931
+ "-2": "Narrows the choice in this domain.",
16932
+ "-1": "Removes a few meaningful options inside the product.",
16933
+ "1": "Offers a few meaningful options inside the product.",
16934
+ "2": "Offers a wide and meaningful choice in this domain.",
16935
+ "3": "Opens a breadth of choice the person could not get anywhere else."
16936
+ },
16937
+ "sensory-appeal": {
16938
+ "-3": "A sensory experience the person avoids.",
16939
+ "-2": "The product looks, sounds or feels bad and the person dislikes using it.",
16940
+ "-1": "An unpleasant detail the person notices in the moment.",
16941
+ "1": "A pleasant detail the person notices in the moment.",
16942
+ "2": "The product looks, sounds or feels good and the person enjoys using it.",
16943
+ "3": "A sensory experience the person seeks out for its own sake."
16944
+ },
16945
+ informs: {
16946
+ "-3": "Misleads the person deeply about the service area or domain.",
16947
+ "-2": "Confuses the person about the service area or domain.",
16948
+ "-1": "Hides from the person something about the service that they want to know.",
16949
+ "1": "Informs the person about the service.",
16950
+ "2": "Informs the person about the service area or domain.",
16951
+ "3": "Informs the person deeply and efficiently about the service area or domain."
16952
+ },
16953
+ "reduces-anxiety": {
16954
+ "-3": "Gives the person a lasting worry in their life.",
16955
+ "-2": "Stirs up a worry the person has in this domain.",
16956
+ "-1": "Adds a small worry inside the product.",
16957
+ "1": "Removes a small worry inside the product.",
16958
+ "2": "Calms a worry the person has in this domain.",
16959
+ "3": "Takes a lasting worry out of the person's life."
16960
+ },
16961
+ "rewards-me": {
16962
+ "-3": "Takes away rewards the person values as much as the product itself.",
16963
+ "-2": "Takes away perks the person regularly values.",
16964
+ "-1": "Takes away a small perk the person had.",
16965
+ "1": "Gives the person a small perk for engaging.",
16966
+ "2": "Gives the person regular perks they value.",
16967
+ "3": "Gives the person rewards they value as much as the product itself."
16968
+ },
16969
+ nostalgia: {
16970
+ "-3": "Destroys a cherished memory for good.",
16971
+ "-2": "Loses or overwrites a good memory of the past.",
16972
+ "-1": "Puts a pleasant memory at slight risk.",
16973
+ "1": "Faintly recalls a pleasant memory of the past.",
16974
+ "2": "Clearly brings back a good memory of the past.",
16975
+ "3": "Brings back a cherished past in a vivid and deeply felt way."
16976
+ },
16977
+ "design-aesthetics": {
16978
+ "-3": "Ugliness the person would be embarrassed to show to others.",
16979
+ "-2": "A design the person finds ugly.",
16980
+ "-1": "A displeasing design detail.",
16981
+ "1": "A pleasing design detail.",
16982
+ "2": "A design the person finds beautiful.",
16983
+ "3": "Beauty the person would show to others and that shapes how they feel about it."
16984
+ },
16985
+ "badge-value": {
16986
+ "-3": "Signals something the person does not want the people who matter to them to see.",
16987
+ "-2": "Clearly signals a low identity or status in a community.",
16988
+ "-1": "Gives a mild negative signal about the person to others.",
16989
+ "1": "Gives a mild signal about the person to others.",
16990
+ "2": "Clearly signals the person's identity or status in a community.",
16991
+ "3": "Signals who the person is to the people who matter to them."
16992
+ },
16993
+ wellness: {
16994
+ "-3": "Lastingly harms the person's physical or mental well-being.",
16995
+ "-2": "Noticeably worsens how the person feels over time.",
16996
+ "-1": "Slightly worsens how the person feels, in the moment.",
16997
+ "1": "Slightly improves how the person feels, in the moment.",
16998
+ "2": "Noticeably improves how the person feels over time.",
16999
+ "3": "Lastingly improves the person's physical or mental well-being."
17000
+ },
17001
+ "therapeutic-value": {
17002
+ "-3": "Deepens something that hurts the person.",
17003
+ "-2": "Makes a difficult feeling harder for the person to work through.",
17004
+ "-1": "Reopens a small emotional sore.",
17005
+ "1": "Gives a small moment of emotional relief.",
17006
+ "2": "Helps the person work through a difficult feeling.",
17007
+ "3": "Supports real healing of something that hurts the person."
17008
+ },
17009
+ "fun-entertainment": {
17010
+ "-3": "So joyless that the person avoids it and warns others.",
17011
+ "-2": "Boring or tedious to use.",
17012
+ "-1": "A dull moment.",
17013
+ "1": "A light moment of enjoyment.",
17014
+ "2": "Genuinely enjoyable to use.",
17015
+ "3": "Delight the person would seek out and tell others about."
17016
+ },
17017
+ attractiveness: {
17018
+ "-3": "Changes how unattractive the person feels in general.",
17019
+ "-2": "Clearly makes the person feel less attractive.",
17020
+ "-1": "Makes the person feel slightly worse about how they look.",
17021
+ "1": "Makes the person feel slightly better about how they look.",
17022
+ "2": "Clearly makes the person feel more attractive.",
17023
+ "3": "Changes how attractive the person feels in general."
17024
+ },
17025
+ "provides-access": {
17026
+ "-3": "Shuts the person out of something that matters in their life.",
17027
+ "-2": "Cuts the person off from a service or from people in this domain that they could otherwise reach.",
17028
+ "-1": "Puts a feature inside the product behind a barrier or closes it off.",
17029
+ "1": "Opens a feature inside the product.",
17030
+ "2": "Gives access to a service or to people in this domain that the person could not easily reach.",
17031
+ "3": "Gives access to something that matters in the person's life and that they could not get otherwise."
17032
+ },
17033
+ "provides-hope": {
17034
+ "-3": "Leaves the person believing their life cannot get better.",
17035
+ "-2": "Gives the person a reason to doubt that things in this domain can improve.",
17036
+ "-1": "Plants a small doubt.",
17037
+ "1": "Gives a small reason for optimism.",
17038
+ "2": "Gives a real reason to believe things in this domain can improve.",
17039
+ "3": "Gives a lasting belief that the person's life can get better."
17040
+ },
17041
+ "self-actualization": {
17042
+ "-3": "Pushes the person away from who they want to be.",
17043
+ "-2": "Clear drift away from who the person wants to be.",
17044
+ "-1": "A small step away from who the person wants to be.",
17045
+ "1": "A small step toward who the person wants to be.",
17046
+ "2": "Clear progress toward who the person wants to be.",
17047
+ "3": "Helps the person become who they want to be."
17048
+ },
17049
+ motivation: {
17050
+ "-3": "Drains the person's drive toward goals that matter in their life.",
17051
+ "-2": "Saps the person's energy toward a goal in this domain.",
17052
+ "-1": "A small drag on the person's drive.",
17053
+ "1": "A small nudge to act.",
17054
+ "2": "Energizes the person toward a goal in this domain.",
17055
+ "3": "Sustains the person's drive toward goals that matter in their life."
17056
+ },
17057
+ heirloom: {
17058
+ "-3": "Loses something meaningful that was meant to be passed on across time.",
17059
+ "-2": "Lets something meaningful be lost within years.",
17060
+ "-1": "Puts something worth keeping at slight risk.",
17061
+ "1": "Keeps something worth keeping for a while.",
17062
+ "2": "Preserves something meaningful for years.",
17063
+ "3": "Holds something meaningful enough to be passed on to others across time."
17064
+ },
17065
+ "affiliation-belonging": {
17066
+ "-3": "Cuts the person off from a group that matters deeply to who they are.",
17067
+ "-2": "Leaves the person out of a group in this domain.",
17068
+ "-1": "A feeling of being slightly left out of something small.",
17069
+ "1": "A feeling of being part of something small.",
17070
+ "2": "Makes the person part of a group in this domain.",
17071
+ "3": "Makes the person part of a group that matters deeply to who they are."
17072
+ },
17073
+ "self-transcendence": {
17074
+ "-3": "Works against something larger than the person themselves.",
17075
+ "-2": "Harms others in a meaningful way.",
17076
+ "-1": "Does a small harm to others.",
17077
+ "1": "Does a small good for others.",
17078
+ "2": "Helps others in a meaningful way.",
17079
+ "3": "Contributes to something larger than the person themselves."
17080
+ }
17081
+ };
17082
+ var VALUE_REACH_LADDERS = Object.freeze(
17083
+ Object.fromEntries(Object.entries(LADDERS).map(([id, ladder]) => [id, Object.freeze(ladder)]))
17084
+ );
17085
+
17086
+ // ../schema/src/weighing.ts
17087
+ var SCORER_KINDS = ["human", "agent", "rule"];
17088
+ var STORED_SCORER_KINDS = ["human", "agent"];
17089
+ function scorerRank(kind) {
17090
+ const index = SCORER_KINDS.indexOf(kind);
17091
+ return index === -1 ? 0 : SCORER_KINDS.length - index;
17092
+ }
17093
+ var WEIGHING_PROBABILITY_FIELDS = ["p_serves", "p_costs"];
17094
+ function isWeighingProbability(value) {
17095
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
17096
+ }
17097
+ var WEIGHING_ASSESSMENT_RECORDED = "weighing.assessment.recorded";
17098
+ var WEIGHING_SET_SAVED = "weighing.set.saved";
17099
+ function cellKey(matrix, subject, criterion) {
17100
+ return `${matrix}\0${subject}\0${criterion}`;
17101
+ }
17102
+ function assessmentKey(a) {
17103
+ const kind = typeof a?.scorer?.kind === "string" ? a.scorer.kind : "";
17104
+ return `${cellKey(String(a?.matrix), String(a?.subject), String(a?.criterion))}\0${kind}`;
17105
+ }
17106
+ var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
17107
+ function isWeighingAssessmentShape(row) {
17108
+ return isRecord3(row) && typeof row.matrix === "string" && typeof row.subject === "string" && typeof row.criterion === "string";
17109
+ }
17110
+ function splitSetRef(ref) {
17111
+ const at2 = ref.lastIndexOf("@");
17112
+ if (at2 === -1) return { id: ref, major: void 0 };
17113
+ return { id: ref.slice(0, at2), major: ref.slice(at2 + 1) };
17114
+ }
17115
+ function majorOf(version2) {
17116
+ const match = /^(\d+)(?:\.|$)/.exec(version2);
17117
+ return match ? match[1] : void 0;
17118
+ }
17119
+ function sortWeighingAssessments(assessments) {
17120
+ return [...assessments].sort((a, b) => {
17121
+ const text = (x) => typeof x === "string" ? x : "\uFFFF";
17122
+ const by = (x, y) => text(x) < text(y) ? -1 : text(x) > text(y) ? 1 : 0;
17123
+ return by(a?.matrix, b?.matrix) || by(a?.subject, b?.subject) || by(a?.criterion, b?.criterion) || scorerRank(b?.scorer?.kind) - scorerRank(a?.scorer?.kind);
17124
+ });
17125
+ }
17126
+
17127
+ // ../schema/src/weighing-library.ts
17128
+ function deepFreeze(value) {
17129
+ if (typeof value === "object" && value !== null && !Object.isFrozen(value)) {
17130
+ Object.freeze(value);
17131
+ for (const child of Object.values(value)) deepFreeze(child);
17132
+ }
17133
+ return value;
17134
+ }
17135
+ var VALUE_SET_ID = "value-contribution";
17136
+ var VALUE_SET_VERSION = "2.0.0";
17137
+ var VALUE_SET_V1_VERSION = "1.0.0";
17138
+ var VALUE_MATRIX_ID = "value";
17139
+ var POSITIONING_SET_ID = "positioning";
17140
+ var VALUE_SCALE_ANCHORS = {
17141
+ "3": "Life-wide. It gives the person this well beyond the product and its domain, in their life.",
17142
+ "2": "Across the domain. The person gets this in the whole area the product belongs to, not only inside it.",
17143
+ "1": "Within the product. A real contribution, felt while using it.",
17144
+ "0": "Unrelated: weighed and found to have nothing to do with it. (No row means nobody has weighed it yet.)",
17145
+ "-1": "Within the product. A small cost, felt while using it.",
17146
+ "-2": "Across the domain. The person notices the loss of this in the whole area the product belongs to.",
17147
+ "-3": "Life-wide. It leaves the person with the opposite of this in their life."
17148
+ };
17149
+ var VALUE_SCALE_V1_ANCHORS = {
17150
+ "3": "Core. The promise exists for this; take it away and the value goes.",
17151
+ "2": "Supports clearly. The user would notice it missing.",
17152
+ "1": "Touches. A side effect of the promise, not its purpose.",
17153
+ "0": "Unrelated: weighed and found to have nothing to do with it. (No row means nobody has weighed it yet.)",
17154
+ "-1": "Small friction. It costs this value a little.",
17155
+ "-2": "Works against it. The user notices the cost.",
17156
+ "-3": "Costs it at its core. The user feels the opposite."
17157
+ };
17158
+ var TIER_TITLES = {
17159
+ functional: "Functional",
17160
+ emotional: "Emotional",
17161
+ "life-changing": "Life-changing",
17162
+ "social-impact": "Social impact"
17163
+ };
17164
+ var VALUE_TEXT = {
17165
+ "saves-time": { name: "Saves time", definition: "Completes the user's task in less time." },
17166
+ simplifies: { name: "Simplifies", definition: "Reduces steps, choices, or cognitive load." },
17167
+ "makes-money": { name: "Makes money", definition: "Helps the user earn." },
17168
+ "reduces-risk": { name: "Reduces risk", definition: "Protects against loss, error, or uncertainty." },
17169
+ organizes: { name: "Organizes", definition: "Brings order to the user's things or life." },
17170
+ integrates: { name: "Integrates", definition: "Ties different tools or parts of life together." },
17171
+ connects: { name: "Connects", definition: "Brings the user together with other people." },
17172
+ "reduces-effort": { name: "Reduces effort", definition: "Same outcome, less work." },
17173
+ "avoids-hassles": { name: "Avoids hassles", definition: "Prevents friction and annoyance before it happens." },
17174
+ "reduces-cost": { name: "Reduces cost", definition: "Saves the user money." },
17175
+ quality: { name: "Quality", definition: "Superior craft or performance the user can feel." },
17176
+ variety: { name: "Variety", definition: "Meaningful choice and breadth." },
17177
+ "sensory-appeal": { name: "Sensory appeal", definition: "Looks, sounds, or feels good in the moment." },
17178
+ informs: { name: "Informs", definition: "Tells the user something they want to know." },
17179
+ "reduces-anxiety": { name: "Reduces anxiety", definition: "Calms; makes the user feel safe." },
17180
+ "rewards-me": { name: "Rewards me", definition: "Tangible perks for engagement." },
17181
+ nostalgia: { name: "Nostalgia", definition: "Positive memory of the past." },
17182
+ "design-aesthetics": { name: "Design / aesthetics", definition: "Beauty as an experienced value, beyond function." },
17183
+ "badge-value": { name: "Badge value", definition: "Signals identity or status to others." },
17184
+ wellness: { name: "Wellness", definition: "Improves physical or mental well-being." },
17185
+ "therapeutic-value": { name: "Therapeutic value", definition: "Actively supports emotional processing or healing." },
17186
+ "fun-entertainment": { name: "Fun / entertainment", definition: "Enjoyable, playful, delightful." },
17187
+ attractiveness: { name: "Attractiveness", definition: "Makes the user feel attractive." },
17188
+ "provides-access": { name: "Provides access", definition: "Grants entry to something otherwise out of reach." },
17189
+ "provides-hope": { name: "Provides hope", definition: "Reason to believe things can improve." },
17190
+ "self-actualization": { name: "Self-actualization", definition: "Helps the user become who they want to be." },
17191
+ motivation: { name: "Motivation", definition: "Energizes the user toward their goals." },
17192
+ heirloom: { name: "Heirloom", definition: "Something worth passing on across time." },
17193
+ "affiliation-belonging": { name: "Affiliation & belonging", definition: "Makes the user part of a group that matters." },
17194
+ "self-transcendence": { name: "Self-transcendence", definition: "Helps beyond the user themselves." }
17195
+ };
17196
+ var VALUE_SCALE = { min: -3, max: 3, anchors: { ...VALUE_SCALE_ANCHORS } };
17197
+ var GROUPS = Object.keys(TIER_TITLES).map((id) => ({ id, title: TIER_TITLES[id] }));
17198
+ function reachQuestion(id) {
17199
+ if (id === "informs") {
17200
+ return "Is what this promise mainly gives the person information, rather than an ability, a shortcut, a protection or a feeling? Or does it keep them from knowing something? And how far into their life does it reach?";
17201
+ }
17202
+ return `Does this promise serve, or cost, "${VALUE_TEXT[id].name}" for the person? And how far into their life does it reach: within the product, across its domain, or life-wide?`;
17203
+ }
17204
+ var VALUE_CONTRIBUTION_SET = deepFreeze({
17205
+ id: VALUE_SET_ID,
17206
+ version: VALUE_SET_VERSION,
17207
+ title: "Elements of value",
17208
+ subject: "acceptance",
17209
+ scale: VALUE_SCALE,
17210
+ groups: GROUPS,
17211
+ criteria: VALUE_IDS.map((id) => ({
17212
+ id,
17213
+ group: VALUE_TIERS[id],
17214
+ name: VALUE_TEXT[id].name,
17215
+ question: reachQuestion(id),
17216
+ definition: VALUE_TEXT[id].definition,
17217
+ anchors: { ...VALUE_REACH_LADDERS[id] }
17218
+ }))
17219
+ });
17220
+ var VALUE_CONTRIBUTION_SET_V1 = deepFreeze({
17221
+ id: VALUE_SET_ID,
17222
+ version: VALUE_SET_V1_VERSION,
17223
+ title: "Elements of value",
17224
+ subject: "acceptance",
17225
+ scale: { min: -3, max: 3, anchors: { ...VALUE_SCALE_V1_ANCHORS } },
17226
+ groups: GROUPS,
17227
+ criteria: VALUE_IDS.map((id) => ({
17228
+ id,
17229
+ group: VALUE_TIERS[id],
17230
+ name: VALUE_TEXT[id].name,
17231
+ question: `Does this promise serve, or cost, "${VALUE_TEXT[id].name}"?`,
17232
+ definition: VALUE_TEXT[id].definition
17233
+ }))
17234
+ });
17235
+ var VALUE_MATRIX = deepFreeze({
17236
+ id: VALUE_MATRIX_ID,
17237
+ title: "Value",
17238
+ set: `${VALUE_SET_ID}@2`,
17239
+ subjects: { kind: "query", species: "acceptance" },
17240
+ positioning: POSITIONING_SET_ID,
17241
+ status: "active"
17242
+ });
17243
+ var BUILT_IN_SETS = [VALUE_CONTRIBUTION_SET, VALUE_CONTRIBUTION_SET_V1];
17244
+ var BUILT_IN_MATRICES = [VALUE_MATRIX];
17245
+ var isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
17246
+ function cleaned(set2) {
17247
+ const usable = set2.criteria.filter((criterion) => isObject2(criterion) && typeof criterion.id === "string");
17248
+ return usable.length === set2.criteria.length ? set2 : { ...set2, criteria: usable };
17249
+ }
17250
+ function isWeighingSetShape(set2) {
17251
+ return isObject2(set2) && typeof set2.id === "string" && typeof set2.version === "string" && Array.isArray(set2.criteria) && (isObject2(set2.scale) || set2.role === "positioning");
17252
+ }
17253
+ function isWeighingMatrixShape(matrix) {
17254
+ if (!isObject2(matrix) || typeof matrix.id !== "string" || typeof matrix.set !== "string" || !isObject2(matrix.subjects)) return false;
17255
+ const { kind, species, items } = matrix.subjects;
17256
+ return kind === "query" && typeof species === "string" || kind === "list" && Array.isArray(items);
17257
+ }
17258
+ function isUsableScale(scale) {
17259
+ return isObject2(scale) && typeof scale.min === "number" && typeof scale.max === "number" && isObject2(scale.anchors);
17260
+ }
17261
+ function weighingScaleOf(set2, resolved) {
17262
+ if (isUsableScale(set2.scale)) return set2.scale;
17263
+ const ruler = typeof set2.extends === "string" && resolved !== void 0 ? setOfRef(resolved, set2.extends) : void 0;
17264
+ return ruler !== void 0 && isUsableScale(ruler.scale) ? ruler.scale : VALUE_SCALE;
17265
+ }
17266
+ function resolveWeighing(section) {
17267
+ const sets = [...BUILT_IN_SETS];
17268
+ const matrices = [...BUILT_IN_MATRICES];
17269
+ const skipped = [];
17270
+ const idOf2 = (entry) => isObject2(entry) ? { ...typeof entry.id === "string" ? { id: entry.id } : {}, ...typeof entry.role === "string" ? { role: entry.role } : {} } : {};
17271
+ (Array.isArray(section?.sets) ? section.sets : []).forEach((set2, index) => {
17272
+ if (isWeighingSetShape(set2) && !sets.some((s) => s.id === set2.id)) sets.push(cleaned(set2));
17273
+ else skipped.push({ kind: "set", ...idOf2(set2), index });
17274
+ });
17275
+ (Array.isArray(section?.matrices) ? section.matrices : []).forEach((matrix, index) => {
17276
+ if (isWeighingMatrixShape(matrix) && !matrices.some((m) => m.id === matrix.id)) matrices.push(matrix);
17277
+ else skipped.push({ kind: "matrix", ...idOf2(matrix), index });
17278
+ });
17279
+ return { sets, matrices, skipped };
17280
+ }
17281
+ function setOfRef(resolved, ref) {
17282
+ const { id, major } = splitSetRef(ref);
17283
+ return resolved.sets.find((candidate) => candidate.id === id && (major === void 0 || majorOf(candidate.version) === major));
17284
+ }
17285
+ function isOlderMajorRef(resolved, ref) {
17286
+ const { id, major } = splitSetRef(ref);
17287
+ const current = resolved.sets.find((candidate) => candidate.id === id);
17288
+ if (current === void 0 || major === void 0) return false;
17289
+ const now = Number(majorOf(current.version));
17290
+ return Number.isFinite(now) && Number(major) < now;
17291
+ }
17292
+
17293
+ // ../schema/src/weighing-validate.ts
17294
+ var isObject3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
17295
+ function validateWeighingSection(section, nodeSpecies, journal) {
17296
+ const out = [];
17297
+ const warn = (path6, rule, message) => out.push({ path: path6, rule, message });
17298
+ if (section !== void 0 && section !== null && !isObject3(section)) {
17299
+ warn("weighing", "weighing-section-shape", "The weighing section is not an object \u2014 it is ignored");
17300
+ }
17301
+ if (isObject3(section)) {
17302
+ for (const list of ["sets", "matrices", "assessments"]) {
17303
+ if (section[list] !== void 0 && !Array.isArray(section[list])) {
17304
+ warn(`weighing.${list}`, "weighing-section-shape", `weighing.${list} is not an array \u2014 it is ignored`);
17305
+ }
17306
+ }
17307
+ const sets = Array.isArray(section.sets) ? section.sets : [];
17308
+ const matrices = Array.isArray(section.matrices) ? section.matrices : [];
17309
+ const assessments = Array.isArray(section.assessments) ? section.assessments : [];
17310
+ const resolved = resolveWeighing(section);
17311
+ const resolveRef2 = (ref, path6, who, unknownRule) => {
17312
+ const set2 = setOfRef(resolved, ref);
17313
+ if (set2 !== void 0) return set2;
17314
+ const named = resolved.sets.find((candidate) => candidate.id === splitSetRef(ref).id);
17315
+ if (named !== void 0) {
17316
+ warn(path6, "weighing-set-ref-major", `${who} names ${ref}, but "${named.id}" is at ${named.version} \u2014 levels are comparable only within a major, so the ref resolves to nothing`);
17317
+ } else {
17318
+ warn(path6, unknownRule, `${who} names set "${ref}", which is neither built in nor in this section`);
17319
+ }
17320
+ return void 0;
17321
+ };
17322
+ const positioningIds = new Set(
17323
+ resolved.matrices.map((matrix) => matrix.positioning).filter((id) => typeof id === "string")
17324
+ );
17325
+ const checkStatus = (path6, who, entry) => {
17326
+ if (entry.status !== void 0 && entry.status !== "draft" && entry.status !== "active") {
17327
+ warn(`${path6}.status`, "weighing-set-status", `${who}: status ${JSON.stringify(entry.status)} is not "draft" or "active" \u2014 it is read as a draft, which feeds no roll-up`);
17328
+ }
17329
+ };
17330
+ const isLevelMap = (value) => isObject3(value) && Object.values(value).every((anchor) => typeof anchor === "string");
17331
+ const seenSets = /* @__PURE__ */ new Set();
17332
+ sets.forEach((entry, index) => {
17333
+ const path6 = `weighing.sets[${index}]`;
17334
+ if (!isObject3(entry)) {
17335
+ warn(path6, "weighing-set-shape", "A set is not an object \u2014 it is ignored");
17336
+ return;
17337
+ }
17338
+ const who = `Set "${String(entry.id)}"`;
17339
+ const wellFormed = isWeighingSetShape(entry);
17340
+ if (!wellFormed) {
17341
+ warn(path6, "weighing-set-shape", `${who} needs a string id and version, a criteria array and a scale object (a positioning may leave the scale out) \u2014 it is ignored`);
17342
+ }
17343
+ if (typeof entry.id === "string") {
17344
+ if (BUILT_IN_SETS.some((set2) => set2.id === entry.id)) {
17345
+ warn(`${path6}.id`, "weighing-pinned-set-redefined", `${who} is built in and pinned by version \u2014 the project's copy is ignored`);
17346
+ } else if (wellFormed) {
17347
+ if (seenSets.has(entry.id)) warn(`${path6}.id`, "weighing-duplicate-set", `Duplicate set id "${entry.id}" \u2014 the first well-formed one wins, this one is ignored`);
17348
+ seenSets.add(entry.id);
17349
+ }
17350
+ }
17351
+ checkStatus(path6, who, entry);
17352
+ if (isObject3(entry.scale)) {
17353
+ const scale = entry.scale;
17354
+ if (typeof scale.min !== "number" || typeof scale.max !== "number" || !isLevelMap(scale.anchors)) {
17355
+ warn(`${path6}.scale`, "weighing-scale-shape", `${who}: a scale needs a numeric min and max and an anchors object of strings`);
17356
+ }
17357
+ }
17358
+ if (Array.isArray(entry.criteria)) {
17359
+ entry.criteria.forEach((criterion, at2) => {
17360
+ const cpath = `${path6}.criteria[${at2}]`;
17361
+ if (!isObject3(criterion) || typeof criterion.id !== "string" || criterion.anchors !== void 0 && !isLevelMap(criterion.anchors)) {
17362
+ warn(cpath, "weighing-criterion-shape", `${who}: criterion ${at2} needs a string id, and its anchors (if any) must be an object of strings`);
17363
+ }
17364
+ });
17365
+ }
17366
+ if (entry.role === "positioning" && !(typeof entry.id === "string" && positioningIds.has(entry.id))) {
17367
+ warn(`${path6}.id`, "weighing-positioning-id", `A positioning set must have the id "${POSITIONING_SET_ID}" (the one a matrix points at) \u2014 "${String(entry.id)}" would never be applied`);
17368
+ } else if (entry.role !== "positioning" && entry.id === POSITIONING_SET_ID) {
17369
+ warn(`${path6}.role`, "weighing-positioning-id", `Set "${POSITIONING_SET_ID}" is where a matrix looks for its positioning, but its role is ${JSON.stringify(entry.role)}, not "positioning" \u2014 it would never be applied`);
17370
+ }
17371
+ if (entry.role === "positioning") {
17372
+ const ruler = typeof entry.extends === "string" ? resolveRef2(entry.extends, `${path6}.extends`, `Positioning "${String(entry.id)}"`, "weighing-positioning-unknown-ruler") : void 0;
17373
+ if (typeof entry.extends !== "string") {
17374
+ warn(`${path6}.extends`, "weighing-positioning-unknown-ruler", `Positioning "${String(entry.id)}" does not say which set it re-weights \u2014 set extends to e.g. value-contribution@2`);
17375
+ } else if (ruler !== void 0 && ruler.role === "positioning") {
17376
+ warn(`${path6}.extends`, "weighing-positioning-unknown-ruler", `Positioning "${String(entry.id)}" extends "${entry.extends}", which is itself a positioning \u2014 it must extend a criteria set such as value-contribution@2`);
17377
+ } else if (ruler !== void 0 && isOlderMajorRef(resolved, entry.extends)) {
17378
+ warn(`${path6}.extends`, "weighing-positioning-old-ruler", `Positioning "${String(entry.id)}" extends ${entry.extends}, an older ruler \u2014 its weights still apply, but read its level descriptions against ${ruler.id}'s current major and save it again`);
17379
+ }
17380
+ const known = new Set(ruler !== void 0 && ruler.role !== "positioning" ? ruler.criteria.map((criterion) => criterion?.id) : []);
17381
+ (Array.isArray(entry.criteria) ? entry.criteria : []).forEach((criterion, at2) => {
17382
+ if (!isObject3(criterion)) return;
17383
+ const cpath = `${path6}.criteria[${at2}]`;
17384
+ if (known.size > 0 && typeof criterion.id === "string" && !known.has(criterion.id)) {
17385
+ warn(`${cpath}.id`, "weighing-positioning-unknown-element", `Positioning names "${criterion.id}", which is not in ${String(entry.extends)}`);
17386
+ }
17387
+ if (criterion.weight !== void 0 && (typeof criterion.weight !== "number" || !(criterion.weight > 0))) {
17388
+ warn(`${cpath}.weight`, "weighing-positioning-weight", `Positioning weight for "${String(criterion.id)}" must be a number above 0 \u2014 leave the element out to leave it unpositioned`);
17389
+ }
17390
+ });
17391
+ }
17392
+ });
17393
+ const seenMatrices = /* @__PURE__ */ new Set();
17394
+ matrices.forEach((entry, index) => {
17395
+ const path6 = `weighing.matrices[${index}]`;
17396
+ if (!isObject3(entry)) {
17397
+ warn(path6, "weighing-matrix-shape", "A matrix is not an object \u2014 it is ignored");
17398
+ return;
17399
+ }
17400
+ const who = `Matrix "${String(entry.id)}"`;
17401
+ const wellFormed = isWeighingMatrixShape(entry);
17402
+ if (!wellFormed) {
17403
+ warn(path6, "weighing-matrix-shape", `${who} needs a string id, a set ref and a subjects object of kind query or list \u2014 it is ignored`);
17404
+ }
17405
+ if (typeof entry.id === "string") {
17406
+ if (BUILT_IN_MATRICES.some((matrix) => matrix.id === entry.id)) {
17407
+ warn(`${path6}.id`, "weighing-pinned-matrix-redefined", `${who} is built in \u2014 the project's copy is ignored`);
17408
+ } else if (wellFormed) {
17409
+ if (seenMatrices.has(entry.id)) warn(`${path6}.id`, "weighing-duplicate-matrix", `Duplicate matrix id "${entry.id}" \u2014 the first well-formed one wins, this one is ignored`);
17410
+ seenMatrices.add(entry.id);
17411
+ }
17412
+ }
17413
+ checkStatus(path6, who, entry);
17414
+ if (wellFormed && resolveRef2(entry.set, `${path6}.set`, who, "weighing-unknown-set") !== void 0 && isOlderMajorRef(resolved, entry.set)) {
17415
+ warn(`${path6}.set`, "weighing-matrix-old-ruler", `${who} reads ${entry.set}, an older ruler \u2014 its levels still read, but nothing new can be scored on it; point it at the current major`);
17416
+ }
17417
+ });
17418
+ const seenCells = /* @__PURE__ */ new Set();
17419
+ assessments.forEach((entry, index) => {
17420
+ const path6 = `weighing.assessments[${index}]`;
17421
+ const label = `Assessment ${index}`;
17422
+ if (!isWeighingAssessmentShape(entry)) {
17423
+ warn(path6, "weighing-assessment-shape", `${label}: not an object with a string matrix, subject and criterion \u2014 it cannot be addressed, so every reader skips it`);
17424
+ return;
17425
+ }
17426
+ if (typeof entry.ts !== "string" || Number.isNaN(Date.parse(entry.ts))) {
17427
+ warn(`${path6}.ts`, "weighing-assessment-ts", `${label}: ts must be an ISO 8601 string \u2014 without it "latest wins" cannot order this row`);
17428
+ }
17429
+ const matrix = resolved.matrices.find((candidate) => candidate.id === entry.matrix);
17430
+ if (matrix === void 0) {
17431
+ warn(`${path6}.matrix`, "weighing-unknown-matrix", `${label}: matrix "${entry.matrix}" is not defined`);
17432
+ }
17433
+ const set2 = matrix === void 0 ? void 0 : setOfRef(resolved, matrix.set);
17434
+ const criterion = set2?.criteria.find((candidate) => candidate?.id === entry.criterion);
17435
+ if (set2 !== void 0 && criterion === void 0) {
17436
+ warn(`${path6}.criterion`, "weighing-unknown-criterion", `${label}: criterion "${entry.criterion}" is not in set "${set2.id}"`);
17437
+ }
17438
+ if (criterion !== void 0 && typeof criterion.superseded_by === "string" && criterion.superseded_by !== "") {
17439
+ warn(`${path6}.criterion`, "weighing-retired-criterion", `${label}: criterion "${criterion.id}" is retired \u2014 superseded by "${criterion.superseded_by}"`);
17440
+ }
17441
+ const scale = set2 === void 0 ? void 0 : weighingScaleOf(set2, resolved);
17442
+ const min = typeof scale?.min === "number" ? scale.min : -3;
17443
+ const max = typeof scale?.max === "number" ? scale.max : 3;
17444
+ if (typeof entry.level !== "number" || !Number.isInteger(entry.level) || entry.level < min || entry.level > max) {
17445
+ warn(`${path6}.level`, "weighing-level-range", `${label}: level must be an integer ${min}..${max} (a blank cell is the absence of the row; 0 means weighed and unrelated)`);
17446
+ }
17447
+ if (![0, 1, 2, 3].includes(entry.confidence)) {
17448
+ warn(`${path6}.confidence`, "weighing-confidence-range", `${label}: confidence must be 0, 1, 2 or 3`);
17449
+ }
17450
+ const scorer = isObject3(entry.scorer) ? entry.scorer : void 0;
17451
+ if (scorer === void 0 || typeof scorer.kind !== "string" || typeof scorer.id !== "string" || scorer.id === "") {
17452
+ warn(`${path6}.scorer`, "weighing-scorer-missing", `${label}: no scorer with a string kind and id \u2014 human, agent and rule levels become indistinguishable, and the row can win no cell`);
17453
+ } else if (!SCORER_KINDS.includes(scorer.kind)) {
17454
+ warn(`${path6}.scorer.kind`, "weighing-scorer-kind", `${label}: scorer kind "${scorer.kind}" is not one of ${SCORER_KINDS.join(", ")} \u2014 it ranks below every other scorer`);
17455
+ } else if (!STORED_SCORER_KINDS.includes(scorer.kind)) {
17456
+ warn(`${path6}.scorer.kind`, "weighing-rule-stored", `${label}: scorer kind "${scorer.kind}" is never stored \u2014 a seeding rule is computed on read`);
17457
+ }
17458
+ if (matrix?.subjects.kind === "query") {
17459
+ const species = nodeSpecies.get(entry.subject);
17460
+ if (species === void 0) {
17461
+ warn(`${path6}.subject`, "weighing-unknown-subject", `${label}: subject "${entry.subject}" is not a node in this bundle`);
17462
+ } else if (species !== matrix.subjects.species) {
17463
+ warn(`${path6}.subject`, "weighing-subject-species", `${label}: subject "${entry.subject}" is a ${species}, and matrix "${matrix.id}" judges ${String(matrix.subjects.species)} nodes`);
17464
+ }
17465
+ }
17466
+ if (entry.evidence !== void 0 && typeof entry.evidence !== "string") {
17467
+ warn(`${path6}.evidence`, "weighing-evidence-type", `${label}: evidence must be a markdown string`);
17468
+ } else if ((entry.confidence === 2 || entry.confidence === 3) && (entry.evidence === void 0 || entry.evidence.trim() === "")) {
17469
+ warn(`${path6}.evidence`, "weighing-no-evidence", `${label}: confidence ${String(entry.confidence)} claims evidence and cites none`);
17470
+ }
17471
+ for (const field of WEIGHING_PROBABILITY_FIELDS) {
17472
+ if (entry[field] !== void 0 && !isWeighingProbability(entry[field])) {
17473
+ warn(`${path6}.${field}`, "weighing-probability-shape", `${label}: ${field} must be a number from 0 to 1 \u2014 it is ignored`);
17474
+ }
17475
+ }
17476
+ if (entry.refs !== void 0 && !(Array.isArray(entry.refs) && entry.refs.every((ref) => typeof ref === "string"))) {
17477
+ warn(`${path6}.refs`, "weighing-refs-type", `${label}: refs must be an array of id strings`);
17478
+ }
17479
+ if (entry.basis !== void 0 && !(isObject3(entry.basis) && ["fingerprint", "commit", "set_version"].every((key) => entry.basis[key] === void 0 || typeof entry.basis[key] === "string"))) {
17480
+ warn(`${path6}.basis`, "weighing-basis-shape", `${label}: basis must be an object whose fingerprint, commit and set_version are strings`);
17481
+ }
17482
+ if (scorer !== void 0 && typeof scorer.kind === "string") {
17483
+ const key = assessmentKey(entry);
17484
+ if (seenCells.has(key)) {
17485
+ warn(path6, "weighing-duplicate-assessment", `${label}: a second ${scorer.kind} score for the same cell \u2014 the section stores latest-per-scorer-kind, so this cell is ambiguous`);
17486
+ }
17487
+ seenCells.add(key);
17488
+ }
17489
+ const setVersion = isObject3(entry.basis) && typeof entry.basis.set_version === "string" ? entry.basis.set_version : void 0;
17490
+ if (set2 !== void 0 && setVersion !== void 0 && majorOf(setVersion) !== majorOf(set2.version)) {
17491
+ warn(`${path6}.basis.set_version`, "weighing-set-major", `${label}: scored against ${set2.id} ${setVersion}, and the set is now ${set2.version} \u2014 levels are comparable only within a major`);
17492
+ }
17493
+ });
17494
+ }
17495
+ journal.forEach((entry, index) => {
17496
+ if (!isObject3(entry)) return;
17497
+ const type = typeof entry.type === "string" ? entry.type : "";
17498
+ if (type !== WEIGHING_ASSESSMENT_RECORDED && type !== WEIGHING_SET_SAVED) return;
17499
+ if (typeof entry.actor !== "string" || entry.actor.trim() === "") {
17500
+ warn(`journal[${index}].actor`, "weighing-event-no-actor", `Journal event ${index}: ${type} has no actor \u2014 human, agent and CI scores become indistinguishable`);
17501
+ }
17502
+ });
17503
+ return out;
17504
+ }
17505
+
16705
17506
  // ../schema/src/validate.ts
16706
17507
  var VALID_STAGES = ["beta", "monitoring", "deprecated"];
16707
17508
  var VALID_VIEW_CARD_VARIANTS = ["compact", "large"];
@@ -17552,6 +18353,13 @@ function validateBundle(input) {
17552
18353
  }
17553
18354
  });
17554
18355
  }
18356
+ const weighing = bundle.weighing;
18357
+ const embeddedJournal = Array.isArray(bundle.journal) ? bundle.journal : [];
18358
+ const weighingSpecies = /* @__PURE__ */ new Map();
18359
+ for (const [id, node] of nodeMap) weighingSpecies.set(id, String(node.species));
18360
+ for (const finding of validateWeighingSection(weighing, weighingSpecies, embeddedJournal)) {
18361
+ warn(finding.path, finding.rule, finding.message);
18362
+ }
17555
18363
  for (const finding of crossCheckJournal(bundle)) findings.push(finding);
17556
18364
  return result();
17557
18365
  }
@@ -17885,7 +18693,7 @@ function edgeRemovedInput(edgeId2) {
17885
18693
  }
17886
18694
  var TOP_LEVEL_FIELDS = ["species", "title", "description", "status", "platforms"];
17887
18695
  var MAX_SCALAR_LEN = 512;
17888
- function isRecord3(value) {
18696
+ function isRecord4(value) {
17889
18697
  return typeof value === "object" && value !== null && !Array.isArray(value);
17890
18698
  }
17891
18699
  function isShortScalar(value) {
@@ -17896,8 +18704,8 @@ function valueEqual(a, b) {
17896
18704
  return JSON.stringify(a) === JSON.stringify(b);
17897
18705
  }
17898
18706
  function changedMapKeys(prev, next) {
17899
- const p = isRecord3(prev) ? prev : {};
17900
- const n = isRecord3(next) ? next : {};
18707
+ const p = isRecord4(prev) ? prev : {};
18708
+ const n = isRecord4(next) ? next : {};
17901
18709
  const changed = [];
17902
18710
  for (const key of /* @__PURE__ */ new Set([...Object.keys(p), ...Object.keys(n)])) {
17903
18711
  if (!valueEqual(p[key], n[key])) changed.push(key);
@@ -17905,8 +18713,8 @@ function changedMapKeys(prev, next) {
17905
18713
  return changed.sort();
17906
18714
  }
17907
18715
  function diffPlatformStatuses(nodeId, currentBase, nextBase, prev, next) {
17908
- const p = isRecord3(prev) ? prev : {};
17909
- const n = isRecord3(next) ? next : {};
18716
+ const p = isRecord4(prev) ? prev : {};
18717
+ const n = isRecord4(next) ? next : {};
17910
18718
  const events = [];
17911
18719
  for (const platform of [.../* @__PURE__ */ new Set([...Object.keys(p), ...Object.keys(n)])].sort()) {
17912
18720
  const from = p[platform];
@@ -17930,7 +18738,7 @@ function diffRefs(nodeId, prev, next) {
17930
18738
  const byId = (arr) => {
17931
18739
  const map2 = /* @__PURE__ */ new Map();
17932
18740
  for (const item of arr) {
17933
- if (isRecord3(item) && typeof item.id === "string") map2.set(item.id, item);
18741
+ if (isRecord4(item) && typeof item.id === "string") map2.set(item.id, item);
17934
18742
  }
17935
18743
  return map2;
17936
18744
  };
@@ -17970,8 +18778,8 @@ function diffNodeUpdate(current, patch) {
17970
18778
  }
17971
18779
  }
17972
18780
  if ("metadata" in pat) {
17973
- const prevMeta = isRecord3(current.metadata) ? current.metadata : {};
17974
- const nextMeta = isRecord3(patch.metadata) ? patch.metadata : {};
18781
+ const prevMeta = isRecord4(current.metadata) ? current.metadata : {};
18782
+ const nextMeta = isRecord4(patch.metadata) ? patch.metadata : {};
17975
18783
  const currentBase = current.status;
17976
18784
  const nextBase = "status" in pat && pat.status !== void 0 ? pat.status : current.status;
17977
18785
  for (const key of /* @__PURE__ */ new Set([...Object.keys(prevMeta), ...Object.keys(nextMeta)])) {
@@ -18378,13 +19186,13 @@ var REGRESSION_SIGNALS = {
18378
19186
  "new-severe-finding": "no open Critical or High finding on this cell",
18379
19187
  "reopened-finding": "a resolved finding stays resolved"
18380
19188
  };
18381
- var cellKey = (criterionId, surface) => `${criterionId}::${surface}`;
19189
+ var cellKey2 = (criterionId, surface) => `${criterionId}::${surface}`;
18382
19190
  var rowsOf = (value) => Array.isArray(value) ? value : [];
18383
19191
  function assessmentsByCell(state) {
18384
19192
  const cells = /* @__PURE__ */ new Map();
18385
19193
  for (const assessment of rowsOf(state?.assessments)) {
18386
19194
  if (typeof assessment?.criterion_id !== "string" || typeof assessment?.surface !== "string") continue;
18387
- cells.set(cellKey(assessment.criterion_id, assessment.surface), assessment);
19195
+ cells.set(cellKey2(assessment.criterion_id, assessment.surface), assessment);
18388
19196
  }
18389
19197
  return cells;
18390
19198
  }
@@ -18395,7 +19203,7 @@ function severeByCell(state, library) {
18395
19203
  if (!isOpenFinding(finding)) continue;
18396
19204
  const severity = severityOf(finding, library);
18397
19205
  if (severity !== "critical" && severity !== "high") continue;
18398
- const key = cellKey(finding.criterion_id, finding.surface);
19206
+ const key = cellKey2(finding.criterion_id, finding.surface);
18399
19207
  const existing = cells.get(key);
18400
19208
  if (existing === void 0) cells.set(key, [finding]);
18401
19209
  else existing.push(finding);
@@ -18451,7 +19259,7 @@ function detectRegressions(previous, next, library) {
18451
19259
 
18452
19260
  // ../schema/src/quality-trend.ts
18453
19261
  var NO_DELTA = { previous: null, delta: null };
18454
- var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
19262
+ var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
18455
19263
  function frameworkMajor(version2) {
18456
19264
  if (typeof version2 !== "string") return null;
18457
19265
  const match = /^\s*v?(\d+)/.exec(version2);
@@ -18464,27 +19272,27 @@ function sameFrameworkMajor(a, b) {
18464
19272
  }
18465
19273
  function scopeOf(raw) {
18466
19274
  if (readPlanScope(raw) !== null) return void 0;
18467
- if (!isRecord4(raw) || typeof raw.since !== "string" || raw.since === "") return void 0;
19275
+ if (!isRecord5(raw) || typeof raw.since !== "string" || raw.since === "") return void 0;
18468
19276
  return { scope: { since: raw.since, cells: typeof raw.cells === "number" && Number.isFinite(raw.cells) ? raw.cells : null } };
18469
19277
  }
18470
19278
  function cleanScores(raw) {
18471
19279
  const scores = {};
18472
- if (!isRecord4(raw)) return scores;
19280
+ if (!isRecord5(raw)) return scores;
18473
19281
  for (const surface of Object.keys(raw)) {
18474
19282
  const bySurface = raw[surface];
18475
- if (!isRecord4(bySurface)) continue;
18476
- const cleaned = {};
19283
+ if (!isRecord5(bySurface)) continue;
19284
+ const cleaned2 = {};
18477
19285
  for (const domain2 of Object.keys(bySurface)) {
18478
19286
  const score = bySurface[domain2];
18479
- if (typeof score === "number" && Number.isFinite(score)) cleaned[domain2] = score;
19287
+ if (typeof score === "number" && Number.isFinite(score)) cleaned2[domain2] = score;
18480
19288
  }
18481
- scores[surface] = cleaned;
19289
+ scores[surface] = cleaned2;
18482
19290
  }
18483
19291
  return scores;
18484
19292
  }
18485
19293
  function cleanCounts(raw) {
18486
19294
  const counts = { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
18487
- if (!isRecord4(raw)) return counts;
19295
+ if (!isRecord5(raw)) return counts;
18488
19296
  for (const severity of Object.keys(counts)) {
18489
19297
  const value = raw[severity];
18490
19298
  if (typeof value === "number" && Number.isFinite(value)) counts[severity] = value;
@@ -18502,7 +19310,7 @@ function liveScores(live) {
18502
19310
  const scores = {};
18503
19311
  for (const domain2 of Object.keys(live.matrix ?? {})) {
18504
19312
  const row = live.matrix[domain2];
18505
- if (!isRecord4(row)) continue;
19313
+ if (!isRecord5(row)) continue;
18506
19314
  for (const surface of Object.keys(row)) {
18507
19315
  const cell = row[surface];
18508
19316
  if (!cell || typeof cell.score !== "number") continue;
@@ -18522,7 +19330,7 @@ function deriveQualityTrend(events, profile, live) {
18522
19330
  const weights = profile?.domain_weights;
18523
19331
  const byAudit = /* @__PURE__ */ new Map();
18524
19332
  const audits = (Array.isArray(events) ? events : []).filter(
18525
- (event) => isRecord4(event) && event.type === "quality.audit.completed"
19333
+ (event) => isRecord5(event) && event.type === "quality.audit.completed"
18526
19334
  );
18527
19335
  for (const event of orderEvents(audits)) {
18528
19336
  const auditId = typeof event.audit_id === "string" ? event.audit_id : typeof event.id === "string" ? event.id : "";
@@ -18629,7 +19437,7 @@ function formatDelta(delta) {
18629
19437
  var rowsOf2 = (value) => Array.isArray(value) ? value : [];
18630
19438
  var isString = (value) => typeof value === "string" && value !== "";
18631
19439
  var stringsOf = (value) => rowsOf2(value).filter(isString);
18632
- var cellKey2 = (criterionId, surface) => `${criterionId}::${surface}`;
19440
+ var cellKey3 = (criterionId, surface) => `${criterionId}::${surface}`;
18633
19441
  var orderedRows = (events) => orderEvents(rowsOf2(events).filter((event) => typeof event === "object" && event !== null));
18634
19442
  function isPlanRecord(event) {
18635
19443
  if (typeof event !== "object" || event === null) return false;
@@ -18713,7 +19521,7 @@ function deriveAuditScope(events, section, library, options = {}) {
18713
19521
  for (const assessment of rowsOf2(section?.assessments)) {
18714
19522
  if (!isString(assessment?.criterion_id) || !isString(assessment?.surface) || !isString(assessment?.audit_id)) continue;
18715
19523
  if (!isString(assessment.ts)) continue;
18716
- const key = cellKey2(assessment.criterion_id, assessment.surface);
19524
+ const key = cellKey3(assessment.criterion_id, assessment.surface);
18717
19525
  const byAudit = scoredAt.get(key) ?? /* @__PURE__ */ new Map();
18718
19526
  const seen = byAudit.get(assessment.audit_id);
18719
19527
  if (seen === void 0 || seen < assessment.ts) byAudit.set(assessment.audit_id, assessment.ts);
@@ -18769,7 +19577,7 @@ function deriveAuditScope(events, section, library, options = {}) {
18769
19577
  const assessmentByCell = /* @__PURE__ */ new Map();
18770
19578
  for (const assessment of rowsOf2(section?.assessments)) {
18771
19579
  if (!isString(assessment?.criterion_id) || !isString(assessment?.surface)) continue;
18772
- assessmentByCell.set(cellKey2(assessment.criterion_id, assessment.surface), assessment);
19580
+ assessmentByCell.set(cellKey3(assessment.criterion_id, assessment.surface), assessment);
18773
19581
  }
18774
19582
  const declared = rowsOf2(section?.profile?.surfaces).map((surface) => surface?.id).filter((id) => isString(id) && id !== CROSS_SURFACE_ID);
18775
19583
  const surfaces = declared.length > 0 ? [...new Set(declared)] : [...new Set([...assessmentByCell.values()].map((assessment) => assessment.surface))].filter((id) => id !== CROSS_SURFACE_ID).sort();
@@ -18782,7 +19590,7 @@ function deriveAuditScope(events, section, library, options = {}) {
18782
19590
  };
18783
19591
  const cells = /* @__PURE__ */ new Map();
18784
19592
  const addDirect = (criterionId, surface, findingId) => {
18785
- const key = cellKey2(criterionId, surface);
19593
+ const key = cellKey3(criterionId, surface);
18786
19594
  const existing = cells.get(key);
18787
19595
  if (existing === void 0) cells.set(key, { criterion_id: criterionId, surface, kind: "direct", because: [findingId] });
18788
19596
  else if (!existing.because.includes(findingId)) existing.because.push(findingId);
@@ -18811,7 +19619,7 @@ function deriveAuditScope(events, section, library, options = {}) {
18811
19619
  unscorable.push(findingId);
18812
19620
  continue;
18813
19621
  }
18814
- const live = targets.filter((surface) => countsFor(cellKey2(finding.criterion_id, surface), resolution.last));
19622
+ const live = targets.filter((surface) => countsFor(cellKey3(finding.criterion_id, surface), resolution.last));
18815
19623
  if (live.length === 0) continue;
18816
19624
  drivers.push(findingId);
18817
19625
  if (resolution.resolved_by !== void 0) resolvedBy[findingId] = resolution.resolved_by;
@@ -18821,7 +19629,7 @@ function deriveAuditScope(events, section, library, options = {}) {
18821
19629
  if (options.widen !== false && resolvedNodes.size > 0) {
18822
19630
  const nodesByCell = /* @__PURE__ */ new Map();
18823
19631
  const noteNodes = (criterionId, surface, nodes) => {
18824
- const key = cellKey2(criterionId, surface);
19632
+ const key = cellKey3(criterionId, surface);
18825
19633
  const bucket = nodesByCell.get(key) ?? /* @__PURE__ */ new Set();
18826
19634
  for (const node of nodes) bucket.add(node);
18827
19635
  nodesByCell.set(key, bucket);
@@ -18930,13 +19738,13 @@ var EVENT_CAUSE = {
18930
19738
  "quality.finding.accepted": "accepted",
18931
19739
  "quality.audit.completed": "audit"
18932
19740
  };
18933
- var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
19741
+ var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
18934
19742
  var isString2 = (value) => typeof value === "string" && value !== "";
18935
19743
  var emptyCounts = () => ({ critical: 0, high: 0, medium: 0, low: 0, info: 0 });
18936
19744
  var asSeverity = (value) => typeof value === "string" && FINDING_SEVERITIES.includes(value) ? value : null;
18937
19745
  function cleanCounts2(raw) {
18938
19746
  const counts = emptyCounts();
18939
- if (!isRecord5(raw)) return counts;
19747
+ if (!isRecord6(raw)) return counts;
18940
19748
  for (const severity of FINDING_SEVERITIES) {
18941
19749
  const value = raw[severity];
18942
19750
  if (typeof value === "number" && Number.isFinite(value) && value > 0) counts[severity] = value;
@@ -18951,7 +19759,7 @@ function deriveFindingsBurndown(events, options = {}) {
18951
19759
  const filtered = surface !== void 0 || domain2 !== void 0;
18952
19760
  const sectionById = /* @__PURE__ */ new Map();
18953
19761
  for (const finding of Array.isArray(options.findings) ? options.findings : []) {
18954
- if (isRecord5(finding) && isString2(finding.id)) sectionById.set(finding.id, finding);
19762
+ if (isRecord6(finding) && isString2(finding.id)) sectionById.set(finding.id, finding);
18955
19763
  }
18956
19764
  const inView = (where2) => {
18957
19765
  if (!filtered) return true;
@@ -18963,7 +19771,7 @@ function deriveFindingsBurndown(events, options = {}) {
18963
19771
  return true;
18964
19772
  };
18965
19773
  const relevant = (Array.isArray(events) ? events : []).filter(
18966
- (event) => isRecord5(event) && typeof event.type === "string" && event.type in EVENT_CAUSE
19774
+ (event) => isRecord6(event) && typeof event.type === "string" && event.type in EVENT_CAUSE
18967
19775
  );
18968
19776
  const openedIds = /* @__PURE__ */ new Set();
18969
19777
  const decidedIds = /* @__PURE__ */ new Set();
@@ -19084,6 +19892,10 @@ function burndownSummary(burndown, openNow) {
19084
19892
  return `${closed} closed${where2} (${tally.resolved} resolved, ${tally.accepted} accepted) \xB7 ${tally.opened} opened \xB7 ${open} open`;
19085
19893
  }
19086
19894
 
19895
+ // ../schema/src/weighing-derive.ts
19896
+ var SEED_SCORER_ID = "seed-claimed";
19897
+ var SEED_SCORER = Object.freeze({ kind: "rule", id: SEED_SCORER_ID });
19898
+
19087
19899
  // src/commands/init.ts
19088
19900
  var DEFAULT_BUNDLE_PATH = "docs/arkaik/bundle.json";
19089
19901
  var DEFAULT_JOURNAL_PATH = "docs/arkaik/journal.jsonl";
@@ -20459,7 +21271,7 @@ ${USAGE6}`);
20459
21271
  }
20460
21272
 
20461
21273
  // src/commands/pack.ts
20462
- import { existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync6 } from "node:fs";
21274
+ import { existsSync as existsSync9, mkdirSync as mkdirSync4, readFileSync as readFileSync7, writeFileSync as writeFileSync6 } from "node:fs";
20463
21275
  import { dirname as dirname5, extname, resolve as resolve5 } from "node:path";
20464
21276
 
20465
21277
  // src/lib/kritik-io.ts
@@ -20765,15 +21577,72 @@ function resolveQualityRoot(options) {
20765
21577
  return options.fallback;
20766
21578
  }
20767
21579
 
21580
+ // ../schema/src/cli/weighing-files.ts
21581
+ import { existsSync as existsSync8, readdirSync as readdirSync3 } from "node:fs";
21582
+ import { join as join6 } from "node:path";
21583
+ var WEIGHING_DIR = "docs/weighing";
21584
+ var WEIGHING_SETS_DIR = "sets";
21585
+ var WEIGHING_ASSESSMENTS_DIR = "assessments";
21586
+ var weighingDir = (root) => join6(root, WEIGHING_DIR);
21587
+ function jsonFilesIn(dir) {
21588
+ if (!existsSync8(dir)) return [];
21589
+ return readdirSync3(dir).filter((name) => name.endsWith(".json")).sort().map((name) => join6(dir, name));
21590
+ }
21591
+ function assessmentsOfFile(file2) {
21592
+ const parsed = readJson(file2);
21593
+ const assessments = typeof parsed === "object" && parsed !== null ? parsed.assessments : void 0;
21594
+ if (!Array.isArray(assessments)) throw new Error(`${file2}: expected { "matrix": \u2026, "assessments": [] }`);
21595
+ return assessments;
21596
+ }
21597
+ function loadWeighingSets(root) {
21598
+ return jsonFilesIn(join6(weighingDir(root), WEIGHING_SETS_DIR)).map((file2) => {
21599
+ const parsed = readJson(file2);
21600
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`${file2}: expected a criteria set object`);
21601
+ return parsed;
21602
+ });
21603
+ }
21604
+ function loadWeighingAssessments(root) {
21605
+ return jsonFilesIn(join6(weighingDir(root), WEIGHING_ASSESSMENTS_DIR)).flatMap(assessmentsOfFile);
21606
+ }
21607
+ function loadWeighingSection(root) {
21608
+ const sets = loadWeighingSets(root);
21609
+ const assessments = loadWeighingAssessments(root);
21610
+ if (sets.length === 0 && assessments.length === 0) return void 0;
21611
+ return { sets, matrices: [], assessments: sortWeighingAssessments(assessments) };
21612
+ }
21613
+
21614
+ // src/lib/weighing-io.ts
21615
+ function isSection(value) {
21616
+ return typeof value === "object" && value !== null && !Array.isArray(value);
21617
+ }
21618
+ function foldWeighingSection(bundle, root) {
21619
+ const section = loadWeighingSection(root);
21620
+ if (section === void 0) {
21621
+ const carriedSection = isSection(bundle.weighing);
21622
+ return {
21623
+ folded: false,
21624
+ carriedSection,
21625
+ notice: carriedSection ? `Weighing: none to fold \u2014 no files under ${weighingDir(root)}
21626
+ Kept the weighing section this bundle already carried \u2014 nothing replaced it.` : `Weighing: none to fold \u2014 no files under ${weighingDir(root)}`
21627
+ };
21628
+ }
21629
+ bundle.weighing = section;
21630
+ return {
21631
+ folded: true,
21632
+ carriedSection: false,
21633
+ notice: `Weighing: folded ${section.assessments?.length ?? 0} assessment(s), ${section.sets?.length ?? 0} set(s) from ${weighingDir(root)}`
21634
+ };
21635
+ }
21636
+
20768
21637
  // src/commands/pack.ts
20769
21638
  var DEFAULT_BUNDLE_PATH6 = "docs/arkaik/bundle.json";
20770
- var USAGE7 = `arkaik pack [--no-journal] [--no-quality] [--inline-assets] [--audit <id>]
20771
- [--root <dir>] [--out <path>] [path]
21639
+ var USAGE7 = `arkaik pack [--no-journal] [--no-quality] [--no-weighing] [--inline-assets]
21640
+ [--audit <id>] [--root <dir>] [--out <path>] [path]
20772
21641
 
20773
21642
  Produce a single self-contained interchange bundle: fold in the sidecar
20774
21643
  journal (or keep an existing embedded one), fold docs/quality/ into the
20775
- quality section, and, with --inline-assets, inline local screenshot files as
20776
- data: URIs. Written canonically via serializeBundle. Unknown top-level keys
21644
+ quality section, fold docs/weighing/ into the weighing section, and, with
21645
+ --inline-assets, inline local screenshot files as data: URIs. Written canonically via serializeBundle. Unknown top-level keys
20777
21646
  and unknown fields always round-trip.
20778
21647
 
20779
21648
  Arguments:
@@ -20794,6 +21663,10 @@ Options:
20794
21663
  find it in. ("arkaik push" packs this way by default;
20795
21664
  its --include-quality opts back in.)
20796
21665
  Default: docs/quality/ IS folded in.
21666
+ --no-weighing DELETE the weighing section rather than folding one in, for
21667
+ the same reason --no-quality deletes: a source bundle that
21668
+ already carried one must not be packed with it either.
21669
+ Default: docs/weighing/ IS folded in.
20797
21670
  --inline-assets Convert relative-path metadata.platformScreenshots values
20798
21671
  into data: URIs by reading the file from disk (resolved
20799
21672
  against the bundle's directory). Absolute https:// URLs
@@ -20885,6 +21758,20 @@ function runPack(options = {}) {
20885
21758
  return fatalResult2(filePath, e.message);
20886
21759
  }
20887
21760
  }
21761
+ let weighingFolded;
21762
+ let weighingNotice;
21763
+ if (options.noWeighing ?? false) {
21764
+ delete bundle.weighing;
21765
+ } else {
21766
+ const root = resolveQualityRoot({ root: options.root, bundlePath: filePath, fallback: cwd });
21767
+ try {
21768
+ const fold = foldWeighingSection(bundle, root);
21769
+ weighingFolded = fold.folded;
21770
+ weighingNotice = fold.notice;
21771
+ } catch (e) {
21772
+ return fatalResult2(filePath, e.message);
21773
+ }
21774
+ }
20888
21775
  const inlinedAssets = [];
20889
21776
  const assetWarnings = [];
20890
21777
  if (inlineAssets) {
@@ -20900,7 +21787,7 @@ function runPack(options = {}) {
20900
21787
  for (const [platform, value] of Object.entries(map2)) {
20901
21788
  if (typeof value !== "string" || !isRelativeAssetPath(value)) continue;
20902
21789
  const assetPath = resolve5(bundleDir, value);
20903
- if (!existsSync8(assetPath)) {
21790
+ if (!existsSync9(assetPath)) {
20904
21791
  assetWarnings.push(`${nodeId}/${platform}: asset not found at ${assetPath} \u2014 left as-is`);
20905
21792
  continue;
20906
21793
  }
@@ -20918,11 +21805,25 @@ function runPack(options = {}) {
20918
21805
  mkdirSync4(dirname5(outPath), { recursive: true });
20919
21806
  writeFileSync6(outPath, output);
20920
21807
  }
20921
- return { ok: true, bundlePath: filePath, outPath, journalIncluded, journalEventCount, inlinedAssets, assetWarnings, qualityFolded, qualityNotice, output };
21808
+ return {
21809
+ ok: true,
21810
+ bundlePath: filePath,
21811
+ outPath,
21812
+ journalIncluded,
21813
+ journalEventCount,
21814
+ inlinedAssets,
21815
+ assetWarnings,
21816
+ qualityFolded,
21817
+ qualityNotice,
21818
+ weighingFolded,
21819
+ weighingNotice,
21820
+ output
21821
+ };
20922
21822
  }
20923
21823
  function runPackCli(args) {
20924
21824
  let noJournal = false;
20925
21825
  let noQuality = false;
21826
+ let noWeighing = false;
20926
21827
  let inlineAssets = false;
20927
21828
  let audit;
20928
21829
  let root;
@@ -20937,6 +21838,8 @@ function runPackCli(args) {
20937
21838
  noJournal = true;
20938
21839
  } else if (arg === "--no-quality") {
20939
21840
  noQuality = true;
21841
+ } else if (arg === "--no-weighing") {
21842
+ noWeighing = true;
20940
21843
  } else if (arg === "--inline-assets") {
20941
21844
  inlineAssets = true;
20942
21845
  } else if (arg === "--audit") {
@@ -20971,7 +21874,7 @@ ${USAGE7}`);
20971
21874
  ${USAGE7}`);
20972
21875
  }
20973
21876
  const filePath = positionals[0] ?? DEFAULT_BUNDLE_PATH6;
20974
- const result = runPack({ path: filePath, out, noJournal, inlineAssets, noQuality, audit, root });
21877
+ const result = runPack({ path: filePath, out, noJournal, inlineAssets, noQuality, noWeighing, audit, root });
20975
21878
  if (!result.ok) fail7(`FATAL: ${result.fatal}`);
20976
21879
  if (result.journalIncluded) {
20977
21880
  console.error(`Journal: embedded ${result.journalEventCount} event(s)`);
@@ -20983,6 +21886,9 @@ ${USAGE7}`);
20983
21886
  if (result.qualityNotice !== void 0) {
20984
21887
  console.error(result.qualityNotice);
20985
21888
  }
21889
+ if (result.weighingNotice !== void 0) {
21890
+ console.error(result.weighingNotice);
21891
+ }
20986
21892
  for (const asset of result.inlinedAssets) {
20987
21893
  console.error(`Inlined asset: ${asset.nodeId}/${asset.platform} (${asset.path})`);
20988
21894
  }
@@ -21001,7 +21907,7 @@ ${USAGE7}`);
21001
21907
  import { spawn } from "node:child_process";
21002
21908
  import { mkdtempSync, writeFileSync as writeFileSync7 } from "node:fs";
21003
21909
  import { tmpdir } from "node:os";
21004
- import { join as join6, resolve as resolve6 } from "node:path";
21910
+ import { join as join7, resolve as resolve6 } from "node:path";
21005
21911
  var DEFAULT_BUNDLE_PATH7 = "docs/arkaik/bundle.json";
21006
21912
  var OPEN_URL = "https://arkaik.app/projects";
21007
21913
  var USAGE8 = `arkaik open [--out <path>] [--no-open] [path]
@@ -21054,8 +21960,8 @@ async function runOpen(options = {}) {
21054
21960
  }
21055
21961
  let outPath = packed.outPath;
21056
21962
  if (outPath === void 0) {
21057
- const dir = mkdtempSync(join6(tmpdir(), "arkaik-open-"));
21058
- outPath = join6(dir, "bundle.json");
21963
+ const dir = mkdtempSync(join7(tmpdir(), "arkaik-open-"));
21964
+ outPath = join7(dir, "bundle.json");
21059
21965
  writeFileSync7(outPath, packed.output);
21060
21966
  }
21061
21967
  let opened = false;
@@ -21131,7 +22037,8 @@ ${USAGE8}`);
21131
22037
  import { resolve as resolve7 } from "node:path";
21132
22038
  var DEFAULT_BUNDLE_PATH8 = "docs/arkaik/bundle.json";
21133
22039
  var DEFAULT_API_BASE = "https://arkaik.app";
21134
- var USAGE9 = `arkaik push [--include-journal] [--include-quality] [--api <base-url>] [path]
22040
+ var USAGE9 = `arkaik push [--include-journal] [--include-quality] [--include-weighing]
22041
+ [--api <base-url>] [path]
21135
22042
  arkaik push --delete <id> --key <owner_key> [--api <base-url>]
21136
22043
 
21137
22044
  Publish a project bundle to Publik (anonymous, account-less snapshot
@@ -21147,7 +22054,9 @@ knows to keep it.
21147
22054
 
21148
22055
  A Kritik "quality" section is stripped by default too, and separately:
21149
22056
  publishing your history and publishing your open findings are two decisions,
21150
- not one, and both default to no. --include-quality opts in.
22057
+ not one, and both default to no. --include-quality opts in. A "weighing"
22058
+ section (a positioning and the assessments scored against it) is a third
22059
+ decision with a third default of no: --include-weighing opts in.
21151
22060
 
21152
22061
  Snapshots are immutable: there is no update verb. Pushing again always mints
21153
22062
  a new id. The owner key printed on success is shown exactly once and cannot
@@ -21168,6 +22077,11 @@ Options:
21168
22077
  \xA7 8.3) \u2014 publishing that is a decision worth typing.
21169
22078
  Default: deleted before packing, so it is never in the
21170
22079
  request body at all.
22080
+ --include-weighing Embed the weighing section and forward
22081
+ ?include_weighing=true. Opt-in: it holds what the
22082
+ product scores its own promises, costs included.
22083
+ Default: deleted before packing, so it is never in
22084
+ the request body at all.
21171
22085
  --api <base-url> Publik API base URL (default: ${DEFAULT_API_BASE}).
21172
22086
  Point at a self-hosted deployment.
21173
22087
  --delete <id> Delete a snapshot by id instead of pushing. Requires
@@ -21195,6 +22109,7 @@ async function runPush(options = {}) {
21195
22109
  const filePath = resolve7(cwd, options.path ?? DEFAULT_BUNDLE_PATH8);
21196
22110
  const includeJournal = options.includeJournal ?? false;
21197
22111
  const includeQuality = options.includeQuality ?? false;
22112
+ const includeWeighing = options.includeWeighing ?? false;
21198
22113
  const apiBase = options.apiBase ?? DEFAULT_API_BASE;
21199
22114
  const httpClient = options.httpClient ?? DEFAULT_HTTP_CLIENT;
21200
22115
  let v;
@@ -21208,7 +22123,13 @@ async function runPush(options = {}) {
21208
22123
  if (!v.valid) {
21209
22124
  return { ok: true, bundlePath: filePath, valid: false, errorLines, warningLines, requestSent: false };
21210
22125
  }
21211
- const packed = runPack({ path: filePath, noJournal: !includeJournal, noQuality: !includeQuality, cwd });
22126
+ const packed = runPack({
22127
+ path: filePath,
22128
+ noJournal: !includeJournal,
22129
+ noQuality: !includeQuality,
22130
+ noWeighing: !includeWeighing,
22131
+ cwd
22132
+ });
21212
22133
  if (!packed.ok) {
21213
22134
  return fatalResult4(filePath, packed.fatal ?? "pack failed");
21214
22135
  }
@@ -21216,6 +22137,7 @@ async function runPush(options = {}) {
21216
22137
  const params = [];
21217
22138
  if (includeJournal) params.push("include_journal=true");
21218
22139
  if (includeQuality) params.push("include_quality=true");
22140
+ if (includeWeighing) params.push("include_weighing=true");
21219
22141
  const url2 = `${apiBase}/api/publik${params.length > 0 ? `?${params.join("&")}` : ""}`;
21220
22142
  let res;
21221
22143
  try {
@@ -21361,6 +22283,7 @@ function reportDelete(id, result) {
21361
22283
  function runPushCli(args) {
21362
22284
  let includeJournal = false;
21363
22285
  let includeQuality = false;
22286
+ let includeWeighing = false;
21364
22287
  let apiBase;
21365
22288
  let deleteId;
21366
22289
  let key;
@@ -21374,6 +22297,8 @@ function runPushCli(args) {
21374
22297
  includeJournal = true;
21375
22298
  } else if (arg === "--include-quality") {
21376
22299
  includeQuality = true;
22300
+ } else if (arg === "--include-weighing") {
22301
+ includeWeighing = true;
21377
22302
  } else if (arg === "--api") {
21378
22303
  const value = args[++i];
21379
22304
  if (value === void 0) fail9(`Missing value for --api
@@ -21416,7 +22341,7 @@ ${USAGE9}`);
21416
22341
 
21417
22342
  ${USAGE9}`);
21418
22343
  const filePath = positionals[0] ?? DEFAULT_BUNDLE_PATH8;
21419
- runPush({ path: filePath, includeJournal, includeQuality, apiBase }).then((result) => {
22344
+ runPush({ path: filePath, includeJournal, includeQuality, includeWeighing, apiBase }).then((result) => {
21420
22345
  if (!result.ok) fail9(`FATAL: ${result.fatal}`);
21421
22346
  reportPush(result);
21422
22347
  }).catch((e) => fail9(`FATAL: ${e.message}`));
@@ -21424,7 +22349,7 @@ ${USAGE9}`);
21424
22349
 
21425
22350
  // src/commands/link.ts
21426
22351
  import { mkdirSync as mkdirSync5, readFileSync as readFileSync8, writeFileSync as writeFileSync8 } from "node:fs";
21427
- import { dirname as dirname6, join as join7, resolve as resolve8 } from "node:path";
22352
+ import { dirname as dirname6, join as join8, resolve as resolve8 } from "node:path";
21428
22353
  var LINK_FILE = "docs/arkaik/arkaik.json";
21429
22354
  var DEFAULT_BASE_URL = "https://arkaik.app";
21430
22355
  var USAGE10 = `arkaik link \u2014 point this repo at a hosted Arkaik project
@@ -21496,7 +22421,7 @@ async function runLink(argv, options = {}) {
21496
22421
  }
21497
22422
  const { bundle } = await res.json();
21498
22423
  const target = resolve8(cwd, argv.find((a) => !a.startsWith("--") && a !== projectId && a !== baseUrl) ?? ".");
21499
- const linkPath = join7(target, LINK_FILE);
22424
+ const linkPath = join8(target, LINK_FILE);
21500
22425
  mkdirSync5(dirname6(linkPath), { recursive: true });
21501
22426
  let existing = {};
21502
22427
  try {
@@ -21531,7 +22456,7 @@ function runLinkCli(argv) {
21531
22456
 
21532
22457
  // src/commands/live.ts
21533
22458
  import { readFileSync as readFileSync9 } from "node:fs";
21534
- import { join as join8, resolve as resolve9 } from "node:path";
22459
+ import { join as join9, resolve as resolve9 } from "node:path";
21535
22460
  var LINK_FILE2 = "docs/arkaik/arkaik.json";
21536
22461
  var DEFAULT_BASE_URL2 = "https://arkaik.app";
21537
22462
  var MAX_ENTRIES_PER_REQUEST = 50;
@@ -21665,7 +22590,7 @@ async function runLive(argv, options = {}) {
21665
22590
  const mentionsFile = flagValue2(argv, "--mentions");
21666
22591
  const paths = (flagValue2(argv, "--paths") ?? "").split(",").map((p) => p.trim()).filter(Boolean);
21667
22592
  const dryRun = argv.includes("--dry-run");
21668
- const linkPath = join8(cwd, LINK_FILE2);
22593
+ const linkPath = join9(cwd, LINK_FILE2);
21669
22594
  let link;
21670
22595
  try {
21671
22596
  link = JSON.parse(readFileSync9(linkPath, "utf8"));
@@ -21790,8 +22715,8 @@ function runLiveCli(argv) {
21790
22715
  }
21791
22716
 
21792
22717
  // src/commands/shot.ts
21793
- import { existsSync as existsSync9, readFileSync as readFileSync10, writeFileSync as writeFileSync9 } from "node:fs";
21794
- import { join as join9, resolve as resolve10 } from "node:path";
22718
+ import { existsSync as existsSync10, readFileSync as readFileSync10, writeFileSync as writeFileSync9 } from "node:fs";
22719
+ import { join as join10, resolve as resolve10 } from "node:path";
21795
22720
  var LINK_FILE3 = "docs/arkaik/arkaik.json";
21796
22721
  var DEFAULT_BUNDLE_PATH9 = "docs/arkaik/bundle.json";
21797
22722
  var DEFAULT_BASE_URL3 = "https://arkaik.app";
@@ -21926,8 +22851,8 @@ async function runShot(argv, options = {}) {
21926
22851
  return { ok: false };
21927
22852
  }
21928
22853
  }
21929
- const linkPath = join9(cwd, LINK_FILE3);
21930
- if (existsSync9(linkPath)) {
22854
+ const linkPath = join10(cwd, LINK_FILE3);
22855
+ if (existsSync10(linkPath)) {
21931
22856
  return runHosted({ entries, commit, order, dryRun, linkPath, argv, env, doFetch, log, errorLog });
21932
22857
  }
21933
22858
  return runKommit({ entries, commit, order, dryRun, cwd, argv, log, errorLog });
@@ -22071,8 +22996,8 @@ function runShotCli(argv) {
22071
22996
  }
22072
22997
 
22073
22998
  // src/commands/restore.ts
22074
- import { existsSync as existsSync10, linkSync, mkdirSync as mkdirSync6, readFileSync as readFileSync11, unlinkSync, writeFileSync as writeFileSync10 } from "node:fs";
22075
- import { join as join10, resolve as resolve11 } from "node:path";
22999
+ import { existsSync as existsSync11, linkSync, mkdirSync as mkdirSync6, readFileSync as readFileSync11, unlinkSync, writeFileSync as writeFileSync10 } from "node:fs";
23000
+ import { join as join11, resolve as resolve11 } from "node:path";
22076
23001
  var LINK_FILE4 = "docs/arkaik/arkaik.json";
22077
23002
  var DEFAULT_BUNDLE_PATH10 = "docs/arkaik/bundle.json";
22078
23003
  var DEFAULT_API_BASE2 = "https://arkaik.app";
@@ -22118,6 +23043,16 @@ Options:
22118
23043
  one \u2014 that needs --allow-quality-loss too, because
22119
23044
  "don't send mine" and "destroy theirs" are different
22120
23045
  decisions and only one of them is irreversible.
23046
+ --no-weighing Do not send a weighing section: skip the docs/weighing/
23047
+ fold AND drop any section the local bundle already
23048
+ carries. WARNING: a restore replaces the hosted
23049
+ journal, and an assessment recorded only on the hosted
23050
+ project lives in that journal. The history guard
23051
+ compares COUNTS, so it does NOT reliably protect those
23052
+ events: a repo whose journal is as long as the hosted
23053
+ one passes it while still erasing them. The backup this
23054
+ command writes first holds them; the proper fix is
23055
+ issue #624 (restore appends by default).
22121
23056
  --allow-quality-loss Proceed even though the restore would erase a quality
22122
23057
  section the hosted project currently has. Without this
22123
23058
  flag, that refuses outright \u2014 it usually means
@@ -22302,7 +23237,7 @@ function describeQualityLoss(hostedQuality, qualityRoot, noQuality, foldNotice)
22302
23237
  lines.push("The outbound bundle has no section because the fold found nothing to build one from:");
22303
23238
  lines.push(` ${foldNotice}`);
22304
23239
  }
22305
- if (!existsSync10(join10(qualityRoot, QUALITY_DIR))) {
23240
+ if (!existsSync11(join11(qualityRoot, QUALITY_DIR))) {
22306
23241
  lines.push(
22307
23242
  `There is no ${QUALITY_DIR}/ under ${qualityRoot} at all. If this project's sidecars live somewhere else, point --root at that repo and the section is rebuilt rather than removed.`
22308
23243
  );
@@ -22333,11 +23268,12 @@ async function runRestore(options = {}) {
22333
23268
  const allowHistoryLoss = options.allowHistoryLoss ?? false;
22334
23269
  const allowDeletions = options.allowDeletions ?? false;
22335
23270
  const noQuality = options.noQuality ?? false;
23271
+ const noWeighing = options.noWeighing ?? false;
22336
23272
  const allowQualityLoss = options.allowQualityLoss ?? false;
22337
23273
  const allowMetadataLoss = options.allowMetadataLoss ?? false;
22338
23274
  const httpClient = options.httpClient ?? DEFAULT_HTTP_CLIENT;
22339
- const linkPath = join10(cwd, LINK_FILE4);
22340
- if (!existsSync10(linkPath)) {
23275
+ const linkPath = join11(cwd, LINK_FILE4);
23276
+ if (!existsSync11(linkPath)) {
22341
23277
  return fatalResult5(dryRun, `No ${LINK_FILE4}. Run \`arkaik link\` first \u2014 restore only targets hosted projects.`);
22342
23278
  }
22343
23279
  let link;
@@ -22353,7 +23289,7 @@ async function runRestore(options = {}) {
22353
23289
  const token = env.ARKAIK_TOKEN;
22354
23290
  if (!token) return fatalResult5(dryRun, `ARKAIK_TOKEN is not set. Create a token at ${baseUrl}/settings/tokens and export it.`);
22355
23291
  const bundlePath = resolve11(cwd, options.path ?? DEFAULT_BUNDLE_PATH10);
22356
- if (!existsSync10(bundlePath)) return fatalResult5(dryRun, `No bundle at ${bundlePath}. Run \`arkaik merge\` (or \`arkaik pack\`) first.`);
23292
+ if (!existsSync11(bundlePath)) return fatalResult5(dryRun, `No bundle at ${bundlePath}. Run \`arkaik merge\` (or \`arkaik pack\`) first.`);
22357
23293
  let localRaw;
22358
23294
  try {
22359
23295
  localRaw = JSON.parse(readFileSync11(bundlePath, "utf8"));
@@ -22382,6 +23318,15 @@ async function runRestore(options = {}) {
22382
23318
  }
22383
23319
  }
22384
23320
  const qualityFields = { qualityFolded, qualityNotice };
23321
+ if (noWeighing) {
23322
+ delete outboundBundle.weighing;
23323
+ } else {
23324
+ try {
23325
+ foldWeighingSection(outboundBundle, qualityRoot);
23326
+ } catch (e) {
23327
+ return fatalResult5(dryRun, e.message);
23328
+ }
23329
+ }
22385
23330
  const headers = { Authorization: `Bearer ${token}` };
22386
23331
  let version2;
22387
23332
  try {
@@ -22454,9 +23399,9 @@ async function runRestore(options = {}) {
22454
23399
  if ((removedNodes.length > 0 || removedEdges.length > 0) && !allowDeletions) {
22455
23400
  return fatalResult5(dryRun, describeDeletions(removedNodes, removedEdges, bundlePath), qualityFields);
22456
23401
  }
22457
- const backupDir = join10(cwd, "docs", "arkaik", ".backups");
23402
+ const backupDir = join11(cwd, "docs", "arkaik", ".backups");
22458
23403
  const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
22459
- const backupPath = join10(backupDir, `${stamp}-bundle.json`);
23404
+ const backupPath = join11(backupDir, `${stamp}-bundle.json`);
22460
23405
  const backupContent = `${JSON.stringify(exported, null, 2)}
22461
23406
  `;
22462
23407
  try {
@@ -22554,6 +23499,7 @@ function runRestoreCli(argv) {
22554
23499
  let allowHistoryLoss = false;
22555
23500
  let allowDeletions = false;
22556
23501
  let noQuality = false;
23502
+ let noWeighing = false;
22557
23503
  let allowQualityLoss = false;
22558
23504
  let allowMetadataLoss = false;
22559
23505
  let audit;
@@ -22574,6 +23520,8 @@ function runRestoreCli(argv) {
22574
23520
  allowDeletions = true;
22575
23521
  } else if (arg === "--no-quality") {
22576
23522
  noQuality = true;
23523
+ } else if (arg === "--no-weighing") {
23524
+ noWeighing = true;
22577
23525
  } else if (arg === "--allow-quality-loss") {
22578
23526
  allowQualityLoss = true;
22579
23527
  } else if (arg === "--allow-metadata-loss") {
@@ -22618,6 +23566,7 @@ ${USAGE13}`);
22618
23566
  allowHistoryLoss,
22619
23567
  allowDeletions,
22620
23568
  noQuality,
23569
+ noWeighing,
22621
23570
  allowQualityLoss,
22622
23571
  allowMetadataLoss,
22623
23572
  audit,
@@ -22628,16 +23577,16 @@ ${USAGE13}`);
22628
23577
 
22629
23578
  // src/commands/bootstrap.ts
22630
23579
  import { spawnSync as spawnSync2 } from "node:child_process";
22631
- import { existsSync as existsSync16, mkdirSync as mkdirSync8, renameSync, writeFileSync as writeFileSync14 } from "node:fs";
23580
+ import { existsSync as existsSync17, mkdirSync as mkdirSync8, renameSync, writeFileSync as writeFileSync14 } from "node:fs";
22632
23581
  import path5 from "node:path";
22633
23582
 
22634
23583
  // src/lib/bootstrap/corpus.ts
22635
23584
  import { spawnSync } from "node:child_process";
22636
- import { existsSync as existsSync12, readdirSync as readdirSync3, readFileSync as readFileSync13, writeFileSync as writeFileSync12 } from "node:fs";
23585
+ import { existsSync as existsSync13, readdirSync as readdirSync4, readFileSync as readFileSync13, writeFileSync as writeFileSync12 } from "node:fs";
22637
23586
  import path2 from "node:path";
22638
23587
 
22639
23588
  // src/lib/bootstrap/paths.ts
22640
- import { existsSync as existsSync11, mkdirSync as mkdirSync7, readFileSync as readFileSync12, writeFileSync as writeFileSync11 } from "node:fs";
23589
+ import { existsSync as existsSync12, mkdirSync as mkdirSync7, readFileSync as readFileSync12, writeFileSync as writeFileSync11 } from "node:fs";
22641
23590
  import path from "node:path";
22642
23591
  var BOOTSTRAP_ROOT = ".arkaik";
22643
23592
  var CORPUS_DIR = ".arkaik/corpus";
@@ -22657,7 +23606,7 @@ function ensureDir(dirPath) {
22657
23606
  function ensureGitignored(cwd) {
22658
23607
  const file2 = path.join(cwd, ".gitignore");
22659
23608
  const line2 = `${BOOTSTRAP_ROOT}/`;
22660
- const current = existsSync11(file2) ? readFileSync12(file2, "utf8") : "";
23609
+ const current = existsSync12(file2) ? readFileSync12(file2, "utf8") : "";
22661
23610
  const ignored = current.split("\n").map((l) => l.trim()).some((l) => l === line2 || l === BOOTSTRAP_ROOT);
22662
23611
  if (ignored) return false;
22663
23612
  const prefix = current.length > 0 && !current.endsWith("\n") ? "\n" : "";
@@ -22758,7 +23707,7 @@ function fetchPrsViaGit(cwd) {
22758
23707
  function walk(root, cwd, out) {
22759
23708
  let entries;
22760
23709
  try {
22761
- entries = readdirSync3(root, { withFileTypes: true });
23710
+ entries = readdirSync4(root, { withFileTypes: true });
22762
23711
  } catch {
22763
23712
  return;
22764
23713
  }
@@ -22821,12 +23770,12 @@ function buildCorpus(options) {
22821
23770
  }
22822
23771
  function readCorpusPrs(cwd) {
22823
23772
  const file2 = at(cwd, PRS_FILE);
22824
- if (!existsSync12(file2)) return [];
23773
+ if (!existsSync13(file2)) return [];
22825
23774
  return readFileSync13(file2, "utf8").split("\n").filter(Boolean).map((line2) => JSON.parse(line2));
22826
23775
  }
22827
23776
 
22828
23777
  // src/lib/bootstrap/fragments.ts
22829
- import { existsSync as existsSync13, readFileSync as readFileSync14 } from "node:fs";
23778
+ import { existsSync as existsSync14, readFileSync as readFileSync14 } from "node:fs";
22830
23779
  import path3 from "node:path";
22831
23780
  function isArrayOfObjects(value) {
22832
23781
  return value === void 0 || Array.isArray(value) && value.every((v) => typeof v === "object" && v !== null && !Array.isArray(v));
@@ -22852,7 +23801,7 @@ function loadFragments(cwd, manifest) {
22852
23801
  problems.push({ unit: String(unit2.id), message: err instanceof Error ? err.message : String(err) });
22853
23802
  continue;
22854
23803
  }
22855
- if (!existsSync13(file2)) {
23804
+ if (!existsSync14(file2)) {
22856
23805
  missing.push(unit2.id);
22857
23806
  continue;
22858
23807
  }
@@ -22895,7 +23844,7 @@ function renderIndex(bundle) {
22895
23844
  }
22896
23845
 
22897
23846
  // src/lib/bootstrap/manifest.ts
22898
- import { existsSync as existsSync14, readFileSync as readFileSync15, writeFileSync as writeFileSync13 } from "node:fs";
23847
+ import { existsSync as existsSync15, readFileSync as readFileSync15, writeFileSync as writeFileSync13 } from "node:fs";
22899
23848
  import path4 from "node:path";
22900
23849
 
22901
23850
  // src/lib/bootstrap/era-window.ts
@@ -23004,7 +23953,7 @@ function assertValidProfile(profile) {
23004
23953
  // src/lib/bootstrap/manifest.ts
23005
23954
  function readProfile(cwd) {
23006
23955
  const file2 = at(cwd, PROFILE_FILE2);
23007
- if (!existsSync14(file2)) return null;
23956
+ if (!existsSync15(file2)) return null;
23008
23957
  try {
23009
23958
  return JSON.parse(readFileSync15(file2, "utf8"));
23010
23959
  } catch (err) {
@@ -23013,7 +23962,7 @@ function readProfile(cwd) {
23013
23962
  }
23014
23963
  function readManifest2(cwd) {
23015
23964
  const file2 = at(cwd, MANIFEST_FILE);
23016
- if (!existsSync14(file2)) return null;
23965
+ if (!existsSync15(file2)) return null;
23017
23966
  try {
23018
23967
  return JSON.parse(readFileSync15(file2, "utf8"));
23019
23968
  } catch (err) {
@@ -23028,7 +23977,7 @@ function writeManifest(cwd, manifest) {
23028
23977
  }
23029
23978
  function detectMode(cwd, bundlePath) {
23030
23979
  const file2 = path4.resolve(cwd, bundlePath);
23031
- if (!existsSync14(file2)) return "greenfield";
23980
+ if (!existsSync15(file2)) return "greenfield";
23032
23981
  let parsed;
23033
23982
  try {
23034
23983
  parsed = JSON.parse(readFileSync15(file2, "utf8"));
@@ -23484,7 +24433,7 @@ function mergeFragments(input) {
23484
24433
  }
23485
24434
 
23486
24435
  // src/lib/bootstrap/slice.ts
23487
- import { existsSync as existsSync15, readFileSync as readFileSync16 } from "node:fs";
24436
+ import { existsSync as existsSync16, readFileSync as readFileSync16 } from "node:fs";
23488
24437
 
23489
24438
  // src/lib/bootstrap/body-budget.ts
23490
24439
  var LAB_NOTE_HEADING_RE = /^##\s+Lab Note.*$/m;
@@ -23526,7 +24475,7 @@ function boundBody(body) {
23526
24475
 
23527
24476
  // src/lib/bootstrap/slice.ts
23528
24477
  function readJsonArray(file2) {
23529
- if (!existsSync15(file2)) return [];
24478
+ if (!existsSync16(file2)) return [];
23530
24479
  const parsed = JSON.parse(readFileSync16(file2, "utf8"));
23531
24480
  return Array.isArray(parsed) ? parsed : [];
23532
24481
  }
@@ -23672,7 +24621,7 @@ ${CORPUS_USAGE}`);
23672
24621
  ${CORPUS_USAGE}`);
23673
24622
  }
23674
24623
  }
23675
- if (!existsSync16(path5.join(cwd, ".git"))) {
24624
+ if (!existsSync17(path5.join(cwd, ".git"))) {
23676
24625
  fail11("`arkaik bootstrap corpus` must run from the repository root (no .git here).");
23677
24626
  }
23678
24627
  try {
@@ -23734,7 +24683,7 @@ ${PLAN_USAGE}`);
23734
24683
 
23735
24684
  ${PLAN_USAGE}`);
23736
24685
  }
23737
- if (!existsSync16(path5.join(cwd, ".git"))) {
24686
+ if (!existsSync17(path5.join(cwd, ".git"))) {
23738
24687
  fail11("`arkaik bootstrap plan` must run from the repository root (no .git here).");
23739
24688
  }
23740
24689
  try {
@@ -23873,7 +24822,7 @@ ${MERGE_USAGE}`);
23873
24822
  }
23874
24823
  try {
23875
24824
  const bundlePath = path5.resolve(cwd, manifest.bundle);
23876
- const base = existsSync16(bundlePath) ? readBundle(bundlePath) : {
24825
+ const base = existsSync17(bundlePath) ? readBundle(bundlePath) : {
23877
24826
  schema_version: 3,
23878
24827
  project: {
23879
24828
  id: path5.basename(cwd),
@@ -24088,17 +25037,17 @@ Pass --domain-name "<display name>" to define it, or use an existing domain code
24088
25037
 
24089
25038
  // ../schema/src/cli/kritik-plan.ts
24090
25039
  import { spawnSync as spawnSync3 } from "node:child_process";
24091
- import { existsSync as existsSync17, readdirSync as readdirSync4, statSync as statSync2 } from "node:fs";
24092
- import { join as join11 } from "node:path";
24093
- var plansDir = (root) => join11(root, QUALITY_DIR, PLAN_PLANS_DIR);
24094
- var planPath = (root, planId2) => join11(plansDir(root), `${planId2}.json`);
25040
+ import { existsSync as existsSync18, readdirSync as readdirSync5, statSync as statSync2 } from "node:fs";
25041
+ import { join as join12 } from "node:path";
25042
+ var plansDir = (root) => join12(root, QUALITY_DIR, PLAN_PLANS_DIR);
25043
+ var planPath = (root, planId2) => join12(plansDir(root), `${planId2}.json`);
24095
25044
  function listPlanIds(root) {
24096
25045
  const dir = plansDir(root);
24097
- if (!existsSync17(dir)) return [];
24098
- return readdirSync4(dir).filter((name) => name.endsWith(".json") && statSync2(join11(dir, name)).isFile()).map((name) => name.slice(0, -".json".length)).filter((id) => isPlanId(id)).sort();
25046
+ if (!existsSync18(dir)) return [];
25047
+ return readdirSync5(dir).filter((name) => name.endsWith(".json") && statSync2(join12(dir, name)).isFile()).map((name) => name.slice(0, -".json".length)).filter((id) => isPlanId(id)).sort();
24099
25048
  }
24100
25049
  function readPlanFile(path6) {
24101
- if (!existsSync17(path6)) throw new Error(`no plan at ${path6}`);
25050
+ if (!existsSync18(path6)) throw new Error(`no plan at ${path6}`);
24102
25051
  const parsed = parseKritikPlan(readJson(path6));
24103
25052
  if (!parsed.ok) throw new Error(`${path6}: ${parsed.issue}`);
24104
25053
  return parsed.plan;
@@ -24264,7 +25213,7 @@ Record each first, or remove its scores (docs/quality/audits/<id>/scores.json),
24264
25213
  }
24265
25214
 
24266
25215
  // src/commands/kritik.ts
24267
- import { existsSync as existsSync18, readFileSync as readFileSync17 } from "node:fs";
25216
+ import { existsSync as existsSync19, readFileSync as readFileSync17 } from "node:fs";
24268
25217
  import { resolve as resolve12 } from "node:path";
24269
25218
  var USAGE15 = `arkaik kritik <subcommand> [options]
24270
25219
 
@@ -24526,7 +25475,7 @@ function collect(args, repeatable = [], boolean4 = []) {
24526
25475
  function textOrFile(value) {
24527
25476
  if (!value.startsWith("@")) return value;
24528
25477
  const path6 = value.slice(1);
24529
- if (!existsSync18(path6)) fail12(`kritik: no file at ${path6}`);
25478
+ if (!existsSync19(path6)) fail12(`kritik: no file at ${path6}`);
24530
25479
  return readFileSync17(path6, "utf8").trim();
24531
25480
  }
24532
25481
  function currentAuditId() {
@@ -24665,7 +25614,7 @@ ${PROFILE_USAGE}`);
24665
25614
  weights[code] = value;
24666
25615
  }
24667
25616
  const path6 = profilePath(common.root);
24668
- if (existsSync18(path6) && !flags.has("force")) {
25617
+ if (existsSync19(path6) && !flags.has("force")) {
24669
25618
  fail12(
24670
25619
  `kritik: ${path6} already exists.
24671
25620
  Changing the surface list invalidates every score recorded against the old one, so this refuses by default.
@@ -25772,10 +26721,10 @@ ${PLAN_USAGE2}`);
25772
26721
  const target = single.out ?? home;
25773
26722
  let written = null;
25774
26723
  if (!flags.has("dry-run")) {
25775
- if (single.out !== void 0 && existsSync18(target)) {
26724
+ if (single.out !== void 0 && existsSync19(target)) {
25776
26725
  fail12(`kritik: ${target} already exists \u2014 a plan file is written once. Pick another --out.`);
25777
26726
  }
25778
- if (existsSync18(target)) {
26727
+ if (existsSync19(target)) {
25779
26728
  fail12(`kritik: ${target} already exists \u2014 a plan file is written once, and another plan took ${plan.planId} meanwhile. Run the command again for the next id.`);
25780
26729
  }
25781
26730
  savePlan(target, plan);
@@ -25865,7 +26814,7 @@ ${CRITERION_USAGE}`);
25865
26814
  let criterion;
25866
26815
  try {
25867
26816
  if (single.from !== void 0) {
25868
- if (!existsSync18(single.from)) fail12(`kritik: no file at ${single.from}`);
26817
+ if (!existsSync19(single.from)) fail12(`kritik: no file at ${single.from}`);
25869
26818
  criterion = JSON.parse(readFileSync17(single.from, "utf8"));
25870
26819
  } else {
25871
26820
  const anchors = {};
@@ -25987,7 +26936,7 @@ Options:
25987
26936
  -v, --version Print the version.
25988
26937
 
25989
26938
  Run "arkaik <command> --help" for command-specific help.`;
25990
- var VERSION = "0.11.1";
26939
+ var VERSION = "0.13.0";
25991
26940
  function main(argv) {
25992
26941
  const [command, ...rest] = argv;
25993
26942
  if (command === void 0 || command === "--help" || command === "-h" || command === "help") {