@wowok/agent-mcp 2.6.0 → 2.6.3

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 (186) hide show
  1. package/README.md +5 -3
  2. package/dist/customer/info-puzzle.d.ts +1 -1
  3. package/dist/customer/info-puzzle.js +4 -2
  4. package/dist/customer/risk-assessment.js +26 -4
  5. package/dist/customer/types.d.ts +2 -0
  6. package/dist/examples/guard-template-balance-check.json +38 -0
  7. package/dist/examples/guard-template-time-lock.json +39 -0
  8. package/dist/examples/machine-template-7node-rental.json +114 -0
  9. package/dist/examples/rental-ziroom-machine-create.json +137 -0
  10. package/dist/examples/rental-ziroom-permission-create.json +35 -0
  11. package/dist/examples/rental-ziroom-service-create.json +80 -0
  12. package/dist/examples/retail-myshop-service-create.json +88 -0
  13. package/dist/extensions/capability-manifest.d.ts +125 -0
  14. package/dist/extensions/capability-manifest.js +594 -0
  15. package/dist/extensions/constraint-registry.d.ts +24 -0
  16. package/dist/extensions/constraint-registry.js +196 -0
  17. package/dist/extensions/index.d.ts +12 -0
  18. package/dist/extensions/index.js +6 -0
  19. package/dist/extensions/metric-registry.d.ts +26 -0
  20. package/dist/extensions/metric-registry.js +257 -0
  21. package/dist/extensions/mode-evaluator.d.ts +15 -0
  22. package/dist/extensions/mode-evaluator.js +170 -0
  23. package/dist/extensions/modes.d.ts +2 -0
  24. package/dist/extensions/modes.js +493 -0
  25. package/dist/extensions/registry.d.ts +50 -0
  26. package/dist/extensions/registry.js +662 -0
  27. package/dist/extensions/types.d.ts +219 -0
  28. package/dist/extensions/types.js +1 -0
  29. package/dist/index.js +50 -0
  30. package/dist/knowledge/deployment-scanner.d.ts +3 -0
  31. package/dist/knowledge/deployment-scanner.js +64 -3
  32. package/dist/knowledge/fund-layer.d.ts +72 -0
  33. package/dist/knowledge/fund-layer.js +420 -0
  34. package/dist/knowledge/guard-render.d.ts +57 -0
  35. package/dist/knowledge/guard-render.js +700 -0
  36. package/dist/knowledge/guard-risk.d.ts +13 -0
  37. package/dist/knowledge/guard-risk.js +57 -0
  38. package/dist/knowledge/guard-submission-prompt.d.ts +31 -0
  39. package/dist/knowledge/guard-submission-prompt.js +171 -0
  40. package/dist/knowledge/guard-templates.js +278 -0
  41. package/dist/knowledge/machine-ledger.js +1 -1
  42. package/dist/knowledge/machine-render.d.ts +41 -0
  43. package/dist/knowledge/machine-render.js +565 -0
  44. package/dist/knowledge/machine-templates.js +24 -5
  45. package/dist/knowledge/reward-confirm.js +2 -2
  46. package/dist/knowledge/reward-puzzle.js +1 -1
  47. package/dist/knowledge/reward-risk.js +9 -9
  48. package/dist/knowledge/reward-templates.js +2 -2
  49. package/dist/knowledge/service-confirm.d.ts +15 -6
  50. package/dist/knowledge/service-confirm.js +119 -11
  51. package/dist/knowledge/service-context.js +1 -1
  52. package/dist/knowledge/service-ledger.js +1 -1
  53. package/dist/knowledge/service-risk.d.ts +1 -1
  54. package/dist/knowledge/service-risk.js +3 -3
  55. package/dist/knowledge/service-templates.js +2 -2
  56. package/dist/knowledge/service-translation.d.ts +1 -1
  57. package/dist/knowledge/service-translation.js +7 -7
  58. package/dist/knowledge/tool-constraints.js +6 -2
  59. package/dist/project/deployment-bridge.d.ts +1 -1
  60. package/dist/project/deployment-bridge.js +31 -7
  61. package/dist/project/deployment-doc.d.ts +3 -0
  62. package/dist/project/deployment-doc.js +76 -14
  63. package/dist/project/edit-planner.d.ts +123 -0
  64. package/dist/project/edit-planner.js +1371 -0
  65. package/dist/project/evaluation.d.ts +2 -0
  66. package/dist/project/evaluation.js +873 -88
  67. package/dist/project/graph-builder.d.ts +4 -1
  68. package/dist/project/graph-builder.js +132 -62
  69. package/dist/project/graph.d.ts +1 -0
  70. package/dist/project/handlers.d.ts +317 -6
  71. package/dist/project/handlers.js +1171 -19
  72. package/dist/project/stage-gate.d.ts +4 -0
  73. package/dist/project/stage-gate.js +64 -5
  74. package/dist/project/task-tracker.d.ts +26 -0
  75. package/dist/project/task-tracker.js +78 -0
  76. package/dist/safety/preview.js +16 -0
  77. package/dist/schema/call/allocation.d.ts +16 -16
  78. package/dist/schema/call/allocation.js +2 -2
  79. package/dist/schema/call/arbitration.js +19 -6
  80. package/dist/schema/call/base.d.ts +21 -13
  81. package/dist/schema/call/base.js +27 -6
  82. package/dist/schema/call/bridge.d.ts +5 -5
  83. package/dist/schema/call/bridge.js +3 -1
  84. package/dist/schema/call/contact.js +2 -2
  85. package/dist/schema/call/demand.d.ts +23 -31
  86. package/dist/schema/call/demand.js +2 -2
  87. package/dist/schema/call/guard.js +2 -2
  88. package/dist/schema/call/machine.d.ts +1976 -752
  89. package/dist/schema/call/machine.js +50 -4
  90. package/dist/schema/call/order.d.ts +149 -228
  91. package/dist/schema/call/order.js +4 -3
  92. package/dist/schema/call/payment.d.ts +183 -3
  93. package/dist/schema/call/payment.js +21 -3
  94. package/dist/schema/call/permission.js +2 -2
  95. package/dist/schema/call/personal.d.ts +241 -52
  96. package/dist/schema/call/progress.d.ts +53 -61
  97. package/dist/schema/call/progress.js +18 -4
  98. package/dist/schema/call/repository.d.ts +23 -31
  99. package/dist/schema/call/repository.js +2 -2
  100. package/dist/schema/call/reward.js +3 -3
  101. package/dist/schema/call/semantic.d.ts +1 -1
  102. package/dist/schema/call/semantic.js +37 -2
  103. package/dist/schema/call/service.d.ts +275 -127
  104. package/dist/schema/call/service.js +89 -13
  105. package/dist/schema/call/treasury.js +3 -3
  106. package/dist/schema/common/index.d.ts +13 -2
  107. package/dist/schema/common/index.js +80 -15
  108. package/dist/schema/local/index.d.ts +32 -35
  109. package/dist/schema/local/index.js +28 -6
  110. package/dist/schema/messenger/index.d.ts +274 -46
  111. package/dist/schema/operations.d.ts +1264 -544
  112. package/dist/schema/operations.js +65 -7
  113. package/dist/schema/project/index.d.ts +2846 -167
  114. package/dist/schema/project/index.js +570 -16
  115. package/dist/schema/query/index.d.ts +922 -349
  116. package/dist/schema/query/index.js +205 -42
  117. package/dist/schema/schema-query/index.d.ts +65 -3
  118. package/dist/schema/schema-query/index.js +38 -5
  119. package/dist/schema/utils/node-parser.js +20 -4
  120. package/dist/schema/utils/object-type-utils.d.ts +12 -0
  121. package/dist/schema/utils/object-type-utils.js +35 -0
  122. package/dist/schema/utils/permission-machine-check.d.ts +49 -0
  123. package/dist/schema/utils/permission-machine-check.js +121 -0
  124. package/dist/schema/utils/skills-recommendation.d.ts +2 -0
  125. package/dist/schema/utils/skills-recommendation.js +76 -0
  126. package/dist/schema-query/index.d.ts +20 -1
  127. package/dist/schema-query/index.js +306 -4
  128. package/dist/schemas/account_operation.output.json +7 -1
  129. package/dist/schemas/account_operation.schema.json +3 -3
  130. package/dist/schemas/bridge_operation.output.json +6 -0
  131. package/dist/schemas/bridge_operation.schema.json +1 -1
  132. package/dist/schemas/guard-templates.json +379 -0
  133. package/dist/schemas/guard2file.schema.json +1 -1
  134. package/dist/schemas/index.json +1 -1
  135. package/dist/schemas/local_info_operation.output.json +6 -0
  136. package/dist/schemas/local_mark_operation.output.json +7 -1
  137. package/dist/schemas/local_mark_operation.schema.json +1 -1
  138. package/dist/schemas/machineNode2file.schema.json +1 -1
  139. package/dist/schemas/messenger_operation.schema.json +4 -4
  140. package/dist/schemas/onchain_events.output.json +1 -1
  141. package/dist/schemas/onchain_operations.output.json +2820 -0
  142. package/dist/schemas/onchain_operations.schema.json +444 -330
  143. package/dist/schemas/onchain_operations_allocation.schema.json +37 -28
  144. package/dist/schemas/onchain_operations_arbitration.schema.json +16 -14
  145. package/dist/schemas/onchain_operations_contact.schema.json +10 -10
  146. package/dist/schemas/onchain_operations_demand.schema.json +10 -10
  147. package/dist/schemas/onchain_operations_gen_passport.schema.json +16 -16
  148. package/dist/schemas/onchain_operations_gen_proof.schema.json +2 -2
  149. package/dist/schemas/onchain_operations_guard.schema.json +2 -2
  150. package/dist/schemas/onchain_operations_machine.schema.json +43 -35
  151. package/dist/schemas/onchain_operations_order.schema.json +72 -78
  152. package/dist/schemas/onchain_operations_payment.schema.json +141 -111
  153. package/dist/schemas/onchain_operations_permission.schema.json +3 -3
  154. package/dist/schemas/onchain_operations_personal.schema.json +7 -7
  155. package/dist/schemas/onchain_operations_progress.schema.json +9 -9
  156. package/dist/schemas/onchain_operations_proof.schema.json +8 -8
  157. package/dist/schemas/onchain_operations_repository.schema.json +10 -10
  158. package/dist/schemas/onchain_operations_reward.schema.json +14 -14
  159. package/dist/schemas/onchain_operations_service.schema.json +119 -48
  160. package/dist/schemas/onchain_operations_treasury.schema.json +11 -11
  161. package/dist/schemas/onchain_table_data.output.json +33 -25
  162. package/dist/schemas/onchain_table_data.schema.json +22 -21
  163. package/dist/schemas/project_operation.output.json +2194 -23
  164. package/dist/schemas/project_operation.schema.json +84 -6
  165. package/dist/schemas/query_toolkit.output.json +108 -80
  166. package/dist/schemas/query_toolkit.schema.json +12 -12
  167. package/dist/schemas/schema_query.output.json +70 -3
  168. package/dist/schemas/schema_query.schema.json +18 -3
  169. package/dist/schemas/wowok_buildin_info.output.json +81 -8
  170. package/dist/schemas/wowok_buildin_info.schema.json +46 -2
  171. package/dist/tools/handlers/local.js +20 -5
  172. package/dist/tools/handlers/onchain.js +594 -6
  173. package/dist/tools/handlers/project.js +76 -4
  174. package/dist/tools/handlers/query.js +27 -0
  175. package/dist/tools/handlers/schema-query.js +43 -1
  176. package/dist/tools/handlers/task-status.d.ts +170 -0
  177. package/dist/tools/handlers/task-status.js +55 -0
  178. package/dist/tools/handlers/wip.js +47 -1
  179. package/dist/tools/index.d.ts +8 -0
  180. package/dist/tools/index.js +387 -12
  181. package/dist/tools/retry.d.ts +8 -0
  182. package/dist/tools/retry.js +85 -0
  183. package/dist/tools/wip-deploy-assist.d.ts +28 -0
  184. package/dist/tools/wip-deploy-assist.js +278 -0
  185. package/package.json +2 -2
  186. package/dist/schemas/guard-node-examples.md +0 -199
@@ -1,4 +1,7 @@
1
- import { type GraphData } from "@wowok/wowok";
1
+ import { type GraphData, type GraphNode } from "@wowok/wowok";
2
+ export type GraphNodeWithTemplate = GraphNode & {
3
+ isTemplate?: boolean;
4
+ };
2
5
  export interface GraphBuildOptions {
3
6
  maxDepth?: number;
4
7
  maxConcurrency?: number;
@@ -9,7 +9,12 @@ function shortTypeName(objectType) {
9
9
  }
10
10
  function extractAddressFields(obj) {
11
11
  const refs = [];
12
- const objType = obj.type;
12
+ const rawType = obj.type;
13
+ let objType = rawType;
14
+ if (rawType && rawType.includes("::")) {
15
+ const parts = rawType.split("::");
16
+ objType = parts[parts.length - 1];
17
+ }
13
18
  const isAddress = (v) => typeof v === "string" && v.startsWith("0x") && v.length >= 10;
14
19
  const addRef = (addr, field, refType) => {
15
20
  if (isAddress(addr) && addr !== "0x0" && addr !== obj.object) {
@@ -45,46 +50,86 @@ function extractAddressFields(obj) {
45
50
  const firstGuard = data.order_allocators.allocators[0]?.guard;
46
51
  addRef(firstGuard, "order_allocators", "create");
47
52
  }
48
- addRefOption(data.compensation_fund, "compensation_fund", "bind");
49
53
  break;
50
54
  }
51
55
  case "Machine": {
52
56
  addRef(data.permission, "permission", "validate");
53
- addRefArray(data.repositories, "repositories", "consume");
54
- if (data.nodes) {
55
- for (const node of data.nodes) {
56
- if (node.forward?.guard) {
57
- addRef(node.forward.guard, "node_guard", "validate");
58
- }
59
- }
60
- }
57
+ addRefArray(data.consensus_repositories, "consensus_repositories", "consume");
61
58
  break;
62
59
  }
63
60
  case "Order": {
64
61
  addRef(data.service, "service", "consume");
65
62
  addRefOption(data.machine, "machine", "consume");
66
63
  addRefOption(data.progress, "progress", "trigger");
67
- addRefOption(data.arbitration, "arbitration", "trigger");
64
+ addRefArray(data.dispute, "dispute", "trigger");
65
+ addRefOption(data.allocation, "allocation", "bind");
68
66
  break;
69
67
  }
70
68
  case "Progress": {
71
69
  addRef(data.machine, "machine", "bind");
72
- addRefOption(data.parent, "parent", "bind");
73
- addRefOption(data.order, "order", "bind");
70
+ addRefArray(data.context_repositories, "context_repositories", "consume");
74
71
  break;
75
72
  }
76
73
  case "Treasury": {
77
74
  addRef(data.permission, "permission", "validate");
78
- addRefOption(data.guard, "guard", "validate");
75
+ if (Array.isArray(data.external_deposit_guard)) {
76
+ for (const g of data.external_deposit_guard)
77
+ addRef(g?.guard, "external_deposit_guard", "validate");
78
+ }
79
+ if (Array.isArray(data.external_withdraw_guard)) {
80
+ for (const g of data.external_withdraw_guard)
81
+ addRef(g?.guard, "external_withdraw_guard", "validate");
82
+ }
83
+ break;
84
+ }
85
+ case "Allocation": {
86
+ if (Array.isArray(data.allocators)) {
87
+ for (const alloc of data.allocators)
88
+ addRef(alloc?.guard, "allocator_guard", "validate");
89
+ }
90
+ addRefOption(data.payment_info?.for_object, "for_object", "bind");
91
+ addRefOption(data.payment_info?.for_guard, "for_guard", "validate");
92
+ addRefArray(data.payment, "payment", "trigger");
93
+ break;
94
+ }
95
+ case "Arbitration": {
96
+ addRef(data.permission, "permission", "validate");
97
+ if (Array.isArray(data.voting_guard)) {
98
+ for (const vg of data.voting_guard)
99
+ addRef(vg?.guard, "voting_guard", "validate");
100
+ }
101
+ addRefOption(data.usage_guard, "usage_guard", "validate");
102
+ break;
103
+ }
104
+ case "Reward": {
105
+ addRef(data.permission, "permission", "validate");
106
+ if (Array.isArray(data.guards)) {
107
+ for (const rg of data.guards)
108
+ addRef(rg?.guard, "guard", "validate");
109
+ }
110
+ break;
111
+ }
112
+ case "Repository": {
113
+ addRef(data.permission, "permission", "validate");
114
+ addRefArray(data.rewards, "rewards", "trigger");
115
+ if (Array.isArray(data.policies)) {
116
+ for (const policy of data.policies) {
117
+ if (Array.isArray(policy?.write_guard)) {
118
+ for (const wg of policy.write_guard)
119
+ addRef(wg?.guard, "write_guard", "validate");
120
+ }
121
+ addRefOption(policy?.quote_guard, "quote_guard", "validate");
122
+ }
123
+ }
79
124
  break;
80
125
  }
81
- case "Allocation":
82
- case "Arbitration":
83
- case "Reward":
84
- case "Repository":
85
126
  case "Demand": {
86
127
  addRef(data.permission, "permission", "validate");
87
- addRefOption(data.guard, "guard", "validate");
128
+ if (Array.isArray(data.guards)) {
129
+ for (const dg of data.guards)
130
+ addRef(dg?.guard, "guard", "validate");
131
+ }
132
+ addRefArray(data.rewards, "rewards", "trigger");
88
133
  break;
89
134
  }
90
135
  case "Contact": {
@@ -95,9 +140,16 @@ function extractAddressFields(obj) {
95
140
  break;
96
141
  }
97
142
  case "Payment": {
98
- addRefOption(data.for_object, "for_object", "bind");
99
- addRefOption(data.for_guard, "for_guard", "validate");
100
- addRefArray(data.recipients, "recipients", "consume");
143
+ addRefOption(data.info?.for_object, "for_object", "bind");
144
+ addRefOption(data.info?.for_guard, "for_guard", "validate");
145
+ if (Array.isArray(data.record)) {
146
+ for (const r of data.record) {
147
+ const rec = r?.recipient;
148
+ if (rec && typeof rec === "object" && typeof rec.Entity === "string") {
149
+ addRef(rec.Entity, "recipient_entity", "consume");
150
+ }
151
+ }
152
+ }
101
153
  break;
102
154
  }
103
155
  case "Guard": {
@@ -165,53 +217,71 @@ const EXPECTED_RELATIONSHIPS = new Map([
165
217
  { targetType: "Machine", fieldName: "machine", relationshipType: "bind", single: true },
166
218
  { targetType: "Guard", fieldName: "buy_guard", relationshipType: "validate", single: true },
167
219
  { targetType: "Permission", fieldName: "permission", relationshipType: "validate", single: true },
168
- { targetType: "Allocation", fieldName: "order_allocators", relationshipType: "create" },
169
- { targetType: "Treasury", fieldName: "compensation_fund", relationshipType: "bind", single: true },
220
+ { targetType: "Guard", fieldName: "allocator_guard", relationshipType: "validate" },
221
+ { targetType: "Contact", fieldName: "um", relationshipType: "bind", single: true },
170
222
  { targetType: "Arbitration", fieldName: "arbitrations", relationshipType: "trigger" },
171
223
  { targetType: "Reward", fieldName: "rewards", relationshipType: "trigger" },
172
224
  { targetType: "Repository", fieldName: "repositories", relationshipType: "consume" },
173
225
  ]],
174
226
  ["Machine", [
175
- { targetType: "Guard", fieldName: "nodes.guard", relationshipType: "validate" },
176
227
  { targetType: "Permission", fieldName: "permission", relationshipType: "validate", single: true },
177
- { targetType: "Repository", fieldName: "repositories", relationshipType: "consume" },
228
+ { targetType: "Repository", fieldName: "consensus_repositories", relationshipType: "consume" },
229
+ { targetType: "Contact", fieldName: "um", relationshipType: "bind", single: true },
178
230
  ]],
179
231
  ["Order", [
180
232
  { targetType: "Service", fieldName: "service", relationshipType: "consume", single: true },
233
+ { targetType: "Machine", fieldName: "machine", relationshipType: "consume", single: true },
181
234
  { targetType: "Progress", fieldName: "progress", relationshipType: "trigger", single: true },
235
+ { targetType: "Arb", fieldName: "dispute", relationshipType: "trigger" },
236
+ { targetType: "Allocation", fieldName: "allocation", relationshipType: "bind", single: true },
182
237
  ]],
183
238
  ["Progress", [
184
- { targetType: "Machine", fieldName: "parent", relationshipType: "bind", single: true },
185
239
  { targetType: "Machine", fieldName: "machine", relationshipType: "bind", single: true },
240
+ { targetType: "Repository", fieldName: "context_repositories", relationshipType: "consume" },
186
241
  ]],
187
242
  ["Allocation", [
188
- { targetType: "Treasury", fieldName: "treasury", relationshipType: "consume", single: true },
189
- { targetType: "Guard", fieldName: "guard", relationshipType: "validate", single: true },
243
+ { targetType: "Guard", fieldName: "allocator_guard", relationshipType: "validate" },
244
+ { targetType: "Guard", fieldName: "for_guard", relationshipType: "validate", single: true },
245
+ { targetType: "Payment", fieldName: "payment", relationshipType: "trigger" },
190
246
  ]],
191
247
  ["Reward", [
192
- { targetType: "Guard", fieldName: "guard", relationshipType: "validate", single: true },
248
+ { targetType: "Guard", fieldName: "guard", relationshipType: "validate" },
193
249
  { targetType: "Permission", fieldName: "permission", relationshipType: "validate", single: true },
250
+ { targetType: "Contact", fieldName: "um", relationshipType: "bind", single: true },
194
251
  ]],
195
252
  ["Repository", [
196
- { targetType: "Guard", fieldName: "guard", relationshipType: "validate", single: true },
253
+ { targetType: "Guard", fieldName: "write_guard", relationshipType: "validate" },
254
+ { targetType: "Guard", fieldName: "quote_guard", relationshipType: "validate", single: true },
197
255
  { targetType: "Permission", fieldName: "permission", relationshipType: "validate", single: true },
256
+ { targetType: "Reward", fieldName: "rewards", relationshipType: "trigger" },
257
+ { targetType: "Contact", fieldName: "um", relationshipType: "bind", single: true },
198
258
  ]],
199
259
  ["Demand", [
200
- { targetType: "Service", fieldName: "service", relationshipType: "consume", single: true },
201
- { targetType: "Guard", fieldName: "guards", relationshipType: "validate" },
260
+ { targetType: "Guard", fieldName: "guard", relationshipType: "validate" },
202
261
  { targetType: "Reward", fieldName: "rewards", relationshipType: "trigger" },
262
+ { targetType: "Contact", fieldName: "um", relationshipType: "bind", single: true },
203
263
  ]],
204
264
  ["Treasury", [
205
265
  { targetType: "Permission", fieldName: "permission", relationshipType: "validate", single: true },
206
- { targetType: "Guard", fieldName: "guard", relationshipType: "validate", single: true },
266
+ { targetType: "Guard", fieldName: "external_deposit_guard", relationshipType: "validate" },
267
+ { targetType: "Guard", fieldName: "external_withdraw_guard", relationshipType: "validate" },
268
+ { targetType: "Contact", fieldName: "um", relationshipType: "bind", single: true },
207
269
  ]],
208
270
  ["Arbitration", [
209
271
  { targetType: "Permission", fieldName: "permission", relationshipType: "validate", single: true },
210
- { targetType: "Guard", fieldName: "guard", relationshipType: "validate", single: true },
272
+ { targetType: "Guard", fieldName: "voting_guard", relationshipType: "validate" },
273
+ { targetType: "Guard", fieldName: "usage_guard", relationshipType: "validate", single: true },
274
+ { targetType: "Contact", fieldName: "um", relationshipType: "bind", single: true },
211
275
  ]],
212
276
  ["Payment", [
213
277
  { targetType: "Guard", fieldName: "for_guard", relationshipType: "validate", single: true },
214
278
  ]],
279
+ ["Contact", [
280
+ { targetType: "Permission", fieldName: "permission", relationshipType: "validate", single: true },
281
+ ]],
282
+ ["Permission", [
283
+ { targetType: "Contact", fieldName: "um", relationshipType: "bind", single: true },
284
+ ]],
215
285
  ]);
216
286
  export class GraphBuilder {
217
287
  localProject;
@@ -478,33 +548,31 @@ export class GraphBuilder {
478
548
  const fieldKey = `${source.address}#${expected.fieldName}`;
479
549
  const existingBindings = sourceFieldBindings.get(fieldKey);
480
550
  const hasOtherBinding = existingBindings !== undefined && existingBindings.size > 0;
481
- for (const target of targets) {
482
- if (source.address === target.address)
483
- continue;
484
- const pairKey = `${source.address}→${target.address}`;
485
- if (existingPairs.has(pairKey))
486
- continue;
487
- if (existingBindings?.has(target.address))
488
- continue;
489
- potentialEdges.push({
490
- sourceObject: source.address,
491
- targetObject: target.address,
492
- edgeSource: "potential",
493
- relationshipType: expected.relationshipType,
494
- fieldName: expected.fieldName,
495
- depth: 0,
496
- verified: false,
497
- weight: hasOtherBinding ? 0.3 : 0.6,
498
- direction: "outbound",
499
- metadata: {
500
- reason: hasOtherBinding
501
- ? "field_already_bound_to_other"
502
- : "expected_relationship_missing",
503
- expected_target_type: expected.targetType,
504
- source_object_name: source.name,
505
- },
506
- });
507
- }
551
+ if (hasOtherBinding)
552
+ continue;
553
+ const representativeTarget = targets.find((t) => t.address !== source.address &&
554
+ !existingPairs.has(`${source.address}→${t.address}`) &&
555
+ !existingBindings?.has(t.address));
556
+ if (!representativeTarget)
557
+ continue;
558
+ potentialEdges.push({
559
+ sourceObject: source.address,
560
+ targetObject: representativeTarget.address,
561
+ edgeSource: "potential",
562
+ relationshipType: expected.relationshipType,
563
+ fieldName: expected.fieldName,
564
+ depth: 0,
565
+ verified: false,
566
+ weight: 0.6,
567
+ direction: "outbound",
568
+ metadata: {
569
+ reason: "expected_relationship_missing",
570
+ expected_target_type: expected.targetType,
571
+ source_object_name: source.name,
572
+ representative: true,
573
+ alternative_target_count: targets.length - 1,
574
+ },
575
+ });
508
576
  }
509
577
  }
510
578
  }
@@ -554,12 +622,14 @@ export class GraphBuilder {
554
622
  const obj = objectCache.get(addr);
555
623
  const queryName = obj?.query_name;
556
624
  const objectName = queryName && queryName !== addr ? queryName : null;
625
+ const isTemplate = addr.startsWith("draft:");
557
626
  nodeMap.set(addr, {
558
627
  address: addr,
559
628
  objectType: obj?.type ?? null,
560
629
  objectName,
561
630
  role: null,
562
631
  isCore: addr === rootAddress,
632
+ isTemplate,
563
633
  });
564
634
  }
565
635
  return nodeMap.get(addr);
@@ -6,6 +6,7 @@ export interface GraphNode {
6
6
  projects?: string[];
7
7
  type?: ProjectObjectType;
8
8
  address?: string;
9
+ isTemplate?: boolean;
9
10
  decision_contexts?: GraphDecisionContext[];
10
11
  }
11
12
  export interface GraphDecisionContext {