@wowok/agent-mcp 2.3.13 → 2.3.16

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 (194) hide show
  1. package/dist/config/index.d.ts +1 -0
  2. package/dist/config/index.js +1 -0
  3. package/dist/config/runtime.d.ts +26 -0
  4. package/dist/config/runtime.js +217 -0
  5. package/dist/customer/industry-risks.d.ts +36 -0
  6. package/dist/customer/industry-risks.js +424 -0
  7. package/dist/customer/info-puzzle.d.ts +102 -0
  8. package/dist/customer/info-puzzle.js +312 -0
  9. package/dist/customer/order-monitor.d.ts +75 -0
  10. package/dist/customer/order-monitor.js +327 -0
  11. package/dist/customer/order-strategy.d.ts +36 -0
  12. package/dist/customer/order-strategy.js +373 -0
  13. package/dist/customer/post-purchase.d.ts +42 -0
  14. package/dist/customer/post-purchase.js +350 -0
  15. package/dist/customer/reminder-system.d.ts +42 -0
  16. package/dist/customer/reminder-system.js +295 -0
  17. package/dist/customer/risk-assessment.d.ts +8 -0
  18. package/dist/customer/risk-assessment.js +337 -0
  19. package/dist/customer/types.d.ts +193 -0
  20. package/dist/customer/types.js +13 -0
  21. package/dist/customer/user-preferences.d.ts +67 -0
  22. package/dist/customer/user-preferences.js +451 -0
  23. package/dist/experience/experience-reuse.d.ts +10 -0
  24. package/dist/experience/experience-reuse.js +103 -0
  25. package/dist/experience/index.d.ts +6 -0
  26. package/dist/experience/index.js +5 -0
  27. package/dist/experience/intent-distill.d.ts +3 -0
  28. package/dist/experience/intent-distill.js +83 -0
  29. package/dist/experience/realtime-feedback.d.ts +5 -0
  30. package/dist/experience/realtime-feedback.js +77 -0
  31. package/dist/experience/types.d.ts +50 -0
  32. package/dist/experience/types.js +1 -0
  33. package/dist/experience/user-profile.d.ts +25 -0
  34. package/dist/experience/user-profile.js +171 -0
  35. package/dist/harness/checkpoint.d.ts +8 -0
  36. package/dist/harness/checkpoint.js +129 -0
  37. package/dist/harness/index.d.ts +33 -0
  38. package/dist/harness/index.js +75 -0
  39. package/dist/harness/plan.d.ts +18 -0
  40. package/dist/harness/plan.js +252 -0
  41. package/dist/harness/recover.d.ts +17 -0
  42. package/dist/harness/recover.js +139 -0
  43. package/dist/harness/types.d.ts +137 -0
  44. package/dist/harness/types.js +1 -0
  45. package/dist/harness/verify.d.ts +42 -0
  46. package/dist/harness/verify.js +237 -0
  47. package/dist/index.js +667 -201
  48. package/dist/knowledge/acquisition-flywheel.d.ts +50 -0
  49. package/dist/knowledge/acquisition-flywheel.js +183 -0
  50. package/dist/knowledge/arbitration-trust.d.ts +24 -0
  51. package/dist/knowledge/arbitration-trust.js +117 -0
  52. package/dist/knowledge/audit-rules.d.ts +28 -0
  53. package/dist/knowledge/audit-rules.js +141 -0
  54. package/dist/knowledge/demand-matching.d.ts +29 -0
  55. package/dist/knowledge/demand-matching.js +132 -0
  56. package/dist/knowledge/dynamic-pricing.d.ts +31 -0
  57. package/dist/knowledge/dynamic-pricing.js +87 -0
  58. package/dist/knowledge/flywheel-loop.d.ts +87 -0
  59. package/dist/knowledge/flywheel-loop.js +378 -0
  60. package/dist/knowledge/glossary.d.ts +18 -0
  61. package/dist/knowledge/glossary.js +209 -0
  62. package/dist/knowledge/index.d.ts +64 -0
  63. package/dist/knowledge/index.js +66 -0
  64. package/dist/knowledge/industry-evolution.d.ts +82 -0
  65. package/dist/knowledge/industry-evolution.js +323 -0
  66. package/dist/knowledge/industry-generalizer.d.ts +17 -0
  67. package/dist/knowledge/industry-generalizer.js +381 -0
  68. package/dist/knowledge/industry-registry.d.ts +49 -0
  69. package/dist/knowledge/industry-registry.js +167 -0
  70. package/dist/knowledge/intent-metrics.d.ts +42 -0
  71. package/dist/knowledge/intent-metrics.js +566 -0
  72. package/dist/knowledge/process-model.d.ts +24 -0
  73. package/dist/knowledge/process-model.js +160 -0
  74. package/dist/knowledge/reputation-rules.d.ts +42 -0
  75. package/dist/knowledge/reputation-rules.js +99 -0
  76. package/dist/knowledge/reward-templates.d.ts +25 -0
  77. package/dist/knowledge/reward-templates.js +125 -0
  78. package/dist/knowledge/safety-rules.d.ts +36 -0
  79. package/dist/knowledge/safety-rules.js +171 -0
  80. package/dist/knowledge/tool-constraints.d.ts +30 -0
  81. package/dist/knowledge/tool-constraints.js +185 -0
  82. package/dist/knowledge/trust-metrics.d.ts +37 -0
  83. package/dist/knowledge/trust-metrics.js +138 -0
  84. package/dist/loop-engineering/aggregate.d.ts +50 -0
  85. package/dist/loop-engineering/aggregate.js +132 -0
  86. package/dist/loop-engineering/diagnose.d.ts +22 -0
  87. package/dist/loop-engineering/diagnose.js +273 -0
  88. package/dist/loop-engineering/improve.d.ts +26 -0
  89. package/dist/loop-engineering/improve.js +229 -0
  90. package/dist/loop-engineering/index.d.ts +4 -0
  91. package/dist/loop-engineering/index.js +4 -0
  92. package/dist/loop-engineering/pipeline.d.ts +17 -0
  93. package/dist/loop-engineering/pipeline.js +56 -0
  94. package/dist/mode-market/index.d.ts +3 -0
  95. package/dist/mode-market/index.js +3 -0
  96. package/dist/mode-market/registry.d.ts +53 -0
  97. package/dist/mode-market/registry.js +124 -0
  98. package/dist/mode-market/review.d.ts +27 -0
  99. package/dist/mode-market/review.js +214 -0
  100. package/dist/mode-market/submission.d.ts +25 -0
  101. package/dist/mode-market/submission.js +85 -0
  102. package/dist/project/graph.d.ts +71 -0
  103. package/dist/project/graph.js +314 -0
  104. package/dist/project/index.d.ts +62 -0
  105. package/dist/project/index.js +167 -0
  106. package/dist/project/namespace.d.ts +62 -0
  107. package/dist/project/namespace.js +181 -0
  108. package/dist/project/query.d.ts +40 -0
  109. package/dist/project/query.js +110 -0
  110. package/dist/safety/confirm-gate.d.ts +15 -0
  111. package/dist/safety/confirm-gate.js +44 -0
  112. package/dist/safety/index.d.ts +3 -0
  113. package/dist/safety/index.js +3 -0
  114. package/dist/safety/preview.d.ts +2 -0
  115. package/dist/safety/preview.js +36 -0
  116. package/dist/schema/call/allocation.d.ts +55 -40
  117. package/dist/schema/call/arbitration.d.ts +201 -186
  118. package/dist/schema/call/base.d.ts +2104 -24
  119. package/dist/schema/call/base.js +168 -22
  120. package/dist/schema/call/bridge-handler.js +36 -18
  121. package/dist/schema/call/bridge.d.ts +777 -120
  122. package/dist/schema/call/bridge.js +13 -2
  123. package/dist/schema/call/contact.d.ts +15 -0
  124. package/dist/schema/call/demand.d.ts +69 -54
  125. package/dist/schema/call/guard.d.ts +125 -80
  126. package/dist/schema/call/handler.d.ts +5 -1
  127. package/dist/schema/call/handler.js +108 -3
  128. package/dist/schema/call/index.d.ts +1 -0
  129. package/dist/schema/call/index.js +1 -0
  130. package/dist/schema/call/machine.d.ts +830 -800
  131. package/dist/schema/call/order.d.ts +27 -12
  132. package/dist/schema/call/payment.d.ts +15 -0
  133. package/dist/schema/call/permission.d.ts +15 -0
  134. package/dist/schema/call/personal.d.ts +15 -0
  135. package/dist/schema/call/progress.d.ts +21 -6
  136. package/dist/schema/call/proof.d.ts +42 -12
  137. package/dist/schema/call/proof.js +3 -3
  138. package/dist/schema/call/repository.d.ts +91 -76
  139. package/dist/schema/call/reward.d.ts +51 -36
  140. package/dist/schema/call/semantic.d.ts +24 -0
  141. package/dist/schema/call/semantic.js +981 -0
  142. package/dist/schema/call/service.d.ts +444 -429
  143. package/dist/schema/call/treasury.d.ts +219 -204
  144. package/dist/schema/common/index.js +3 -3
  145. package/dist/schema/local/index.d.ts +341 -74
  146. package/dist/schema/local/index.js +44 -7
  147. package/dist/schema/messenger/index.d.ts +1034 -92
  148. package/dist/schema/messenger/index.js +18 -0
  149. package/dist/schema/operations.d.ts +2634 -1817
  150. package/dist/schema/operations.js +16 -5
  151. package/dist/schema/query/index.d.ts +2293 -2289
  152. package/dist/schema/query/index.js +34 -28
  153. package/dist/schemas/account_operation.output.json +28 -16
  154. package/dist/schemas/account_operation.schema.json +2 -2
  155. package/dist/schemas/bridge_operation.output.json +520 -0
  156. package/dist/schemas/bridge_operation.schema.json +15 -0
  157. package/dist/schemas/guard2file.schema.json +15 -0
  158. package/dist/schemas/index.json +1 -1
  159. package/dist/schemas/local_info_operation.output.json +26 -0
  160. package/dist/schemas/local_info_operation.schema.json +1 -1
  161. package/dist/schemas/local_mark_operation.output.json +27 -1
  162. package/dist/schemas/local_mark_operation.schema.json +4 -4
  163. package/dist/schemas/machineNode2file.schema.json +15 -0
  164. package/dist/schemas/messenger_operation.output.json +549 -0
  165. package/dist/schemas/messenger_operation.schema.json +21 -0
  166. package/dist/schemas/onchain_events.output.json +3 -0
  167. package/dist/schemas/onchain_operations.output.json +814 -37
  168. package/dist/schemas/onchain_operations.schema.json +117 -40
  169. package/dist/schemas/onchain_operations_allocation.schema.json +26 -9
  170. package/dist/schemas/onchain_operations_arbitration.schema.json +26 -9
  171. package/dist/schemas/onchain_operations_contact.schema.json +26 -9
  172. package/dist/schemas/onchain_operations_demand.schema.json +26 -9
  173. package/dist/schemas/onchain_operations_gen_passport.schema.json +51 -17
  174. package/dist/schemas/onchain_operations_guard.schema.json +26 -9
  175. package/dist/schemas/onchain_operations_machine.schema.json +92 -32
  176. package/dist/schemas/onchain_operations_order.schema.json +26 -9
  177. package/dist/schemas/onchain_operations_payment.schema.json +26 -9
  178. package/dist/schemas/onchain_operations_permission.schema.json +26 -9
  179. package/dist/schemas/onchain_operations_personal.schema.json +26 -9
  180. package/dist/schemas/onchain_operations_progress.schema.json +26 -9
  181. package/dist/schemas/onchain_operations_repository.schema.json +26 -9
  182. package/dist/schemas/onchain_operations_reward.schema.json +26 -9
  183. package/dist/schemas/onchain_operations_service.schema.json +26 -9
  184. package/dist/schemas/onchain_operations_treasury.schema.json +26 -9
  185. package/dist/schemas/onchain_table_data.output.json +224 -69
  186. package/dist/schemas/onchain_table_data.schema.json +2 -2
  187. package/dist/schemas/query_toolkit.schema.json +5 -1
  188. package/dist/telemetry/index.d.ts +19 -0
  189. package/dist/telemetry/index.js +112 -0
  190. package/dist/telemetry/redact.d.ts +2 -0
  191. package/dist/telemetry/redact.js +23 -0
  192. package/dist/telemetry/storage.d.ts +8 -0
  193. package/dist/telemetry/storage.js +80 -0
  194. package/package.json +6 -3
@@ -0,0 +1,181 @@
1
+ export const TAG_PREFIX = {
2
+ project: "project:",
3
+ type: "type:",
4
+ role: "role:",
5
+ industry: "industry:",
6
+ version: "version:",
7
+ shareable: "shareable:",
8
+ archived: "archived:",
9
+ };
10
+ export const NAMESPACE_CONSTRAINTS = {
11
+ projectPrefixMin: 3,
12
+ projectPrefixMax: 16,
13
+ purposeMin: 1,
14
+ purposeMax: 32,
15
+ versionPattern: /^v\d+$/,
16
+ };
17
+ export function validateProjectName(name) {
18
+ if (!name || typeof name !== "string") {
19
+ return { valid: false, reason: "name is empty" };
20
+ }
21
+ if (name.startsWith("0x")) {
22
+ return { valid: false, reason: "name must not start with '0x'" };
23
+ }
24
+ if (/^0x[0-9a-fA-F]{64}$/.test(name)) {
25
+ return { valid: false, reason: "name is an on-chain address, not a project name" };
26
+ }
27
+ const parts = name.split("_");
28
+ if (parts.length < 3) {
29
+ return {
30
+ valid: false,
31
+ reason: "name does not match `<prefix>_<type>_<purpose>[_v<version>]`",
32
+ };
33
+ }
34
+ const projectPrefix = parts[0];
35
+ const typeStr = parts[1];
36
+ let version;
37
+ let purpose;
38
+ const last = parts[parts.length - 1];
39
+ if (NAMESPACE_CONSTRAINTS.versionPattern.test(last)) {
40
+ version = last;
41
+ purpose = parts.slice(2, -1).join("_") || parts[2];
42
+ }
43
+ else {
44
+ purpose = parts.slice(2).join("_");
45
+ }
46
+ if (projectPrefix.length < NAMESPACE_CONSTRAINTS.projectPrefixMin) {
47
+ return { valid: false, reason: `projectPrefix too short (min ${NAMESPACE_CONSTRAINTS.projectPrefixMin})` };
48
+ }
49
+ if (projectPrefix.length > NAMESPACE_CONSTRAINTS.projectPrefixMax) {
50
+ return { valid: false, reason: `projectPrefix too long (max ${NAMESPACE_CONSTRAINTS.projectPrefixMax})` };
51
+ }
52
+ if (!/^[a-z][a-z0-9]*$/.test(projectPrefix)) {
53
+ return { valid: false, reason: "projectPrefix must be lowercase alphanumeric (start with a letter)" };
54
+ }
55
+ if (!isProjectObjectType(typeStr)) {
56
+ return { valid: false, reason: `unknown object type '${typeStr}'` };
57
+ }
58
+ if (!purpose || purpose.length < NAMESPACE_CONSTRAINTS.purposeMin) {
59
+ return { valid: false, reason: "purpose is empty" };
60
+ }
61
+ if (purpose.length > NAMESPACE_CONSTRAINTS.purposeMax) {
62
+ return { valid: false, reason: `purpose too long (max ${NAMESPACE_CONSTRAINTS.purposeMax})` };
63
+ }
64
+ if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(purpose)) {
65
+ return { valid: false, reason: "purpose must be alphanumeric (start with a letter)" };
66
+ }
67
+ return {
68
+ valid: true,
69
+ parsed: { projectPrefix, type: typeStr, purpose, version },
70
+ };
71
+ }
72
+ function isProjectObjectType(s) {
73
+ return [
74
+ "service", "machine", "guard", "permission", "reward", "arb",
75
+ "progress", "treasury", "demand", "repository", "contact", "order",
76
+ "allocation", "personal", "payment", "proof",
77
+ ].includes(s);
78
+ }
79
+ export function objectTypeFromOperation(operation_type) {
80
+ const direct = {
81
+ service: "service",
82
+ machine: "machine",
83
+ guard: "guard",
84
+ permission: "permission",
85
+ reward: "reward",
86
+ arbitration: "arb",
87
+ progress: "progress",
88
+ treasury: "treasury",
89
+ demand: "demand",
90
+ repository: "repository",
91
+ contact: "contact",
92
+ order: "order",
93
+ allocation: "allocation",
94
+ personal: "personal",
95
+ payment: "payment",
96
+ proof: "proof",
97
+ };
98
+ return direct[operation_type];
99
+ }
100
+ export function buildProjectTags(opts) {
101
+ const tags = new Set(opts.existingTags ?? []);
102
+ if (opts.projectPrefix) {
103
+ tags.add(`${TAG_PREFIX.project}${opts.projectPrefix}`);
104
+ }
105
+ if (opts.type) {
106
+ tags.add(`${TAG_PREFIX.type}${opts.type}`);
107
+ }
108
+ if (opts.role) {
109
+ tags.add(`${TAG_PREFIX.role}${opts.role}`);
110
+ }
111
+ if (opts.industry) {
112
+ tags.add(`${TAG_PREFIX.industry}${opts.industry}`);
113
+ }
114
+ if (opts.version) {
115
+ tags.add(`${TAG_PREFIX.version}${opts.version}`);
116
+ }
117
+ if (opts.shareable) {
118
+ tags.add(`${TAG_PREFIX.shareable}true`);
119
+ }
120
+ return Array.from(tags);
121
+ }
122
+ export function extractProjectPrefix(tags) {
123
+ if (!tags)
124
+ return undefined;
125
+ for (const t of tags) {
126
+ if (t.startsWith(TAG_PREFIX.project)) {
127
+ return t.slice(TAG_PREFIX.project.length);
128
+ }
129
+ }
130
+ return undefined;
131
+ }
132
+ export function normalizeForProject(input) {
133
+ const warnings = [];
134
+ const data = input.data;
135
+ if (!data || typeof data !== "object") {
136
+ return { data, warnings };
137
+ }
138
+ const namedNew = data.namedNew ?? data.object;
139
+ if (!namedNew || typeof namedNew !== "object") {
140
+ return { data, warnings };
141
+ }
142
+ const name = namedNew.name;
143
+ const inferredType = objectTypeFromOperation(input.operation_type);
144
+ let prefix = input.projectPrefix;
145
+ let version = input.version;
146
+ let nameValidation;
147
+ if (name) {
148
+ nameValidation = validateProjectName(name);
149
+ if (nameValidation.valid && nameValidation.parsed) {
150
+ prefix = prefix ?? nameValidation.parsed.projectPrefix;
151
+ version = version ?? nameValidation.parsed.version;
152
+ }
153
+ else if (nameValidation.reason && !nameValidation.reason.includes("address")) {
154
+ warnings.push(`Object name '${name}' does not follow the project naming convention ` +
155
+ `'<prefix>_<type>_<purpose>[_v<version>]': ${nameValidation.reason}. ` +
156
+ `Consider renaming for better project organization.`);
157
+ }
158
+ }
159
+ if (!prefix) {
160
+ return { data, warnings };
161
+ }
162
+ const existingTags = Array.isArray(namedNew.tags) ? namedNew.tags : [];
163
+ const projectTags = buildProjectTags({
164
+ projectPrefix: prefix,
165
+ type: inferredType,
166
+ role: input.role,
167
+ industry: input.industry,
168
+ version,
169
+ shareable: input.shareable,
170
+ existingTags,
171
+ });
172
+ if (projectTags.length > existingTags.length) {
173
+ namedNew.tags = projectTags;
174
+ }
175
+ return {
176
+ data,
177
+ warnings,
178
+ project: { prefix, type: inferredType, version },
179
+ };
180
+ }
181
+ export const NAMESPACE_VERSION = 1;
@@ -0,0 +1,40 @@
1
+ import type { ProjectGraph, GraphEdge } from "./graph.js";
2
+ export interface ProjectInfo {
3
+ prefix: string;
4
+ objectCount: number;
5
+ types: string[];
6
+ objects: Array<{
7
+ name?: string;
8
+ address?: string;
9
+ type?: string;
10
+ }>;
11
+ }
12
+ export interface DependencyTrace {
13
+ object: string;
14
+ directDependencies: GraphEdge[];
15
+ transitive: Array<{
16
+ object: string;
17
+ via: string[];
18
+ }>;
19
+ dangling: string[];
20
+ }
21
+ export interface ReverseTrace {
22
+ object: string;
23
+ referencedBy: GraphEdge[];
24
+ }
25
+ export declare function listProjects(): Promise<ProjectInfo[]>;
26
+ export declare function listProjectObjects(prefix: string): Promise<ProjectInfo["objects"]>;
27
+ export declare function listShareableObjects(): Promise<Array<{
28
+ name?: string;
29
+ address?: string;
30
+ type?: string;
31
+ project?: string;
32
+ }>>;
33
+ export declare function traceDependencies(graph: ProjectGraph, objectId: string): DependencyTrace;
34
+ export declare function traceReferencedBy(graph: ProjectGraph, objectId: string): ReverseTrace;
35
+ export declare function prePublishCheck(graph: ProjectGraph, serviceId: string): string[];
36
+ export declare function findCrossProjectReferences(graph: ProjectGraph): Array<{
37
+ edge: GraphEdge;
38
+ fromProject?: string;
39
+ toProject?: string;
40
+ }>;
@@ -0,0 +1,110 @@
1
+ import { LocalMark } from "@wowok/wowok";
2
+ import { extractProjectPrefix, TAG_PREFIX } from "./namespace.js";
3
+ export async function listProjects() {
4
+ const marks = await LocalMark.Instance().list(undefined);
5
+ const byProject = new Map();
6
+ for (const m of marks) {
7
+ const prefix = extractProjectPrefix(m.tags);
8
+ if (!prefix)
9
+ continue;
10
+ if (!byProject.has(prefix)) {
11
+ byProject.set(prefix, { prefix, objectCount: 0, types: [], objects: [] });
12
+ }
13
+ const proj = byProject.get(prefix);
14
+ proj.objectCount++;
15
+ const typeTag = m.tags?.find((t) => t.startsWith(TAG_PREFIX.type));
16
+ const type = typeTag?.slice(TAG_PREFIX.type.length);
17
+ if (type && !proj.types.includes(type))
18
+ proj.types.push(type);
19
+ proj.objects.push({ name: m.name, address: m.address, type });
20
+ }
21
+ return Array.from(byProject.values()).sort((a, b) => b.objectCount - a.objectCount);
22
+ }
23
+ export async function listProjectObjects(prefix) {
24
+ const marks = await LocalMark.Instance().list({ tags: [`${TAG_PREFIX.project}${prefix}`] });
25
+ return marks.map((m) => {
26
+ const typeTag = m.tags?.find((t) => t.startsWith(TAG_PREFIX.type));
27
+ return {
28
+ name: m.name,
29
+ address: m.address,
30
+ type: typeTag?.slice(TAG_PREFIX.type.length),
31
+ };
32
+ });
33
+ }
34
+ export async function listShareableObjects() {
35
+ const marks = await LocalMark.Instance().list({ tags: [`${TAG_PREFIX.shareable}true`] });
36
+ return marks.map((m) => {
37
+ const typeTag = m.tags?.find((t) => t.startsWith(TAG_PREFIX.type));
38
+ const projectTag = m.tags?.find((t) => t.startsWith(TAG_PREFIX.project));
39
+ return {
40
+ name: m.name,
41
+ address: m.address,
42
+ type: typeTag?.slice(TAG_PREFIX.type.length),
43
+ project: projectTag?.slice(TAG_PREFIX.project.length),
44
+ };
45
+ });
46
+ }
47
+ export function traceDependencies(graph, objectId) {
48
+ const directDependencies = graph.getDependencies(objectId);
49
+ const visited = new Set([objectId]);
50
+ const transitive = [];
51
+ const queue = directDependencies.map((e) => ({ id: e.to, via: [e.from, e.to] }));
52
+ const dangling = new Set();
53
+ while (queue.length > 0) {
54
+ const { id, via } = queue.shift();
55
+ if (visited.has(id))
56
+ continue;
57
+ visited.add(id);
58
+ const node = graph.getNode(id);
59
+ if (!node || (!node.address && !node.project)) {
60
+ dangling.add(id);
61
+ }
62
+ transitive.push({ object: id, via });
63
+ const nextEdges = graph.getDependencies(id);
64
+ for (const e of nextEdges) {
65
+ if (!visited.has(e.to)) {
66
+ queue.push({ id: e.to, via: [...via, e.to] });
67
+ }
68
+ }
69
+ }
70
+ return {
71
+ object: objectId,
72
+ directDependencies,
73
+ transitive,
74
+ dangling: Array.from(dangling),
75
+ };
76
+ }
77
+ export function traceReferencedBy(graph, objectId) {
78
+ return {
79
+ object: objectId,
80
+ referencedBy: graph.getReferencedBy(objectId),
81
+ };
82
+ }
83
+ export function prePublishCheck(graph, serviceId) {
84
+ const warnings = [];
85
+ const trace = traceDependencies(graph, serviceId);
86
+ if (trace.dangling.length > 0) {
87
+ warnings.push(`Service '${serviceId}' references objects not yet created: ${trace.dangling.join(", ")}. ` +
88
+ `Publishing will lock 'machine' and 'order_allocators' — ensure these are finalized first.`);
89
+ }
90
+ const cycles = graph.detectCycles();
91
+ if (cycles.length > 0) {
92
+ warnings.push(`Dependency graph contains ${cycles.length} cycle(s): ` +
93
+ cycles.map((c) => c.join(" → ")).join("; ") +
94
+ `. Cycles may indicate a design issue.`);
95
+ }
96
+ return warnings;
97
+ }
98
+ export function findCrossProjectReferences(graph) {
99
+ const result = [];
100
+ for (const edge of graph.getEdges()) {
101
+ const fromNode = graph.getNode(edge.from);
102
+ const toNode = graph.getNode(edge.to);
103
+ const fromProj = fromNode?.project;
104
+ const toProj = toNode?.project;
105
+ if (fromProj && toProj && fromProj !== toProj) {
106
+ result.push({ edge, fromProject: fromProj, toProject: toProj });
107
+ }
108
+ }
109
+ return result;
110
+ }
@@ -0,0 +1,15 @@
1
+ import type { CallEnv } from "../schema/call/base.js";
2
+ import { type ConfirmationRule, type OperationPreview } from "../knowledge/safety-rules.js";
3
+ export declare function isConfirmGateEnabled(): boolean;
4
+ export type ConfirmResult = {
5
+ pass: true;
6
+ } | {
7
+ pass: false;
8
+ level: ConfirmationRule["level"];
9
+ preview: OperationPreview;
10
+ rule_id: string;
11
+ };
12
+ export declare function confirmGate(operation_type: string, data: any, env: any, userIntentPhrases?: string[]): ConfirmResult;
13
+ export declare function isExplicitlyConfirmed(env: CallEnv & {
14
+ confirmed?: boolean;
15
+ }): boolean;
@@ -0,0 +1,44 @@
1
+ import { CONFIRMATION_RULES, } from "../knowledge/safety-rules.js";
2
+ import { isEnabled as isRuntimeEnabled } from "../config/index.js";
3
+ export function isConfirmGateEnabled() {
4
+ return isRuntimeEnabled("confirm_gate");
5
+ }
6
+ export function confirmGate(operation_type, data, env, userIntentPhrases) {
7
+ if (!isConfirmGateEnabled())
8
+ return { pass: true };
9
+ if (env?.confirmed === true)
10
+ return { pass: true };
11
+ let matched;
12
+ try {
13
+ matched = CONFIRMATION_RULES.find((r) => {
14
+ try {
15
+ return r.when(operation_type, data, env);
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ });
21
+ }
22
+ catch {
23
+ return { pass: true };
24
+ }
25
+ if (!matched)
26
+ return { pass: true };
27
+ if (matched.bypass_on_explicit_intent && userIntentPhrases && userIntentPhrases.length > 0) {
28
+ const lower = userIntentPhrases.map((p) => p.toLowerCase());
29
+ const bypass = matched.bypass_on_explicit_intent.some((p) => lower.some((u) => u.includes(p.toLowerCase())));
30
+ if (bypass)
31
+ return { pass: true };
32
+ }
33
+ let preview;
34
+ try {
35
+ preview = matched.preview(operation_type, data, env);
36
+ }
37
+ catch {
38
+ return { pass: true };
39
+ }
40
+ return { pass: false, level: matched.level, preview, rule_id: matched.id };
41
+ }
42
+ export function isExplicitlyConfirmed(env) {
43
+ return env?.confirmed === true;
44
+ }
@@ -0,0 +1,3 @@
1
+ export { confirmGate, isConfirmGateEnabled, isExplicitlyConfirmed, type ConfirmResult, } from "./confirm-gate.js";
2
+ export { renderPreview } from "./preview.js";
3
+ export { CONFIRMATION_RULES, DEFAULT_VALUE_WARNINGS, DEFAULT_AMOUNT_THRESHOLD, getAmountThreshold, formatAmount, collectDefaultWarnings, type ConfirmLevel, type OperationPreview, type ConfirmationRule, SAFETY_RULES_VERSION, } from "../knowledge/safety-rules.js";
@@ -0,0 +1,3 @@
1
+ export { confirmGate, isConfirmGateEnabled, isExplicitlyConfirmed, } from "./confirm-gate.js";
2
+ export { renderPreview } from "./preview.js";
3
+ export { CONFIRMATION_RULES, DEFAULT_VALUE_WARNINGS, DEFAULT_AMOUNT_THRESHOLD, getAmountThreshold, formatAmount, collectDefaultWarnings, SAFETY_RULES_VERSION, } from "../knowledge/safety-rules.js";
@@ -0,0 +1,2 @@
1
+ import type { OperationPreview } from "../knowledge/safety-rules.js";
2
+ export declare function renderPreview(p: OperationPreview): string;
@@ -0,0 +1,36 @@
1
+ const LEVEL_LABEL = {
2
+ none: "none",
3
+ standard: "Standard confirmation",
4
+ amount: "Amount confirmation",
5
+ publish: "Publish confirmation (irreversible lock)",
6
+ irreversible: "Irreversible operation confirmation",
7
+ };
8
+ export function renderPreview(p) {
9
+ const lines = [];
10
+ lines.push(`⚠️ Confirmation required — ${LEVEL_LABEL[p.level]}`);
11
+ lines.push(` Operation: ${p.operation}`);
12
+ if (p.object)
13
+ lines.push(` Object: ${p.object}`);
14
+ if (p.network)
15
+ lines.push(` Network: ${p.network}`);
16
+ if (p.account !== undefined)
17
+ lines.push(` Account: ${p.account === "" ? "(default)" : p.account}`);
18
+ if (p.amount) {
19
+ lines.push(` Amount: ${p.amount.human_readable} (${p.amount.value} smallest unit)` +
20
+ (p.amount.recipient ? ` → ${p.amount.recipient}` : ""));
21
+ }
22
+ if (p.immutable_after && p.immutable_after.length > 0) {
23
+ lines.push(` Fields becoming immutable: ${p.immutable_after.join(", ")}`);
24
+ }
25
+ if (p.warnings && p.warnings.length > 0) {
26
+ lines.push(" Warnings:");
27
+ for (const w of p.warnings)
28
+ lines.push(` - ${w}`);
29
+ }
30
+ if (p.irreversible) {
31
+ lines.push(" ⛔ This operation is IRREVERSIBLE. It cannot be undone.");
32
+ }
33
+ lines.push("");
34
+ lines.push("Confirm by re-calling with env.confirmed=true, or modify/cancel.");
35
+ return lines.join("\n");
36
+ }