@haneinfo/definition-registry 0.0.0-stage → 0.1.1

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 (117) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +65 -2
  3. package/agent-guide.md +159 -0
  4. package/dist/config.d.ts +5 -0
  5. package/dist/config.d.ts.map +1 -0
  6. package/dist/config.js +26 -0
  7. package/dist/config.js.map +1 -0
  8. package/dist/definition-registry.controller.d.ts +33 -0
  9. package/dist/definition-registry.controller.d.ts.map +1 -0
  10. package/dist/definition-registry.controller.js +135 -0
  11. package/dist/definition-registry.controller.js.map +1 -0
  12. package/dist/definition-registry.module.d.ts +12 -0
  13. package/dist/definition-registry.module.d.ts.map +1 -0
  14. package/dist/definition-registry.module.js +55 -0
  15. package/dist/definition-registry.module.js.map +1 -0
  16. package/dist/definition-registry.service.d.ts +183 -0
  17. package/dist/definition-registry.service.d.ts.map +1 -0
  18. package/dist/definition-registry.service.js +590 -0
  19. package/dist/definition-registry.service.js.map +1 -0
  20. package/dist/errors.d.ts +23 -0
  21. package/dist/errors.d.ts.map +1 -0
  22. package/dist/errors.js +48 -0
  23. package/dist/errors.js.map +1 -0
  24. package/dist/frontend/definition-review.d.ts +8 -0
  25. package/dist/frontend/definition-review.d.ts.map +1 -0
  26. package/dist/frontend/definition-review.js +30 -0
  27. package/dist/frontend/definition-review.js.map +1 -0
  28. package/dist/frontend/definitions-table.d.ts +4 -0
  29. package/dist/frontend/definitions-table.d.ts.map +1 -0
  30. package/dist/frontend/definitions-table.js +10 -0
  31. package/dist/frontend/definitions-table.js.map +1 -0
  32. package/dist/frontend/diff.d.ts +12 -0
  33. package/dist/frontend/diff.d.ts.map +1 -0
  34. package/dist/frontend/diff.js +43 -0
  35. package/dist/frontend/diff.js.map +1 -0
  36. package/dist/frontend/index.d.ts +5 -0
  37. package/dist/frontend/index.d.ts.map +1 -0
  38. package/dist/frontend/index.js +12 -0
  39. package/dist/frontend/index.js.map +1 -0
  40. package/dist/frontend/types.d.ts +59 -0
  41. package/dist/frontend/types.d.ts.map +1 -0
  42. package/dist/frontend/types.js +3 -0
  43. package/dist/frontend/types.js.map +1 -0
  44. package/dist/frontend.d.ts +7 -0
  45. package/dist/frontend.d.ts.map +1 -0
  46. package/dist/frontend.js +13 -0
  47. package/dist/frontend.js.map +1 -0
  48. package/dist/index.d.ts +17 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +39 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/json-patch.d.ts +38 -0
  53. package/dist/json-patch.d.ts.map +1 -0
  54. package/dist/json-patch.js +165 -0
  55. package/dist/json-patch.js.map +1 -0
  56. package/dist/kind-registry.d.ts +84 -0
  57. package/dist/kind-registry.d.ts.map +1 -0
  58. package/dist/kind-registry.js +89 -0
  59. package/dist/kind-registry.js.map +1 -0
  60. package/dist/mcp-tools.d.ts +42 -0
  61. package/dist/mcp-tools.d.ts.map +1 -0
  62. package/dist/mcp-tools.js +239 -0
  63. package/dist/mcp-tools.js.map +1 -0
  64. package/dist/permissions.d.ts +8 -0
  65. package/dist/permissions.d.ts.map +1 -0
  66. package/dist/permissions.js +19 -0
  67. package/dist/permissions.js.map +1 -0
  68. package/dist/plugin.d.ts +21 -0
  69. package/dist/plugin.d.ts.map +1 -0
  70. package/dist/plugin.js +103 -0
  71. package/dist/plugin.js.map +1 -0
  72. package/dist/prisma-store.d.ts +81 -0
  73. package/dist/prisma-store.d.ts.map +1 -0
  74. package/dist/prisma-store.js +144 -0
  75. package/dist/prisma-store.js.map +1 -0
  76. package/dist/repo-sync.d.ts +16 -0
  77. package/dist/repo-sync.d.ts.map +1 -0
  78. package/dist/repo-sync.js +50 -0
  79. package/dist/repo-sync.js.map +1 -0
  80. package/dist/repo-validation.d.ts +16 -0
  81. package/dist/repo-validation.d.ts.map +1 -0
  82. package/dist/repo-validation.js +41 -0
  83. package/dist/repo-validation.js.map +1 -0
  84. package/dist/store.d.ts +79 -0
  85. package/dist/store.d.ts.map +1 -0
  86. package/dist/store.js +150 -0
  87. package/dist/store.js.map +1 -0
  88. package/dist/testing.d.ts +50 -0
  89. package/dist/testing.d.ts.map +1 -0
  90. package/dist/testing.js +174 -0
  91. package/dist/testing.js.map +1 -0
  92. package/dist/tokens.d.ts +2 -0
  93. package/dist/tokens.d.ts.map +1 -0
  94. package/dist/tokens.js +5 -0
  95. package/dist/tokens.js.map +1 -0
  96. package/dist/types.d.ts +76 -0
  97. package/dist/types.d.ts.map +1 -0
  98. package/dist/types.js +3 -0
  99. package/dist/types.js.map +1 -0
  100. package/dist/user-content.d.ts +23 -0
  101. package/dist/user-content.d.ts.map +1 -0
  102. package/dist/user-content.js +59 -0
  103. package/dist/user-content.js.map +1 -0
  104. package/dist/validation.d.ts +16 -0
  105. package/dist/validation.d.ts.map +1 -0
  106. package/dist/validation.js +69 -0
  107. package/dist/validation.js.map +1 -0
  108. package/examples/README.md +9 -0
  109. package/examples/definitions/welcome/welcome.note.json +13 -0
  110. package/examples/note-kind/note.spec.json +11 -0
  111. package/haneinfo.plugin.json +70 -0
  112. package/package.json +92 -3
  113. package/plugin.d.ts +2 -0
  114. package/plugin.js +4 -0
  115. package/prisma/definition-registry.prisma +71 -0
  116. package/testing.d.ts +2 -0
  117. package/testing.js +3 -0
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ /**
3
+ * RFC 6902 JSON Patch over plain JSON values. Applied to a deep copy: the input is never mutated,
4
+ * and a failing operation leaves nothing half-applied. Errors name the operation index and the
5
+ * pointer so an agent can fix the one bad operation instead of guessing.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.JsonPatchError = void 0;
9
+ exports.applyJsonPatch = applyJsonPatch;
10
+ exports.deepEqual = deepEqual;
11
+ const plugin_api_1 = require("@haneinfo/plugin-api");
12
+ class JsonPatchError extends Error {
13
+ constructor(index, path, message) {
14
+ super(`operation ${index} (${path || '<root>'}): ${message}`);
15
+ this.index = index;
16
+ this.path = path;
17
+ this.name = 'JsonPatchError';
18
+ }
19
+ }
20
+ exports.JsonPatchError = JsonPatchError;
21
+ function isContainer(value) {
22
+ return typeof value === 'object' && value !== null;
23
+ }
24
+ function clone(value) {
25
+ return value === undefined ? value : JSON.parse(JSON.stringify(value));
26
+ }
27
+ function deepEqual(a, b) {
28
+ if (a === b)
29
+ return true;
30
+ if (Array.isArray(a) && Array.isArray(b)) {
31
+ return a.length === b.length && a.every((item, index) => deepEqual(item, b[index]));
32
+ }
33
+ if (isContainer(a) && isContainer(b) && !Array.isArray(a) && !Array.isArray(b)) {
34
+ const aKeys = Object.keys(a);
35
+ const bKeys = Object.keys(b);
36
+ return (aKeys.length === bKeys.length &&
37
+ aKeys.every((key) => Object.getOwnPropertyDescriptor(b, key) !== undefined && deepEqual(a[key], b[key])));
38
+ }
39
+ return false;
40
+ }
41
+ const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
42
+ function arrayIndex(array, segment, allowEnd) {
43
+ if (allowEnd && segment === '-')
44
+ return array.length;
45
+ if (!/^(0|[1-9][0-9]*)$/.test(segment))
46
+ return null;
47
+ const index = Number(segment);
48
+ return index <= (allowEnd ? array.length : array.length - 1) ? index : null;
49
+ }
50
+ function locate(document, pointer, index) {
51
+ let segments;
52
+ try {
53
+ segments = (0, plugin_api_1.parseJsonPointer)(pointer);
54
+ }
55
+ catch (error) {
56
+ throw new JsonPatchError(index, pointer, error.message);
57
+ }
58
+ if (segments.length === 0)
59
+ throw new JsonPatchError(index, pointer, 'the root cannot be targeted');
60
+ let node = document;
61
+ for (const segment of segments.slice(0, -1)) {
62
+ if (FORBIDDEN_KEYS.has(segment))
63
+ throw new JsonPatchError(index, pointer, `"${segment}" is not allowed`);
64
+ if (Array.isArray(node)) {
65
+ const at = arrayIndex(node, segment, false);
66
+ if (at === null)
67
+ throw new JsonPatchError(index, pointer, `array index "${segment}" does not exist`);
68
+ node = node[at];
69
+ }
70
+ else if (isContainer(node) && Object.getOwnPropertyDescriptor(node, segment) !== undefined) {
71
+ node = node[segment];
72
+ }
73
+ else {
74
+ throw new JsonPatchError(index, pointer, `"${segment}" does not exist`);
75
+ }
76
+ }
77
+ if (!isContainer(node))
78
+ throw new JsonPatchError(index, pointer, 'the parent is not an object or array');
79
+ const key = segments[segments.length - 1];
80
+ if (FORBIDDEN_KEYS.has(key))
81
+ throw new JsonPatchError(index, pointer, `"${key}" is not allowed`);
82
+ return { parent: node, key };
83
+ }
84
+ function read(document, pointer, index) {
85
+ if (pointer === '')
86
+ return document;
87
+ const { parent, key } = locate(document, pointer, index);
88
+ if (Array.isArray(parent)) {
89
+ const at = arrayIndex(parent, key, false);
90
+ if (at === null)
91
+ throw new JsonPatchError(index, pointer, `array index "${key}" does not exist`);
92
+ return parent[at];
93
+ }
94
+ if (Object.getOwnPropertyDescriptor(parent, key) === undefined) {
95
+ throw new JsonPatchError(index, pointer, `"${key}" does not exist`);
96
+ }
97
+ return parent[key];
98
+ }
99
+ function add(document, pointer, value, index) {
100
+ const { parent, key } = locate(document, pointer, index);
101
+ if (Array.isArray(parent)) {
102
+ const at = arrayIndex(parent, key, true);
103
+ if (at === null)
104
+ throw new JsonPatchError(index, pointer, `array index "${key}" is out of range`);
105
+ parent.splice(at, 0, value);
106
+ }
107
+ else {
108
+ parent[key] = value;
109
+ }
110
+ }
111
+ function remove(document, pointer, index) {
112
+ const { parent, key } = locate(document, pointer, index);
113
+ if (Array.isArray(parent)) {
114
+ const at = arrayIndex(parent, key, false);
115
+ if (at === null)
116
+ throw new JsonPatchError(index, pointer, `array index "${key}" does not exist`);
117
+ return parent.splice(at, 1)[0];
118
+ }
119
+ if (Object.getOwnPropertyDescriptor(parent, key) === undefined) {
120
+ throw new JsonPatchError(index, pointer, `"${key}" does not exist`);
121
+ }
122
+ const removed = parent[key];
123
+ delete parent[key];
124
+ return removed;
125
+ }
126
+ function applyJsonPatch(document, operations) {
127
+ const working = clone(document);
128
+ operations.forEach((operation, index) => {
129
+ switch (operation.op) {
130
+ case 'add':
131
+ add(working, operation.path, clone(operation.value), index);
132
+ break;
133
+ case 'remove':
134
+ remove(working, operation.path, index);
135
+ break;
136
+ case 'replace':
137
+ remove(working, operation.path, index);
138
+ add(working, operation.path, clone(operation.value), index);
139
+ break;
140
+ case 'move': {
141
+ if (operation.path === operation.from || operation.path.startsWith(`${operation.from}/`)) {
142
+ if (operation.path !== operation.from) {
143
+ throw new JsonPatchError(index, operation.path, 'cannot move a value into itself');
144
+ }
145
+ break;
146
+ }
147
+ const value = remove(working, operation.from, index);
148
+ add(working, operation.path, value, index);
149
+ break;
150
+ }
151
+ case 'copy':
152
+ add(working, operation.path, clone(read(working, operation.from, index)), index);
153
+ break;
154
+ case 'test':
155
+ if (!deepEqual(read(working, operation.path, index), operation.value)) {
156
+ throw new JsonPatchError(index, operation.path, 'test failed: the current value differs');
157
+ }
158
+ break;
159
+ default:
160
+ throw new JsonPatchError(index, operation.path ?? '', 'unknown op');
161
+ }
162
+ });
163
+ return working;
164
+ }
165
+ //# sourceMappingURL=json-patch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-patch.js","sourceRoot":"","sources":["../src/json-patch.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA0IH,wCAsCC;AAEQ,8BAAS;AAhLlB,qDAAwD;AAUxD,MAAa,cAAe,SAAQ,KAAK;IACvC,YACW,KAAa,EACb,IAAY,EACrB,OAAe;QAEf,KAAK,CAAC,aAAa,KAAK,KAAK,IAAI,IAAI,QAAQ,MAAM,OAAO,EAAE,CAAC,CAAC;QAJrD,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAQ;QAIrB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AATD,wCASC;AAID,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED,SAAS,KAAK,CAAI,KAAQ;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K,EAAG,SAA+B,CAAC,IAAI,IAAI,EAAE,EAAE,YAAY,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,84 @@
1
+ import { type DefinitionKindRegistration, findDefinitionRefs } from '@haneinfo/plugin-api';
2
+ import { type CompiledDefinitionKind } from '@haneinfo/plugin-api/loader';
3
+ export interface RegisteredKind {
4
+ registration: DefinitionKindRegistration;
5
+ compiled: CompiledDefinitionKind;
6
+ freeTextPaths: string[];
7
+ }
8
+ /** What `list_definition_kinds` returns per kind. */
9
+ export interface DefinitionKindSummary {
10
+ kind: string;
11
+ schemaVersion: number;
12
+ displayName: string;
13
+ description?: string;
14
+ permissions: {
15
+ read: string;
16
+ write: string;
17
+ publish: string;
18
+ };
19
+ }
20
+ export declare class KindRegistry {
21
+ private readonly kinds;
22
+ register(registration: DefinitionKindRegistration): void;
23
+ has(kind: string): boolean;
24
+ get(kind: string): RegisteredKind | undefined;
25
+ compiledMap(): ReadonlyMap<string, CompiledDefinitionKind>;
26
+ list(): DefinitionKindSummary[];
27
+ schemaOf(kind: string): {
28
+ example?: import("@haneinfo/plugin-api").DefinitionEnvelope<unknown> | undefined;
29
+ envelopeSchema: Readonly<{
30
+ $schema: "https://json-schema.org/draft/2020-12/schema";
31
+ $id: "https://haneinfo.dev/schemas/definition-envelope.json";
32
+ title: "Haneinfo definition envelope";
33
+ type: "object";
34
+ additionalProperties: false;
35
+ required: string[];
36
+ properties: {
37
+ kind: {
38
+ type: string;
39
+ pattern: string;
40
+ maxLength: 64;
41
+ };
42
+ schemaVersion: {
43
+ type: string;
44
+ minimum: number;
45
+ };
46
+ metadata: {
47
+ type: string;
48
+ additionalProperties: boolean;
49
+ required: string[];
50
+ properties: {
51
+ code: {
52
+ type: string;
53
+ pattern: string;
54
+ maxLength: 64;
55
+ };
56
+ name: {
57
+ type: string;
58
+ minLength: number;
59
+ maxLength: 200;
60
+ };
61
+ description: {
62
+ type: string;
63
+ maxLength: 2000;
64
+ };
65
+ };
66
+ };
67
+ spec: {
68
+ type: string;
69
+ };
70
+ };
71
+ }>;
72
+ specSchema: Record<string, unknown>;
73
+ freeTextPaths: string[];
74
+ referenceConvention: string;
75
+ description?: string | undefined;
76
+ kind: string;
77
+ schemaVersion: number;
78
+ displayName: string;
79
+ } | undefined;
80
+ extractRefs(definition: Parameters<typeof findDefinitionRefs>[0] & {
81
+ kind: string;
82
+ }): import("@haneinfo/plugin-api").ExtractedDefinitionRef[];
83
+ }
84
+ //# sourceMappingURL=kind-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kind-registry.d.ts","sourceRoot":"","sources":["../src/kind-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,0BAA0B,EAE/B,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,KAAK,sBAAsB,EAAyB,MAAM,6BAA6B,CAAC;AAGjG,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,0BAA0B,CAAC;IACzC,QAAQ,EAAE,sBAAsB,CAAC;IACjC,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,qDAAqD;AACrD,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/D;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqC;IAE3D,QAAQ,CAAC,YAAY,EAAE,0BAA0B,GAAG,IAAI;IAkCxD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAI7C,WAAW,IAAI,WAAW,CAAC,MAAM,EAAE,sBAAsB,CAAC;IAI1D,IAAI,IAAI,qBAAqB,EAAE;IAgB/B,QAAQ,CAAC,IAAI,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkBrB,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;CAMpF"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KindRegistry = void 0;
4
+ const plugin_api_1 = require("@haneinfo/plugin-api");
5
+ const loader_1 = require("@haneinfo/plugin-api/loader");
6
+ const user_content_1 = require("./user-content");
7
+ class KindRegistry {
8
+ constructor() {
9
+ this.kinds = new Map();
10
+ }
11
+ register(registration) {
12
+ if (!plugin_api_1.DEFINITION_KIND_PATTERN.test(registration.kind)) {
13
+ throw new Error(`definition kind "${registration.kind}" must be PascalCase`);
14
+ }
15
+ if (!Number.isInteger(registration.schemaVersion) || registration.schemaVersion < 1) {
16
+ throw new Error(`definition kind "${registration.kind}" needs a positive integer schemaVersion`);
17
+ }
18
+ if (this.kinds.has(registration.kind)) {
19
+ throw new Error(`definition kind "${registration.kind}" is already registered`);
20
+ }
21
+ if (typeof registration.specSchema !== 'object' || registration.specSchema === null) {
22
+ throw new Error(`definition kind "${registration.kind}" must provide a specSchema`);
23
+ }
24
+ for (const pattern of registration.freeTextPaths ?? []) {
25
+ if (!pattern.startsWith('/spec/') && pattern !== '/spec') {
26
+ throw new Error(`free-text path "${pattern}" of kind "${registration.kind}" must be a JSON Pointer under /spec`);
27
+ }
28
+ }
29
+ const compiled = (0, loader_1.compileDefinitionKind)({
30
+ kind: registration.kind,
31
+ schemaVersion: registration.schemaVersion,
32
+ specSchema: registration.specSchema,
33
+ });
34
+ this.kinds.set(registration.kind, {
35
+ registration: registration,
36
+ compiled,
37
+ freeTextPaths: [...user_content_1.ENVELOPE_FREE_TEXT_PATHS, ...(registration.freeTextPaths ?? [])],
38
+ });
39
+ }
40
+ has(kind) {
41
+ return this.kinds.has(kind);
42
+ }
43
+ get(kind) {
44
+ return this.kinds.get(kind);
45
+ }
46
+ compiledMap() {
47
+ return new Map([...this.kinds].map(([kind, entry]) => [kind, entry.compiled]));
48
+ }
49
+ list() {
50
+ return [...this.kinds.values()]
51
+ .map(({ registration }) => ({
52
+ kind: registration.kind,
53
+ schemaVersion: registration.schemaVersion,
54
+ displayName: registration.displayName,
55
+ ...(registration.description ? { description: registration.description } : {}),
56
+ permissions: {
57
+ read: (0, plugin_api_1.definitionPermission)(registration.kind, 'read'),
58
+ write: (0, plugin_api_1.definitionPermission)(registration.kind, 'write'),
59
+ publish: (0, plugin_api_1.definitionPermission)(registration.kind, 'publish'),
60
+ },
61
+ }))
62
+ .sort((a, b) => (a.kind < b.kind ? -1 : 1));
63
+ }
64
+ schemaOf(kind) {
65
+ const entry = this.kinds.get(kind);
66
+ if (!entry)
67
+ return undefined;
68
+ const { registration } = entry;
69
+ return {
70
+ kind: registration.kind,
71
+ schemaVersion: registration.schemaVersion,
72
+ displayName: registration.displayName,
73
+ ...(registration.description ? { description: registration.description } : {}),
74
+ envelopeSchema: plugin_api_1.DEFINITION_ENVELOPE_JSON_SCHEMA,
75
+ specSchema: registration.specSchema,
76
+ freeTextPaths: entry.freeTextPaths,
77
+ referenceConvention: 'A reference to another definition is an object with exactly { "kind", "code" }. It always points at the latest published version.',
78
+ ...(registration.example ? { example: registration.example } : {}),
79
+ };
80
+ }
81
+ extractRefs(definition) {
82
+ const entry = this.kinds.get(definition.kind);
83
+ const extract = entry?.registration.extractRefs;
84
+ // biome-ignore lint/suspicious/noExplicitAny: envelope shape already validated by the caller
85
+ return extract ? extract(definition) : (0, plugin_api_1.findDefinitionRefs)(definition);
86
+ }
87
+ }
88
+ exports.KindRegistry = KindRegistry;
89
+ //# sourceMappingURL=kind-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kind-registry.js","sourceRoot":"","sources":["../src/kind-registry.ts"],"names":[],"mappings":";;;AAAA,qDAM8B;AAC9B,wDAAiG;AACjG,iDAA0D;AAiB1D,MAAa,YAAY;IAAzB;QACmB,UAAK,GAAG,IAAI,GAAG,EAA0B,CAAC;IAwF7D,CAAC;IAtFC,QAAQ,CAAC,YAAwC;QAC/C,IAAI,CAAC,oCAAuB,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACrD,MAAM,IAAI,KAAK,CAAC,oBAAoB,YAAY,CAAC,IAAI,sBAAsB,CAAC,CAAC;QAC/E,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,YAAY,CAAC,aAAa,GAAG,CAAC,EAAE,CAAC;YACpF,MAAM,IAAI,KAAK,CACb,oBAAoB,YAAY,CAAC,IAAI,0CAA0C,CAChF,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,oBAAoB,YAAY,CAAC,IAAI,yBAAyB,CAAC,CAAC;QAClF,CAAC;QACD,IAAI,OAAO,YAAY,CAAC,UAAU,KAAK,QAAQ,IAAI,YAAY,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YACpF,MAAM,IAAI,KAAK,CAAC,oBAAoB,YAAY,CAAC,IAAI,6BAA6B,CAAC,CAAC;QACtF,CAAC;QACD,KAAK,MAAM,OAAO,IAAI,YAAY,CAAC,aAAa,IAAI,EAAE,EAAE,CAAC;YACvD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;gBACzD,MAAM,IAAI,KAAK,CACb,mBAAmB,OAAO,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AAW,CAAC,UAAuE;QACjF,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,KAAK,EAAE,YAAY,CAAC,WAAW,CAAC;QAChD,6FAA6F;QAC7F,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,UAAiB,CAAC,CAAC,CAAC,CAAC,IAAA,+BAAkB,EAAC,UAAU,CAAC,CAAC;IAC/E,CAAC;CACF;AAzFD,oCAyFC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Generic MCP design tools (decision 202610-00b3, points 15–21).
3
+ *
4
+ * The App decides which MCP registry receives them — the employee connection registry, the
5
+ * machine registry, or both — by calling `DefinitionMcpTools.registerInto()` from its own tool
6
+ * module, the same way Apps register their own tools today. There is no publish tool on purpose.
7
+ *
8
+ * Expected failures come back as data (`{ ok: false, error }`) rather than as tool errors, so an
9
+ * agent gets the error code, the suggestion and the diagnostics' JSON Pointers instead of a bare
10
+ * message it has to parse.
11
+ */
12
+ import { type McpToolsPort, type RbacPolicyPort } from '@haneinfo/plugin-api';
13
+ import { DefinitionRegistryService } from './definition-registry.service';
14
+ import type { ResolvedDefinitionRegistryConfig } from './types';
15
+ /** The parts of `@haneinfo/mcp-server`'s `McpCallContext` the tools read. Structural on purpose. */
16
+ export interface DefinitionMcpCallContext {
17
+ scopes: string[];
18
+ actingUserId: string | null;
19
+ actingUserEmail?: string;
20
+ connectionId?: string;
21
+ sub: string;
22
+ workflowId: string | null;
23
+ }
24
+ export declare const DEFINITION_MCP_TOOL_NAMES: readonly ["list_definition_kinds", "get_definition_schema", "list_definitions", "get_definition", "create_definition_draft", "patch_definition_draft", "validate_definition", "get_capability_catalog"];
25
+ export declare class DefinitionMcpTools {
26
+ private readonly registry;
27
+ private readonly config;
28
+ private readonly rbac?;
29
+ constructor(registry: DefinitionRegistryService, config: ResolvedDefinitionRegistryConfig, rbac?: RbacPolicyPort | undefined);
30
+ /** Registers the design tools into an MCP registry (`McpToolRegistry` from `@haneinfo/mcp-server`). */
31
+ registerInto(target: McpToolsPort, options?: {
32
+ scopeNamespace?: string;
33
+ includeCapabilityCatalog?: boolean;
34
+ /** Defaults to `<cwd>/.haneinfo/generated/catalog.json`, which `haneinfo build` writes. */
35
+ catalogPath?: string;
36
+ }): void;
37
+ private receipt;
38
+ /** The acting user's RBAC authorization; fails closed for a credential bound to nobody. */
39
+ private actor;
40
+ private capabilityCatalog;
41
+ }
42
+ //# sourceMappingURL=mcp-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-tools.d.ts","sourceRoot":"","sources":["../src/mcp-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAEL,KAAK,YAAY,EAGjB,KAAK,cAAc,EACpB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,yBAAyB,EAG1B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAAmB,gCAAgC,EAAE,MAAM,SAAS,CAAC;AAGjF,oGAAoG;AACpG,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,eAAO,MAAM,yBAAyB,yMAS5B,CAAC;AAyFX,qBACa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACW,OAAO,CAAC,QAAQ,CAAC,MAAM;IAC1B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAFtC,QAAQ,EAAE,yBAAyB,EACC,MAAM,EAAE,gCAAgC,EAC3C,IAAI,CAAC,EAAE,cAAc,YAAA;IAGzE,uGAAuG;IACvG,YAAY,CACV,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE;QACP,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,wBAAwB,CAAC,EAAE,OAAO,CAAC;QACnC,2FAA2F;QAC3F,WAAW,CAAC,EAAE,MAAM,CAAC;KACjB,GACL,IAAI;IA2FP,OAAO,CAAC,OAAO;IAcf,2FAA2F;YAC7E,KAAK;IA2BnB,OAAO,CAAC,iBAAiB;CAW1B"}
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ /**
3
+ * Generic MCP design tools (decision 202610-00b3, points 15–21).
4
+ *
5
+ * The App decides which MCP registry receives them — the employee connection registry, the
6
+ * machine registry, or both — by calling `DefinitionMcpTools.registerInto()` from its own tool
7
+ * module, the same way Apps register their own tools today. There is no publish tool on purpose.
8
+ *
9
+ * Expected failures come back as data (`{ ok: false, error }`) rather than as tool errors, so an
10
+ * agent gets the error code, the suggestion and the diagnostics' JSON Pointers instead of a bare
11
+ * message it has to parse.
12
+ */
13
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
18
+ };
19
+ var __metadata = (this && this.__metadata) || function (k, v) {
20
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
21
+ };
22
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
23
+ return function (target, key) { decorator(target, key, paramIndex); }
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.DefinitionMcpTools = exports.DEFINITION_MCP_TOOL_NAMES = void 0;
30
+ const node_fs_1 = require("node:fs");
31
+ const node_path_1 = __importDefault(require("node:path"));
32
+ const plugin_api_1 = require("@haneinfo/plugin-api");
33
+ const common_1 = require("@nestjs/common");
34
+ const zod_1 = require("zod");
35
+ const definition_registry_service_1 = require("./definition-registry.service");
36
+ const errors_1 = require("./errors");
37
+ const tokens_1 = require("./tokens");
38
+ const user_content_1 = require("./user-content");
39
+ exports.DEFINITION_MCP_TOOL_NAMES = [
40
+ 'list_definition_kinds',
41
+ 'get_definition_schema',
42
+ 'list_definitions',
43
+ 'get_definition',
44
+ 'create_definition_draft',
45
+ 'patch_definition_draft',
46
+ 'validate_definition',
47
+ 'get_capability_catalog',
48
+ ];
49
+ const kindInput = zod_1.z
50
+ .string()
51
+ .regex(/^[A-Z][A-Za-z0-9]*$/)
52
+ .describe('Definition kind, e.g. "Form"');
53
+ const codeInput = zod_1.z
54
+ .string()
55
+ .regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/)
56
+ .describe('metadata.code, kebab-case');
57
+ const REQUEST_ID_HINT = 'requestId is required: generate a new UUID for this call, and send the same requestId only when retrying this exact call';
58
+ const requestIdInput = zod_1.z
59
+ .string({ error: REQUEST_ID_HINT })
60
+ .uuid({ error: REQUEST_ID_HINT })
61
+ .describe('A new UUID for every new call. Reuse it only to retry the exact same call.');
62
+ const patchOperation = zod_1.z.union([
63
+ zod_1.z.object({ op: zod_1.z.literal('add'), path: zod_1.z.string(), value: zod_1.z.unknown() }),
64
+ zod_1.z.object({ op: zod_1.z.literal('remove'), path: zod_1.z.string() }),
65
+ zod_1.z.object({ op: zod_1.z.literal('replace'), path: zod_1.z.string(), value: zod_1.z.unknown() }),
66
+ zod_1.z.object({ op: zod_1.z.literal('move'), from: zod_1.z.string(), path: zod_1.z.string() }),
67
+ zod_1.z.object({ op: zod_1.z.literal('copy'), from: zod_1.z.string(), path: zod_1.z.string() }),
68
+ zod_1.z.object({ op: zod_1.z.literal('test'), path: zod_1.z.string(), value: zod_1.z.unknown() }),
69
+ ]);
70
+ const inputs = {
71
+ list_definition_kinds: zod_1.z.object({}),
72
+ get_definition_schema: zod_1.z.object({ kind: kindInput }),
73
+ list_definitions: zod_1.z.object({
74
+ kind: kindInput.optional(),
75
+ source: zod_1.z.enum(['REPO', 'RUNTIME']).optional(),
76
+ }),
77
+ get_definition: zod_1.z.object({ kind: kindInput, code: codeInput }),
78
+ create_definition_draft: zod_1.z.object({
79
+ requestId: requestIdInput,
80
+ definition: zod_1.z
81
+ .record(zod_1.z.string(), zod_1.z.unknown())
82
+ .describe('The whole envelope: { kind, schemaVersion, metadata, spec }'),
83
+ }),
84
+ patch_definition_draft: zod_1.z.object({
85
+ requestId: requestIdInput,
86
+ kind: kindInput,
87
+ code: codeInput,
88
+ expectedVersion: zod_1.z
89
+ .number()
90
+ .int()
91
+ .positive()
92
+ .describe('The revision returned by get_definition or the last write'),
93
+ operations: zod_1.z
94
+ .array(patchOperation)
95
+ .min(1)
96
+ .max(200)
97
+ .describe('RFC 6902 JSON Patch; paths are JSON Pointers into the whole definition'),
98
+ }),
99
+ validate_definition: zod_1.z
100
+ .object({
101
+ kind: kindInput.optional(),
102
+ code: codeInput.optional(),
103
+ definition: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
104
+ })
105
+ .refine((value) => (value.definition !== undefined) !== (value.kind !== undefined && value.code !== undefined), {
106
+ message: 'Pass either { kind, code } to validate the stored draft, or { definition } to validate unsaved content',
107
+ }),
108
+ get_capability_catalog: zod_1.z.object({}),
109
+ };
110
+ const descriptions = {
111
+ list_definition_kinds: 'List the definition kinds installed in this App (Form, StateMachine, ...), with their schemaVersion and the RBAC permissions each needs.',
112
+ get_definition_schema: "Get the JSON Schema of one kind's definitions, the shared envelope, its free-text fields and a minimal example. Read this before writing a definition.",
113
+ list_definitions: `List definitions you may read, with source (REPO is read-only), current revision, draft and published state. ${user_content_1.USER_CONTENT_NOTICE}`,
114
+ get_definition: `Get one definition: its draft (if any), its latest published version and the revision to pass as expectedVersion. ${user_content_1.USER_CONTENT_NOTICE}`,
115
+ create_definition_draft: 'Create a new draft definition, or start a draft of a published runtime definition. Saves immediately but never publishes: a person reviews and publishes it in the App. Returns diagnostics with JSON Pointer paths; fix them with patch_definition_draft. Requires a new requestId (UUID); keep it on retries.',
116
+ patch_definition_draft: 'Change a draft with RFC 6902 JSON Patch. Pass the current revision as expectedVersion; on VERSION_CONFLICT read the definition again before retrying. Diagnostic paths can be used directly as patch paths. Requires a new requestId (UUID); keep it on retries.',
117
+ validate_definition: 'Validate a stored draft ({ kind, code }) or unsaved content ({ definition }) without saving anything. Returns diagnostics with JSON Pointer paths and suggestions.',
118
+ get_capability_catalog: "Get the App's capability catalog: installed plugins with their definition kinds, MCP tools, events, adapters and agent guides.",
119
+ };
120
+ let DefinitionMcpTools = class DefinitionMcpTools {
121
+ constructor(registry, config, rbac) {
122
+ this.registry = registry;
123
+ this.config = config;
124
+ this.rbac = rbac;
125
+ }
126
+ /** Registers the design tools into an MCP registry (`McpToolRegistry` from `@haneinfo/mcp-server`). */
127
+ registerInto(target, options = {}) {
128
+ const namespace = options.scopeNamespace ?? this.config.scopeNamespace;
129
+ if (!namespace) {
130
+ throw new Error('definition-registry MCP tools need a scope namespace: set definitionRegistry.scopeNamespace or MCP_TOOL_PREFIX');
131
+ }
132
+ const read = `${namespace}:definition:read`;
133
+ const write = `${namespace}:definition:write`;
134
+ const register = (name, scope, handler) => {
135
+ target.registerTool({
136
+ name,
137
+ description: descriptions[name],
138
+ inputSchema: inputs[name],
139
+ requiredScopes: [scope],
140
+ handler: async (raw, ctx) => {
141
+ try {
142
+ const args = inputs[name].parse(raw);
143
+ return {
144
+ ok: true,
145
+ ...(await handler(args, ctx)),
146
+ };
147
+ }
148
+ catch (error) {
149
+ if (error instanceof errors_1.DefinitionRegistryError)
150
+ return { ok: false, error: error.toJSON() };
151
+ if (error instanceof zod_1.z.ZodError) {
152
+ const missingRequestId = error.issues.some((issue) => issue.path[0] === 'requestId');
153
+ return {
154
+ ok: false,
155
+ error: {
156
+ code: missingRequestId ? 'REQUEST_ID_REQUIRED' : 'INVALID_INPUT',
157
+ message: missingRequestId ? REQUEST_ID_HINT : 'The tool input is invalid',
158
+ suggestion: error.issues
159
+ .map((issue) => `${issue.path.join('.') || '(input)'}: ${issue.message}`)
160
+ .join('; '),
161
+ },
162
+ };
163
+ }
164
+ throw error;
165
+ }
166
+ },
167
+ });
168
+ };
169
+ register('list_definition_kinds', read, async () => ({ kinds: this.registry.listKinds() }));
170
+ register('get_definition_schema', read, async ({ kind }) => this.registry.getKindSchema(kind));
171
+ register('list_definitions', read, async (args, ctx) => ({
172
+ definitions: await this.registry.list(await this.actor(ctx, 'list_definitions'), args),
173
+ }));
174
+ register('get_definition', read, async ({ kind, code }, ctx) => this.registry.get(await this.actor(ctx, 'get_definition'), { kind, code }));
175
+ register('create_definition_draft', write, async (args, ctx) => this.registry.createDraft(await this.actor(ctx, 'create_definition_draft'), args.definition, this.receipt('create_definition_draft', args, ctx)));
176
+ register('patch_definition_draft', write, async (args, ctx) => this.registry.patchDraft(await this.actor(ctx, 'patch_definition_draft'), { kind: args.kind, code: args.code }, args.expectedVersion, args.operations, this.receipt('patch_definition_draft', args, ctx)));
177
+ register('validate_definition', read, async (args, ctx) => {
178
+ const actor = await this.actor(ctx, 'validate_definition');
179
+ return args.definition !== undefined
180
+ ? this.registry.validate(actor, { definition: args.definition })
181
+ : this.registry.validate(actor, {
182
+ ref: { kind: args.kind, code: args.code },
183
+ });
184
+ });
185
+ if (options.includeCapabilityCatalog !== false) {
186
+ const catalogPath = options.catalogPath ?? node_path_1.default.join(process.cwd(), '.haneinfo', 'generated', 'catalog.json');
187
+ register('get_capability_catalog', read, async () => this.capabilityCatalog(catalogPath));
188
+ }
189
+ }
190
+ receipt(tool, args, ctx) {
191
+ const { requestId, ...rest } = args;
192
+ return {
193
+ callerKey: ctx.connectionId ?? `api-key:${ctx.sub}`,
194
+ requestId,
195
+ tool,
196
+ inputDigest: (0, definition_registry_service_1.digestOf)({ tool, input: rest }),
197
+ };
198
+ }
199
+ /** The acting user's RBAC authorization; fails closed for a credential bound to nobody. */
200
+ async actor(ctx, tool) {
201
+ if (!ctx.actingUserId) {
202
+ throw new errors_1.DefinitionRegistryError('FORBIDDEN', 'This credential is not bound to a user', 'Use an employee MCP connection, or an API key bound to a user');
203
+ }
204
+ let authorization = {
205
+ roleNames: [],
206
+ permissionPolicy: 'DENY_ALL',
207
+ permissions: [],
208
+ };
209
+ if (this.rbac)
210
+ authorization = this.rbac.flatten(await this.rbac.rolesForUser(ctx.actingUserId));
211
+ return {
212
+ userId: ctx.actingUserId,
213
+ email: ctx.actingUserEmail ?? '',
214
+ authorization,
215
+ isAiOperation: true,
216
+ mcpTool: tool,
217
+ apiKeyId: ctx.connectionId ? null : ctx.sub,
218
+ mcpConnectionId: ctx.connectionId ?? null,
219
+ workflowId: ctx.workflowId,
220
+ };
221
+ }
222
+ capabilityCatalog(file) {
223
+ try {
224
+ return { catalog: JSON.parse((0, node_fs_1.readFileSync)(file, 'utf8')) };
225
+ }
226
+ catch {
227
+ throw new errors_1.DefinitionRegistryError('DEFINITION_NOT_FOUND', 'The capability catalog was not found in this deployment', 'Run haneinfo build in the App and deploy .haneinfo/generated/catalog.json with it');
228
+ }
229
+ }
230
+ };
231
+ exports.DefinitionMcpTools = DefinitionMcpTools;
232
+ exports.DefinitionMcpTools = DefinitionMcpTools = __decorate([
233
+ (0, common_1.Injectable)(),
234
+ __param(1, (0, common_1.Inject)(tokens_1.DEFINITION_REGISTRY_CONFIG)),
235
+ __param(2, (0, common_1.Optional)()),
236
+ __param(2, (0, common_1.Inject)(plugin_api_1.RBAC_POLICY)),
237
+ __metadata("design:paramtypes", [definition_registry_service_1.DefinitionRegistryService, Object, Object])
238
+ ], DefinitionMcpTools);
239
+ //# sourceMappingURL=mcp-tools.js.map