@intentset/publisher 0.1.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.
Files changed (56) hide show
  1. package/dist/body.d.ts +18 -0
  2. package/dist/body.d.ts.map +1 -0
  3. package/dist/body.js +34 -0
  4. package/dist/body.js.map +1 -0
  5. package/dist/chunks.d.ts +24 -0
  6. package/dist/chunks.d.ts.map +1 -0
  7. package/dist/chunks.js +116 -0
  8. package/dist/chunks.js.map +1 -0
  9. package/dist/diagnostic.d.ts +25 -0
  10. package/dist/diagnostic.d.ts.map +1 -0
  11. package/dist/diagnostic.js +21 -0
  12. package/dist/diagnostic.js.map +1 -0
  13. package/dist/generate.d.ts +89 -0
  14. package/dist/generate.d.ts.map +1 -0
  15. package/dist/generate.js +157 -0
  16. package/dist/generate.js.map +1 -0
  17. package/dist/index.d.ts +15 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +15 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/project.d.ts +56 -0
  22. package/dist/project.d.ts.map +1 -0
  23. package/dist/project.js +187 -0
  24. package/dist/project.js.map +1 -0
  25. package/dist/publish.d.ts +42 -0
  26. package/dist/publish.d.ts.map +1 -0
  27. package/dist/publish.js +132 -0
  28. package/dist/publish.js.map +1 -0
  29. package/dist/references.d.ts +32 -0
  30. package/dist/references.d.ts.map +1 -0
  31. package/dist/references.js +196 -0
  32. package/dist/references.js.map +1 -0
  33. package/dist/request.d.ts +63 -0
  34. package/dist/request.d.ts.map +1 -0
  35. package/dist/request.js +156 -0
  36. package/dist/request.js.map +1 -0
  37. package/dist/review.d.ts +58 -0
  38. package/dist/review.d.ts.map +1 -0
  39. package/dist/review.js +77 -0
  40. package/dist/review.js.map +1 -0
  41. package/dist/yaml.d.ts +18 -0
  42. package/dist/yaml.d.ts.map +1 -0
  43. package/dist/yaml.js +90 -0
  44. package/dist/yaml.js.map +1 -0
  45. package/package.json +36 -0
  46. package/src/body.ts +32 -0
  47. package/src/chunks.ts +132 -0
  48. package/src/diagnostic.ts +44 -0
  49. package/src/generate.ts +244 -0
  50. package/src/index.ts +70 -0
  51. package/src/project.ts +254 -0
  52. package/src/publish.ts +177 -0
  53. package/src/references.ts +226 -0
  54. package/src/request.ts +239 -0
  55. package/src/review.ts +121 -0
  56. package/src/yaml.ts +85 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"references.js","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAA8C,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAA2B,MAAM,EAAE,MAAM,cAAc,CAAC;AAY/D,qFAAqF;AACrF,MAAM,SAAS,GAAkC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAE1F,gDAAgD;AAChD,SAAS,OAAO,CAAC,KAAwB;IACvC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;AAC/G,CAAC;AAED,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,qBAAqB,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,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;YACnB,QAAQ,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YAClE,OAAO,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,0BAA0B,EAAE,gBAAgB,OAAO,CAAC,UAAU,6BAA6B;YACvH,WAAW,EACT,yGAAyG;SAC5G,CAAC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,gIAAgI;AAChI,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1D,MAAM,KAAK,GAAG,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,EAAE,CAAC;IACjF,MAAM,GAAG,GAAG,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9E,OAAO,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * The publication request and the projection levels (Core §9).
3
+ *
4
+ * A request names one value per availability dimension, the flags the reader
5
+ * is entitled to, the audience and the projection's visibility. Every one of
6
+ * them is required: a request that leaves a dimension out is refused rather
7
+ * than read as "any" (Core §7: no implicit wildcard; Core §4: missing access
8
+ * information fails closed). Values must be ones the registries declare, so a
9
+ * request for an unknown release is refused instead of quietly matching
10
+ * nothing (Core §9: abstain when the requested version is unknown).
11
+ *
12
+ * Public projection admits public records only; customer admits public and
13
+ * customer. Internal and restricted data need their own explicit
14
+ * authorization, and a restricted projection, which admits internal records
15
+ * too, needs both.
16
+ */
17
+ import { type Diagnostic, type Graph, type Registries, type Visibility } from "@intentset/core";
18
+ export interface PublicationRequest {
19
+ visibility: Visibility;
20
+ audience: string;
21
+ product: string;
22
+ release: string;
23
+ role: string;
24
+ edition: string;
25
+ /** The flags the reader is entitled to. Empty means none. */
26
+ flags: string[];
27
+ /** Knowledge IDs requested; omitted means every eligible one. */
28
+ ids?: string[];
29
+ /** Explicit authorization for an internal or restricted projection. */
30
+ authorizedInternal?: boolean;
31
+ /** Explicit authorization for a restricted projection. */
32
+ authorizedRestricted?: boolean;
33
+ }
34
+ /** The request as an index records it: authorization flags removed, flags and ids sorted. */
35
+ export interface IndexedRequest {
36
+ visibility: Visibility;
37
+ audience: string;
38
+ product: string;
39
+ release: string;
40
+ role: string;
41
+ edition: string;
42
+ flags: string[];
43
+ ids?: string[];
44
+ }
45
+ /** Core §9: the visibilities each projection admits. */
46
+ export declare const PROJECTION_ADMITS: Readonly<Record<Visibility, readonly Visibility[]>>;
47
+ /** The single-valued dimensions of a request, in the order they are reported. */
48
+ export declare const REQUEST_DIMENSIONS: readonly ["audience", "product", "release", "role", "edition"];
49
+ export type RequestDimension = (typeof REQUEST_DIMENSIONS)[number];
50
+ /** True when the request's projection admits a record of this visibility. */
51
+ export declare function admits(request: Pick<PublicationRequest, "visibility">, visibility: Visibility): boolean;
52
+ /** The request without its authorization flags, for an index a reader may see. */
53
+ export declare function indexedRequest(request: PublicationRequest): IndexedRequest;
54
+ /**
55
+ * Check a request before anything is selected: shape, authorization, and
56
+ * values against the registries and the graph. Every problem is a PUB001 and
57
+ * all of them are reported at once; any one refuses the whole request.
58
+ */
59
+ export declare function checkRequest(value: unknown, graph: Graph, registries: Registries): {
60
+ request: PublicationRequest | null;
61
+ diagnostics: Diagnostic[];
62
+ };
63
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,KAAK,UAAU,EAAgB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG9G,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,iEAAiE;IACjE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,uEAAuE;IACvE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,0DAA0D;IAC1D,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,6FAA6F;AAC7F,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,wDAAwD;AACxD,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,UAAU,EAAE,CAAC,CAKjF,CAAC;AAEF,iFAAiF;AACjF,eAAO,MAAM,kBAAkB,YAAI,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAU,CAAC;AACjG,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAWnE,6EAA6E;AAC7E,wBAAgB,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,YAAY,CAAC,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAEvG;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,cAAc,CAY1E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,UAAU,GACrB;IAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,UAAU,EAAE,CAAA;CAAE,CA4InE"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * The publication request and the projection levels (Core §9).
3
+ *
4
+ * A request names one value per availability dimension, the flags the reader
5
+ * is entitled to, the audience and the projection's visibility. Every one of
6
+ * them is required: a request that leaves a dimension out is refused rather
7
+ * than read as "any" (Core §7: no implicit wildcard; Core §4: missing access
8
+ * information fails closed). Values must be ones the registries declare, so a
9
+ * request for an unknown release is refused instead of quietly matching
10
+ * nothing (Core §9: abstain when the requested version is unknown).
11
+ *
12
+ * Public projection admits public records only; customer admits public and
13
+ * customer. Internal and restricted data need their own explicit
14
+ * authorization, and a restricted projection, which admits internal records
15
+ * too, needs both.
16
+ */
17
+ import { VISIBILITIES } from "@intentset/core";
18
+ import { compareStrings, publicationDiagnostic, sortedUnique } from "./diagnostic.js";
19
+ /** Core §9: the visibilities each projection admits. */
20
+ export const PROJECTION_ADMITS = {
21
+ public: ["public"],
22
+ customer: ["public", "customer"],
23
+ internal: ["public", "customer", "internal"],
24
+ restricted: ["public", "customer", "internal", "restricted"],
25
+ };
26
+ /** The single-valued dimensions of a request, in the order they are reported. */
27
+ export const REQUEST_DIMENSIONS = ["audience", "product", "release", "role", "edition"];
28
+ const REQUEST_KEYS = new Set([
29
+ "visibility",
30
+ ...REQUEST_DIMENSIONS,
31
+ "flags",
32
+ "ids",
33
+ "authorizedInternal",
34
+ "authorizedRestricted",
35
+ ]);
36
+ /** True when the request's projection admits a record of this visibility. */
37
+ export function admits(request, visibility) {
38
+ return PROJECTION_ADMITS[request.visibility].includes(visibility);
39
+ }
40
+ /** The request without its authorization flags, for an index a reader may see. */
41
+ export function indexedRequest(request) {
42
+ const out = {
43
+ visibility: request.visibility,
44
+ audience: request.audience,
45
+ product: request.product,
46
+ release: request.release,
47
+ role: request.role,
48
+ edition: request.edition,
49
+ flags: sortedUnique(request.flags),
50
+ };
51
+ if (request.ids !== undefined)
52
+ out.ids = sortedUnique(request.ids);
53
+ return out;
54
+ }
55
+ /**
56
+ * Check a request before anything is selected: shape, authorization, and
57
+ * values against the registries and the graph. Every problem is a PUB001 and
58
+ * all of them are reported at once; any one refuses the whole request.
59
+ */
60
+ export function checkRequest(value, graph, registries) {
61
+ const diagnostics = [];
62
+ const refuse = (message, remediation) => diagnostics.push(publicationDiagnostic({ code: "PUB001", artifact: null, path: null, message, remediation }));
63
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
64
+ refuse("The publication request is not a mapping of dimensions.", "Pass visibility, audience, product, release, role, edition and flags.");
65
+ return { request: null, diagnostics };
66
+ }
67
+ const raw = value;
68
+ for (const key of Object.keys(raw).sort(compareStrings)) {
69
+ if (!REQUEST_KEYS.has(key)) {
70
+ refuse(`The request has an unknown key \`${key}\`.`, `Use only ${[...REQUEST_KEYS].join(", ")}; an unrecognized key is refused rather than ignored.`);
71
+ }
72
+ }
73
+ const visibility = raw.visibility;
74
+ if (visibility === undefined || visibility === null) {
75
+ refuse("The request names no visibility, so no projection can be chosen.", "Set visibility to public, customer, internal or restricted; missing access information fails closed (Core §4).");
76
+ }
77
+ else if (!VISIBILITIES.includes(visibility)) {
78
+ refuse("The request's visibility is not one of public, customer, internal or restricted.", "Name one of the four Core §4 visibilities.");
79
+ }
80
+ for (const dimension of REQUEST_DIMENSIONS) {
81
+ const v = raw[dimension];
82
+ if (typeof v !== "string" || v === "") {
83
+ refuse(`The request names no ${dimension}.`, `Name exactly one ${dimension}; availability has no implicit wildcard, so a missing dimension is refused (Core §7).`);
84
+ }
85
+ }
86
+ const flags = raw.flags;
87
+ const flagsOk = Array.isArray(flags) && flags.every((flag) => typeof flag === "string" && flag !== "");
88
+ if (flags === undefined || flags === null) {
89
+ refuse("The request names no flags.", "Pass the reader's enabled flags, or `flags: []` for none; an omission is refused rather than read as none (Core §7).");
90
+ }
91
+ else if (!flagsOk) {
92
+ refuse("The request's flags are not a list of flag names.", "Pass flags as a list of non-empty strings.");
93
+ }
94
+ const ids = raw.ids;
95
+ if (ids !== undefined && !(Array.isArray(ids) && ids.every((id) => typeof id === "string" && id !== ""))) {
96
+ refuse("The request's ids are not a list of artifact IDs.", "Pass ids as a list of knowledge IDs, or omit it to publish every eligible one.");
97
+ }
98
+ for (const key of ["authorizedInternal", "authorizedRestricted"]) {
99
+ if (raw[key] !== undefined && typeof raw[key] !== "boolean") {
100
+ refuse(`The request's ${key} is not true or false.`, `Set ${key} to true only when the caller holds that authorization.`);
101
+ }
102
+ }
103
+ if (visibility === "internal" || visibility === "restricted") {
104
+ if (raw.authorizedInternal !== true) {
105
+ refuse(`${visibility === "internal" ? "An internal" : "A restricted"} projection was requested without internal authorization.`, "Internal records need explicit authorization: pass authorizedInternal only for a caller entitled to engineering material (Core §9).");
106
+ }
107
+ }
108
+ if (visibility === "restricted" && raw.authorizedRestricted !== true) {
109
+ refuse("A restricted projection was requested without restricted authorization.", "Restricted records need their own explicit authorization: pass authorizedRestricted only for a caller entitled to them (Core §9).");
110
+ }
111
+ const known = (v, list) => typeof v === "string" && list.includes(v);
112
+ if (typeof raw.audience === "string" && raw.audience !== "" && !known(raw.audience, registries.audiences)) {
113
+ refuse(`The request names audience ${raw.audience}, which the audience registry does not declare.`, "Request a registered audience.");
114
+ }
115
+ if (typeof raw.product === "string" &&
116
+ raw.product !== "" &&
117
+ graph.artifacts.get(raw.product)?.meta.type !== "product") {
118
+ refuse(`The request names product ${raw.product}, which is not a product in this snapshot.`, "Name the product artifact's ID, such as PRD-LANTERN.");
119
+ }
120
+ for (const [dimension, list] of [
121
+ ["release", registries.releases],
122
+ ["role", registries.roles],
123
+ ["edition", registries.editions],
124
+ ]) {
125
+ const v = raw[dimension];
126
+ if (typeof v === "string" && v !== "" && !known(v, list)) {
127
+ refuse(`The request names ${dimension} ${v}, which the registries do not declare.`, `Request a declared ${dimension}; release labels match exactly and an unknown one is refused rather than guessed (Core §7, §9).`);
128
+ }
129
+ }
130
+ if (flagsOk) {
131
+ for (const flag of sortedUnique(flags)) {
132
+ if (!registries.flags.includes(flag)) {
133
+ refuse(`The request names flag ${flag}, which the registries do not declare.`, "Request only declared flags.");
134
+ }
135
+ }
136
+ }
137
+ if (diagnostics.length > 0)
138
+ return { request: null, diagnostics };
139
+ const request = {
140
+ visibility: visibility,
141
+ audience: raw.audience,
142
+ product: raw.product,
143
+ release: raw.release,
144
+ role: raw.role,
145
+ edition: raw.edition,
146
+ flags: sortedUnique(flags),
147
+ };
148
+ if (ids !== undefined)
149
+ request.ids = sortedUnique(ids);
150
+ if (raw.authorizedInternal === true)
151
+ request.authorizedInternal = true;
152
+ if (raw.authorizedRestricted === true)
153
+ request.authorizedRestricted = true;
154
+ return { request, diagnostics };
155
+ }
156
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAgD,YAAY,EAAmB,MAAM,iBAAiB,CAAC;AAC9G,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA+BtF,wDAAwD;AACxD,MAAM,CAAC,MAAM,iBAAiB,GAAwD;IACpF,MAAM,EAAE,C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,GAAe,CAAC,CAAC;IACnE,IAAI,GAAG,CAAC,kBAAkB,KAAK,IAAI;QAAE,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IACvE,IAAI,GAAG,CAAC,oBAAoB,KAAK,IAAI;QAAE,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAC3E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AAClC,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Needs-review (Core §9): knowledge is current only while every source it was
3
+ * reviewed against still has the hash it had at review.
4
+ *
5
+ * A review is `reviewedBy` and `reviewedAt` in the knowledge's own
6
+ * frontmatter plus a review record under
7
+ * `intentset.extensions["intentset.org/review"]` that pins, by ID, the
8
+ * source hash each source had when it was reviewed:
9
+ *
10
+ * extensions:
11
+ * intentset.org/review:
12
+ * sources:
13
+ * BEH-ASMT-SCHEDULE: 2f53...
14
+ * RULE-ASMT-FUTURE: e39f...
15
+ * snapshot: <commit or graph hash at review, informative>
16
+ *
17
+ * The sources a review must pin are what the knowledge `explains`, plus the
18
+ * rules that govern each explained behavior: a rule changing under a behavior
19
+ * changes what the behavior promises, which is catalog case P04.
20
+ *
21
+ * A pin of the literal `@current` is a fixture placeholder: `bindReviewPins`
22
+ * replaces it with the source's hash in the snapshot being checked, so a
23
+ * case can say "reviewed against what is there now" without computing a
24
+ * hash. Unbound, it never equals a hash, so it reads as changed.
25
+ */
26
+ import type { Artifact, Graph } from "@intentset/core";
27
+ export declare const REVIEW_EXTENSION = "intentset.org/review";
28
+ export declare const CURRENT_PIN = "@current";
29
+ export interface ReviewRecord {
30
+ /** Source ID -> the source hash it was reviewed against. Entries that are not strings are dropped. */
31
+ sources: Record<string, string>;
32
+ snapshot?: string;
33
+ }
34
+ export interface ReviewStatus {
35
+ status: "current" | "needs-review";
36
+ /** Sources whose current hash differs from the pin, or that are no longer in the graph. */
37
+ changed: string[];
38
+ /** Sources the review record does not pin. */
39
+ missing: string[];
40
+ /** `reviewedBy`, or null when the knowledge names no reviewer. */
41
+ reviewer: string | null;
42
+ /** `reviewedAt`, or null when absent. */
43
+ reviewedAt: string | null;
44
+ }
45
+ /** The sources a review must pin: everything explained, and the rules governing each explained behavior. Sorted. */
46
+ export declare function reviewSources(graph: Graph, artifact: Artifact): string[];
47
+ /** The review record of a knowledge artifact, or null when it has none or it is not a mapping with `sources`. */
48
+ export declare function readReviewRecord(artifact: Artifact): ReviewRecord | null;
49
+ /** Core §9: whether the knowledge is current against the sources it was reviewed against. */
50
+ export declare function reviewStatus(graph: Graph, artifact: Artifact): ReviewStatus;
51
+ /**
52
+ * Bind every `@current` pin to the pinned source's hash in this graph, for
53
+ * fixtures. Returns a new graph; the given one is not modified, and nothing
54
+ * the graph hash covers changes. A pin naming an artifact that is not in the
55
+ * graph stays `@current`, which reads as changed.
56
+ */
57
+ export declare function bindReviewPins(graph: Graph): Graph;
58
+ //# sourceMappingURL=review.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review.d.ts","sourceRoot":"","sources":["../src/review.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGvD,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AACvD,eAAO,MAAM,WAAW,aAAa,CAAC;AAEtC,MAAM,WAAW,YAAY;IAC3B,sGAAsG;IACtG,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,SAAS,GAAG,cAAc,CAAC;IACnC,2FAA2F;IAC3F,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,kEAAkE;IAClE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,yCAAyC;IACzC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,oHAAoH;AACpH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,EAAE,CAQxE;AAED,iHAAiH;AACjH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,YAAY,GAAG,IAAI,CAWxE;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,GAAG,YAAY,CAa3E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAgBlD"}
package/dist/review.js ADDED
@@ -0,0 +1,77 @@
1
+ import { compareStrings, sortedUnique } from "./diagnostic.js";
2
+ export const REVIEW_EXTENSION = "intentset.org/review";
3
+ export const CURRENT_PIN = "@current";
4
+ /** The sources a review must pin: everything explained, and the rules governing each explained behavior. Sorted. */
5
+ export function reviewSources(graph, artifact) {
6
+ const ids = [];
7
+ for (const id of artifact.meta.links.explains ?? []) {
8
+ ids.push(id);
9
+ const source = graph.artifacts.get(id);
10
+ if (source?.meta.type === "behavior")
11
+ ids.push(...(source.meta.links.governedBy ?? []));
12
+ }
13
+ return sortedUnique(ids);
14
+ }
15
+ /** The review record of a knowledge artifact, or null when it has none or it is not a mapping with `sources`. */
16
+ export function readReviewRecord(artifact) {
17
+ const value = artifact.meta.extensions?.[REVIEW_EXTENSION];
18
+ if (!isRecord(value) || !isRecord(value.sources))
19
+ return null;
20
+ const sources = {};
21
+ for (const id of Object.keys(value.sources).sort(compareStrings)) {
22
+ const pin = value.sources[id];
23
+ if (typeof pin === "string")
24
+ sources[id] = pin;
25
+ }
26
+ const record = { sources };
27
+ if (typeof value.snapshot === "string")
28
+ record.snapshot = value.snapshot;
29
+ return record;
30
+ }
31
+ /** Core §9: whether the knowledge is current against the sources it was reviewed against. */
32
+ export function reviewStatus(graph, artifact) {
33
+ const record = readReviewRecord(artifact);
34
+ const changed = [];
35
+ const missing = [];
36
+ for (const id of reviewSources(graph, artifact)) {
37
+ const pin = record?.sources[id];
38
+ if (pin === undefined)
39
+ missing.push(id);
40
+ else if (graph.artifacts.get(id)?.sourceHash !== pin)
41
+ changed.push(id);
42
+ }
43
+ const reviewer = nonEmpty(artifact.meta.reviewedBy);
44
+ const reviewedAt = nonEmpty(artifact.meta.reviewedAt);
45
+ const current = changed.length === 0 && missing.length === 0 && reviewer !== null && reviewedAt !== null;
46
+ return { status: current ? "current" : "needs-review", changed, missing, reviewer, reviewedAt };
47
+ }
48
+ /**
49
+ * Bind every `@current` pin to the pinned source's hash in this graph, for
50
+ * fixtures. Returns a new graph; the given one is not modified, and nothing
51
+ * the graph hash covers changes. A pin naming an artifact that is not in the
52
+ * graph stays `@current`, which reads as changed.
53
+ */
54
+ export function bindReviewPins(graph) {
55
+ const artifacts = new Map();
56
+ for (const [id, artifact] of graph.artifacts) {
57
+ const value = artifact.meta.extensions?.[REVIEW_EXTENSION];
58
+ if (!isRecord(value) || !isRecord(value.sources) || !Object.values(value.sources).includes(CURRENT_PIN)) {
59
+ artifacts.set(id, artifact);
60
+ continue;
61
+ }
62
+ const sources = {};
63
+ for (const [source, pin] of Object.entries(value.sources)) {
64
+ sources[source] = pin === CURRENT_PIN ? (graph.artifacts.get(source)?.sourceHash ?? pin) : pin;
65
+ }
66
+ const extensions = { ...artifact.meta.extensions, [REVIEW_EXTENSION]: { ...value, sources } };
67
+ artifacts.set(id, { ...artifact, meta: { ...artifact.meta, extensions } });
68
+ }
69
+ return { ...graph, artifacts };
70
+ }
71
+ function isRecord(value) {
72
+ return typeof value === "object" && value !== null && !Array.isArray(value);
73
+ }
74
+ function nonEmpty(value) {
75
+ return value === undefined || value.trim() === "" ? null : value;
76
+ }
77
+ //# sourceMappingURL=review.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review.js","sourceRoot":"","sources":["../src/review.ts"],"names":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AQ,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,CAAC;AACjC,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,QAAQ,CAAC,KAAyB;IACzC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AACnE,CAAC"}
package/dist/yaml.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The YAML the generated frontmatter is written in: block mappings with
3
+ * two-space indentation, sequences indented under their key, `[]` for an
4
+ * empty list, and strings left plain only when they are an identifier-like
5
+ * token no reader could take for anything else. It is written for two
6
+ * readers: core's strict reader (ADR 0001) and Markset's frontmatter subset,
7
+ * which does not accept a sequence at its key's own indentation. Key order is
8
+ * the object's own, so the output is fixed by the code that builds it.
9
+ */
10
+ export type YamlValue = string | number | boolean | null | YamlValue[] | {
11
+ [key: string]: YamlValue;
12
+ };
13
+ export declare class YamlEmitError extends Error {
14
+ }
15
+ export declare function emitYaml(value: {
16
+ [key: string]: YamlValue;
17
+ }): string;
18
+ //# sourceMappingURL=yaml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEtG,qBAAa,aAAc,SAAQ,KAAK;CAAG;AAE3C,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,MAAM,CAIpE"}
package/dist/yaml.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * The YAML the generated frontmatter is written in: block mappings with
3
+ * two-space indentation, sequences indented under their key, `[]` for an
4
+ * empty list, and strings left plain only when they are an identifier-like
5
+ * token no reader could take for anything else. It is written for two
6
+ * readers: core's strict reader (ADR 0001) and Markset's frontmatter subset,
7
+ * which does not accept a sequence at its key's own indentation. Key order is
8
+ * the object's own, so the output is fixed by the code that builds it.
9
+ */
10
+ export class YamlEmitError extends Error {
11
+ }
12
+ export function emitYaml(value) {
13
+ const lines = [];
14
+ writeMapping(value, 0, lines);
15
+ return `${lines.join("\n")}\n`;
16
+ }
17
+ function writeMapping(mapping, indent, lines) {
18
+ const pad = " ".repeat(indent);
19
+ for (const [key, value] of Object.entries(mapping)) {
20
+ const label = `${pad}${scalar(key)}:`;
21
+ if (Array.isArray(value)) {
22
+ if (value.length === 0)
23
+ lines.push(`${label} []`);
24
+ else {
25
+ lines.push(label);
26
+ writeSequence(value, indent + 2, lines);
27
+ }
28
+ }
29
+ else if (isMapping(value)) {
30
+ if (Object.keys(value).length === 0)
31
+ throw new YamlEmitError(`cannot write the empty mapping at ${key}`);
32
+ lines.push(label);
33
+ writeMapping(value, indent + 2, lines);
34
+ }
35
+ else {
36
+ lines.push(`${label} ${scalar(value)}`);
37
+ }
38
+ }
39
+ }
40
+ function writeSequence(items, indent, lines) {
41
+ const pad = " ".repeat(indent);
42
+ for (const item of items) {
43
+ if (isMapping(item)) {
44
+ const inner = [];
45
+ writeMapping(item, indent + 2, inner);
46
+ if (inner.length === 0)
47
+ throw new YamlEmitError("cannot write an empty mapping in a sequence");
48
+ inner[0] = `${pad}- ${inner[0].slice(indent + 2)}`;
49
+ lines.push(...inner);
50
+ }
51
+ else if (Array.isArray(item)) {
52
+ throw new YamlEmitError("cannot write a sequence directly inside a sequence");
53
+ }
54
+ else {
55
+ lines.push(`${pad}- ${scalar(item)}`);
56
+ }
57
+ }
58
+ }
59
+ const PLAIN = /^[A-Za-z_][A-Za-z0-9_./-]*$/;
60
+ const RESERVED = /^(?:true|false|yes|no|on|off|y|n|null)$/i;
61
+ function scalar(value) {
62
+ if (value === null)
63
+ return "null";
64
+ if (typeof value === "boolean")
65
+ return value ? "true" : "false";
66
+ if (typeof value === "number") {
67
+ if (!Number.isInteger(value))
68
+ throw new YamlEmitError(`cannot write the number ${value}: only integers are written`);
69
+ return String(value);
70
+ }
71
+ if (typeof value !== "string")
72
+ throw new YamlEmitError("cannot write a collection as a scalar");
73
+ if (hasControlCharacter(value))
74
+ throw new YamlEmitError("cannot write a string containing a control character");
75
+ if (PLAIN.test(value) && !RESERVED.test(value))
76
+ return value;
77
+ return `'${value.replace(/'/g, "''")}'`;
78
+ }
79
+ function hasControlCharacter(text) {
80
+ for (let i = 0; i < text.length; i++) {
81
+ const code = text.charCodeAt(i);
82
+ if (code < 0x20 || code === 0x7f)
83
+ return true;
84
+ }
85
+ return false;
86
+ }
87
+ function isMapping(value) {
88
+ return typeof value === "object" && value !== null && !Array.isArray(value);
89
+ }
90
+ //# sourceMappingURL=yaml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml.js","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,OAAO,aAAc,SAAQ,KAAK;CAAG;AAE3C,MAAM,UAAU,QAAQ,CAAC,KAAmC;IAC1D,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,YAAY,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAC9B,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACjC,CAAC;AAED,SAAS,YAAY,CAAC,OAAqC,EAAE,MAAc,EAAE,KAAe;IAC1F,MAAM,GAAG,GA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,CAAC;IAChG,IAAI,mBAAmB,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,aAAa,CAAC,sDAAsD,CAAC,CAAC;IAChH,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7D,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AAC1C,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAY;IACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;IAChD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,SAAS,CAAC,KAAgB;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@intentset/publisher",
3
+ "version": "0.1.0",
4
+ "description": "Audience and release projection of reviewed knowledge into Markset documents with provenance.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=22.18"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/intentset/intentset.git",
13
+ "directory": "packages/publisher"
14
+ },
15
+ "homepage": "https://intentset.org/",
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "src"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "intentset-source": "./src/index.ts",
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ }
29
+ },
30
+ "dependencies": {
31
+ "@intentset/core": "^0.1.0",
32
+ "@intentset/markset-adapter": "^0.1.0",
33
+ "@markset-lang/parser": "0.3.4",
34
+ "@markset-lang/render-html": "0.3.4"
35
+ }
36
+ }
package/src/body.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Line arithmetic between a knowledge body and the file it came from, so a
3
+ * publication diagnostic about the body can point at the line an author
4
+ * edits. When the offset cannot be established the location is left out,
5
+ * never guessed (ADR 0004).
6
+ */
7
+ import { type Artifact, type Location, collectHeadings } from "@intentset/core";
8
+
9
+ /**
10
+ * The number to add to a 1-based body line to get its file line, found by
11
+ * matching the body's first heading with the carrier's first heading. Null
12
+ * when the document has no heading or the two disagree.
13
+ */
14
+ export function bodyLineOffset(artifact: Artifact): number | null {
15
+ const fromFile = artifact.headings[0];
16
+ const fromBody = collectHeadings(artifact.body.split("\n"), 0)[0];
17
+ if (fromFile === undefined || fromBody === undefined || fromFile.text !== fromBody.text) return null;
18
+ return fromFile.line - fromBody.line;
19
+ }
20
+
21
+ /** A file location for a 1-based body line, or undefined when the offset is unknown. */
22
+ export function fileLocation(offset: number | null, bodyLine: number | undefined): Location | undefined {
23
+ if (offset === null || bodyLine === undefined) return undefined;
24
+ return { line: bodyLine + offset };
25
+ }
26
+
27
+ /** The 1-based line of a character index in a text. */
28
+ export function lineAt(text: string, index: number): number {
29
+ let line = 1;
30
+ for (let i = 0; i < index && i < text.length; i++) if (text.charCodeAt(i) === 10) line++;
31
+ return line;
32
+ }