@wowok/agent-mcp 2.3.14 → 2.3.18

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 (189) 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/index.d.ts +9 -0
  6. package/dist/customer/index.js +9 -0
  7. package/dist/customer/industry-risks.d.ts +40 -0
  8. package/dist/customer/industry-risks.js +438 -0
  9. package/dist/customer/info-puzzle.d.ts +102 -0
  10. package/dist/customer/info-puzzle.js +312 -0
  11. package/dist/customer/order-monitor.d.ts +75 -0
  12. package/dist/customer/order-monitor.js +327 -0
  13. package/dist/customer/order-strategy.d.ts +36 -0
  14. package/dist/customer/order-strategy.js +373 -0
  15. package/dist/customer/post-purchase.d.ts +42 -0
  16. package/dist/customer/post-purchase.js +350 -0
  17. package/dist/customer/reminder-system.d.ts +42 -0
  18. package/dist/customer/reminder-system.js +295 -0
  19. package/dist/customer/risk-assessment.d.ts +8 -0
  20. package/dist/customer/risk-assessment.js +337 -0
  21. package/dist/customer/types.d.ts +193 -0
  22. package/dist/customer/types.js +13 -0
  23. package/dist/customer/user-preferences.d.ts +70 -0
  24. package/dist/customer/user-preferences.js +460 -0
  25. package/dist/experience/experience-reuse.d.ts +10 -0
  26. package/dist/experience/experience-reuse.js +103 -0
  27. package/dist/experience/index.d.ts +6 -0
  28. package/dist/experience/index.js +5 -0
  29. package/dist/experience/intent-distill.d.ts +3 -0
  30. package/dist/experience/intent-distill.js +83 -0
  31. package/dist/experience/realtime-feedback.d.ts +5 -0
  32. package/dist/experience/realtime-feedback.js +94 -0
  33. package/dist/experience/types.d.ts +50 -0
  34. package/dist/experience/types.js +1 -0
  35. package/dist/experience/user-profile.d.ts +25 -0
  36. package/dist/experience/user-profile.js +171 -0
  37. package/dist/index.js +842 -371
  38. package/dist/knowledge/acquisition-flywheel.d.ts +53 -0
  39. package/dist/knowledge/acquisition-flywheel.js +192 -0
  40. package/dist/knowledge/arbitration-trust.d.ts +24 -0
  41. package/dist/knowledge/arbitration-trust.js +117 -0
  42. package/dist/knowledge/audit-rules.d.ts +28 -0
  43. package/dist/knowledge/audit-rules.js +141 -0
  44. package/dist/knowledge/demand-matching.d.ts +29 -0
  45. package/dist/knowledge/demand-matching.js +132 -0
  46. package/dist/knowledge/dynamic-pricing.d.ts +31 -0
  47. package/dist/knowledge/dynamic-pricing.js +87 -0
  48. package/dist/knowledge/flywheel-loop.d.ts +87 -0
  49. package/dist/knowledge/flywheel-loop.js +378 -0
  50. package/dist/knowledge/glossary.d.ts +18 -0
  51. package/dist/knowledge/glossary.js +209 -0
  52. package/dist/knowledge/guard-ledger.d.ts +19 -0
  53. package/dist/knowledge/guard-ledger.js +219 -0
  54. package/dist/knowledge/guard-puzzle.d.ts +93 -0
  55. package/dist/knowledge/guard-puzzle.js +278 -0
  56. package/dist/knowledge/guard-risk.d.ts +60 -0
  57. package/dist/knowledge/guard-risk.js +474 -0
  58. package/dist/knowledge/guard-translation.d.ts +46 -0
  59. package/dist/knowledge/guard-translation.js +487 -0
  60. package/dist/knowledge/index.d.ts +77 -0
  61. package/dist/knowledge/index.js +79 -0
  62. package/dist/knowledge/industry-evolution.d.ts +82 -0
  63. package/dist/knowledge/industry-evolution.js +323 -0
  64. package/dist/knowledge/industry-generalizer.d.ts +17 -0
  65. package/dist/knowledge/industry-generalizer.js +381 -0
  66. package/dist/knowledge/industry-registry.d.ts +48 -0
  67. package/dist/knowledge/industry-registry.js +187 -0
  68. package/dist/knowledge/intent-metrics.d.ts +42 -0
  69. package/dist/knowledge/intent-metrics.js +566 -0
  70. package/dist/knowledge/process-model.d.ts +24 -0
  71. package/dist/knowledge/process-model.js +160 -0
  72. package/dist/knowledge/reputation-rules.d.ts +42 -0
  73. package/dist/knowledge/reputation-rules.js +99 -0
  74. package/dist/knowledge/reward-templates.d.ts +25 -0
  75. package/dist/knowledge/reward-templates.js +125 -0
  76. package/dist/knowledge/safety-rules.d.ts +36 -0
  77. package/dist/knowledge/safety-rules.js +232 -0
  78. package/dist/knowledge/tool-constraints.d.ts +30 -0
  79. package/dist/knowledge/tool-constraints.js +175 -0
  80. package/dist/knowledge/trust-metrics.d.ts +37 -0
  81. package/dist/knowledge/trust-metrics.js +138 -0
  82. package/dist/loop-engineering/diagnose.d.ts +3 -2
  83. package/dist/loop-engineering/diagnose.js +94 -0
  84. package/dist/loop-engineering/improve.d.ts +1 -1
  85. package/dist/loop-engineering/improve.js +52 -1
  86. package/dist/project/graph.d.ts +71 -0
  87. package/dist/project/graph.js +314 -0
  88. package/dist/project/index.d.ts +62 -0
  89. package/dist/project/index.js +167 -0
  90. package/dist/project/namespace.d.ts +62 -0
  91. package/dist/project/namespace.js +181 -0
  92. package/dist/project/query.d.ts +40 -0
  93. package/dist/project/query.js +110 -0
  94. package/dist/safety/confirm-gate.d.ts +17 -0
  95. package/dist/safety/confirm-gate.js +88 -0
  96. package/dist/safety/index.d.ts +3 -0
  97. package/dist/safety/index.js +3 -0
  98. package/dist/safety/preview.d.ts +2 -0
  99. package/dist/safety/preview.js +36 -0
  100. package/dist/schema/call/allocation.d.ts +39 -14
  101. package/dist/schema/call/arbitration.d.ts +187 -162
  102. package/dist/schema/call/base.d.ts +1971 -87
  103. package/dist/schema/call/base.js +135 -3
  104. package/dist/schema/call/bridge-handler.js +15 -2
  105. package/dist/schema/call/bridge.d.ts +1478 -53
  106. package/dist/schema/call/bridge.js +50 -2
  107. package/dist/schema/call/contact.d.ts +25 -0
  108. package/dist/schema/call/demand.d.ts +79 -54
  109. package/dist/schema/call/guard.d.ts +125 -50
  110. package/dist/schema/call/handler.d.ts +3 -0
  111. package/dist/schema/call/handler.js +60 -14
  112. package/dist/schema/call/machine.d.ts +988 -938
  113. package/dist/schema/call/order.d.ts +25 -0
  114. package/dist/schema/call/payment.d.ts +25 -0
  115. package/dist/schema/call/permission.d.ts +244 -219
  116. package/dist/schema/call/personal.d.ts +25 -0
  117. package/dist/schema/call/progress.d.ts +25 -0
  118. package/dist/schema/call/proof.d.ts +62 -12
  119. package/dist/schema/call/proof.js +3 -3
  120. package/dist/schema/call/repository.d.ts +101 -76
  121. package/dist/schema/call/reward.d.ts +55 -30
  122. package/dist/schema/call/semantic.d.ts +10 -2
  123. package/dist/schema/call/semantic.js +616 -11
  124. package/dist/schema/call/service.d.ts +442 -417
  125. package/dist/schema/call/treasury.d.ts +25 -0
  126. package/dist/schema/common/index.js +3 -3
  127. package/dist/schema/config/index.d.ts +18 -0
  128. package/dist/schema/config/index.js +17 -0
  129. package/dist/schema/index.d.ts +6 -0
  130. package/dist/schema/index.js +5 -0
  131. package/dist/schema/local/index.d.ts +237 -81
  132. package/dist/schema/local/index.js +42 -6
  133. package/dist/schema/messenger/index.d.ts +1018 -79
  134. package/dist/schema/messenger/index.js +26 -17
  135. package/dist/schema/operations.d.ts +3192 -1746
  136. package/dist/schema/operations.js +93 -98
  137. package/dist/schema/project/index.d.ts +21 -0
  138. package/dist/schema/project/index.js +32 -0
  139. package/dist/schema/query/index.d.ts +2762 -1856
  140. package/dist/schema/query/index.js +38 -35
  141. package/dist/schema/schema-query/index.d.ts +33 -0
  142. package/dist/schema/schema-query/index.js +36 -0
  143. package/dist/schema/schema-version.d.ts +25 -0
  144. package/dist/schema/schema-version.js +76 -0
  145. package/dist/schema/trust/index.d.ts +407 -0
  146. package/dist/schema/trust/index.js +113 -0
  147. package/dist/schemas/account_operation.output.json +25 -16
  148. package/dist/schemas/account_operation.schema.json +1 -1
  149. package/dist/schemas/bridge_operation.output.json +744 -0
  150. package/dist/schemas/bridge_operation.schema.json +82 -8
  151. package/dist/schemas/config_operation.output.json +18 -0
  152. package/dist/schemas/config_operation.schema.json +34 -0
  153. package/dist/schemas/guard-node-schema.json +82 -0
  154. package/dist/schemas/guard2file.schema.json +23 -0
  155. package/dist/schemas/index.json +19 -1
  156. package/dist/schemas/local_info_operation.output.json +23 -0
  157. package/dist/schemas/local_info_operation.schema.json +1 -1
  158. package/dist/schemas/local_mark_operation.output.json +24 -1
  159. package/dist/schemas/local_mark_operation.schema.json +4 -4
  160. package/dist/schemas/machineNode2file.schema.json +23 -0
  161. package/dist/schemas/messenger_operation.output.json +752 -0
  162. package/dist/schemas/onchain_events.output.json +718 -0
  163. package/dist/schemas/onchain_operations.output.json +627 -18
  164. package/dist/schemas/onchain_operations.schema.json +115 -39
  165. package/dist/schemas/onchain_operations_allocation.schema.json +23 -0
  166. package/dist/schemas/onchain_operations_arbitration.schema.json +23 -0
  167. package/dist/schemas/onchain_operations_contact.schema.json +23 -0
  168. package/dist/schemas/onchain_operations_demand.schema.json +23 -0
  169. package/dist/schemas/onchain_operations_gen_passport.schema.json +46 -0
  170. package/dist/schemas/onchain_operations_guard.schema.json +26 -16
  171. package/dist/schemas/onchain_operations_machine.schema.json +89 -23
  172. package/dist/schemas/onchain_operations_order.schema.json +23 -0
  173. package/dist/schemas/onchain_operations_payment.schema.json +23 -0
  174. package/dist/schemas/onchain_operations_permission.schema.json +23 -0
  175. package/dist/schemas/onchain_operations_personal.schema.json +23 -0
  176. package/dist/schemas/onchain_operations_progress.schema.json +23 -0
  177. package/dist/schemas/onchain_operations_repository.schema.json +23 -0
  178. package/dist/schemas/onchain_operations_reward.schema.json +23 -0
  179. package/dist/schemas/onchain_operations_service.schema.json +23 -0
  180. package/dist/schemas/onchain_operations_treasury.schema.json +23 -0
  181. package/dist/schemas/onchain_table_data.output.json +939 -69
  182. package/dist/schemas/onchain_table_data.schema.json +2 -2
  183. package/dist/schemas/project_operation.output.json +18 -0
  184. package/dist/schemas/project_operation.schema.json +42 -0
  185. package/dist/schemas/query_toolkit.schema.json +360 -368
  186. package/dist/schemas/schema_query.schema.json +6 -3
  187. package/dist/schemas/trust_score.output.json +327 -0
  188. package/dist/schemas/trust_score.schema.json +46 -0
  189. package/package.json +2 -2
@@ -0,0 +1,167 @@
1
+ import { normalizeForProject, extractProjectPrefix, TAG_PREFIX, } from "./namespace.js";
2
+ import { ProjectGraph, extractReferences, nodeIdOf, } from "./graph.js";
3
+ import { listProjects, listProjectObjects, listShareableObjects, traceDependencies, traceReferencedBy, prePublishCheck, findCrossProjectReferences, } from "./query.js";
4
+ import { isEnabled as isRuntimeEnabled } from "../config/index.js";
5
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
6
+ import { dirname, join } from "path";
7
+ import { homedir } from "os";
8
+ export * from "./namespace.js";
9
+ export * from "./graph.js";
10
+ export * from "./query.js";
11
+ export function isProjectServiceEnabled() {
12
+ return isRuntimeEnabled("project_service");
13
+ }
14
+ let GRAPH_INSTANCE = null;
15
+ let GRAPH_HYDRATED = false;
16
+ function isAutoHydrateEnabled() {
17
+ const v = process.env.WOWOK_PROJECT_SERVICE_HYDRATE;
18
+ return v === "1" || v === "true";
19
+ }
20
+ export function getGraph() {
21
+ if (!GRAPH_INSTANCE) {
22
+ GRAPH_INSTANCE = new ProjectGraph();
23
+ if (isAutoHydrateEnabled() && !GRAPH_HYDRATED) {
24
+ GRAPH_HYDRATED = true;
25
+ try {
26
+ loadGraph();
27
+ }
28
+ catch {
29
+ }
30
+ }
31
+ }
32
+ return GRAPH_INSTANCE;
33
+ }
34
+ export function setGraph(g) {
35
+ GRAPH_INSTANCE = g;
36
+ }
37
+ export function normalize(input) {
38
+ if (!isProjectServiceEnabled()) {
39
+ return { data: input.data, warnings: [] };
40
+ }
41
+ return normalizeForProject({
42
+ operation_type: input.operation_type,
43
+ data: input.data,
44
+ projectPrefix: input.projectPrefix,
45
+ role: input.role,
46
+ industry: input.industry,
47
+ version: input.version,
48
+ shareable: input.shareable,
49
+ });
50
+ }
51
+ export function observe(operation_type, data, result) {
52
+ if (!isProjectServiceEnabled())
53
+ return;
54
+ try {
55
+ const graph = getGraph();
56
+ const namedNew = data?.namedNew ?? data?.object;
57
+ const name = namedNew?.name;
58
+ const address = extractAddressFromResult(result);
59
+ const nodeId = nodeIdOf(name, address);
60
+ if (!nodeId)
61
+ return;
62
+ const tags = namedNew?.tags;
63
+ const project = extractProjectPrefix(tags);
64
+ const typeTag = tags?.find((t) => t.startsWith(TAG_PREFIX.type));
65
+ const type = typeTag?.slice(TAG_PREFIX.type.length);
66
+ const node = { id: nodeId, project, type, address };
67
+ graph.upsertNode(node);
68
+ const refs = extractReferences(operation_type, data);
69
+ for (const r of refs) {
70
+ graph.addEdge(nodeId, r.target, r.kind);
71
+ }
72
+ if (isRuntimeEnabled("graph_persist")) {
73
+ try {
74
+ saveGraph();
75
+ }
76
+ catch {
77
+ }
78
+ }
79
+ }
80
+ catch {
81
+ }
82
+ }
83
+ function extractAddressFromResult(result) {
84
+ if (!result || typeof result !== "object")
85
+ return undefined;
86
+ const candidate = result?.object_id ??
87
+ result?.objectId ??
88
+ result?.effects?.created?.[0]?.reference?.objectId ??
89
+ result?.objectRef?.objectId ??
90
+ result?.data?.objectId;
91
+ if (typeof candidate === "string" && candidate.startsWith("0x"))
92
+ return candidate;
93
+ const inner = result.result ?? result.data;
94
+ if (inner && typeof inner === "object") {
95
+ const c2 = inner.object_id ??
96
+ inner.objectId ??
97
+ inner.effects?.created?.[0]?.reference?.objectId ??
98
+ inner.objectRef?.objectId;
99
+ if (typeof c2 === "string" && c2.startsWith("0x"))
100
+ return c2;
101
+ }
102
+ return undefined;
103
+ }
104
+ export async function queryProjects() {
105
+ return listProjects();
106
+ }
107
+ export async function queryProjectObjects(prefix) {
108
+ return listProjectObjects(prefix);
109
+ }
110
+ export async function queryShareableObjects() {
111
+ return listShareableObjects();
112
+ }
113
+ export function queryDependencies(objectId) {
114
+ return traceDependencies(getGraph(), objectId);
115
+ }
116
+ export function queryReferencedBy(objectId) {
117
+ return traceReferencedBy(getGraph(), objectId);
118
+ }
119
+ export function queryPrePublishCheck(serviceId) {
120
+ return prePublishCheck(getGraph(), serviceId);
121
+ }
122
+ export function queryCrossProjectReferences() {
123
+ return findCrossProjectReferences(getGraph());
124
+ }
125
+ export function queryGraphStats() {
126
+ const g = getGraph();
127
+ return {
128
+ nodeCount: g.nodeCount,
129
+ edgeCount: g.edgeCount,
130
+ cycles: g.detectCycles(),
131
+ dangling: g.findDanglingDependencies(),
132
+ };
133
+ }
134
+ function graphFilePath() {
135
+ const dir = process.env.WOWOK_CONFIG_DIR
136
+ ? process.env.WOWOK_CONFIG_DIR
137
+ : join(homedir(), ".wowok");
138
+ return join(dir, "project-graph.json");
139
+ }
140
+ export function saveGraph() {
141
+ const path = graphFilePath();
142
+ const dir = dirname(path);
143
+ if (!existsSync(dir))
144
+ mkdirSync(dir, { recursive: true });
145
+ const snap = getGraph().snapshot();
146
+ writeFileSync(path, JSON.stringify(snap, null, 2), "utf-8");
147
+ return path;
148
+ }
149
+ export function loadGraph() {
150
+ const path = graphFilePath();
151
+ if (!existsSync(path))
152
+ return false;
153
+ try {
154
+ const raw = readFileSync(path, "utf-8");
155
+ const snap = JSON.parse(raw);
156
+ if (snap && snap.nodes && snap.edges) {
157
+ getGraph().restore(snap);
158
+ return true;
159
+ }
160
+ }
161
+ catch { }
162
+ return false;
163
+ }
164
+ export function hasPersistedGraph() {
165
+ return existsSync(graphFilePath());
166
+ }
167
+ export const PROJECT_SERVICE_VERSION = 1;
@@ -0,0 +1,62 @@
1
+ export type ProjectObjectType = "service" | "machine" | "guard" | "permission" | "reward" | "arb" | "progress" | "treasury" | "demand" | "repository" | "contact" | "order" | "allocation" | "personal" | "payment" | "proof";
2
+ export type ProjectRole = "workflow" | "trust" | "revenue" | "acceptance" | "identity" | "communication" | "marketing" | "governance";
3
+ export type IndustryMode = "freelance" | "rental" | "education" | "travel" | "subscription" | "general";
4
+ export declare const TAG_PREFIX: {
5
+ readonly project: "project:";
6
+ readonly type: "type:";
7
+ readonly role: "role:";
8
+ readonly industry: "industry:";
9
+ readonly version: "version:";
10
+ readonly shareable: "shareable:";
11
+ readonly archived: "archived:";
12
+ };
13
+ export declare const NAMESPACE_CONSTRAINTS: {
14
+ readonly projectPrefixMin: 3;
15
+ readonly projectPrefixMax: 16;
16
+ readonly purposeMin: 1;
17
+ readonly purposeMax: 32;
18
+ readonly versionPattern: RegExp;
19
+ };
20
+ export interface NameValidation {
21
+ valid: boolean;
22
+ reason?: string;
23
+ parsed?: {
24
+ projectPrefix: string;
25
+ type: ProjectObjectType;
26
+ purpose: string;
27
+ version?: string;
28
+ };
29
+ }
30
+ export declare function validateProjectName(name: string): NameValidation;
31
+ export declare function objectTypeFromOperation(operation_type: string): ProjectObjectType | undefined;
32
+ export interface TagInjectionOptions {
33
+ projectPrefix?: string;
34
+ type?: ProjectObjectType;
35
+ role?: ProjectRole;
36
+ industry?: IndustryMode;
37
+ version?: string;
38
+ shareable?: boolean;
39
+ existingTags?: string[];
40
+ }
41
+ export declare function buildProjectTags(opts: TagInjectionOptions): string[];
42
+ export declare function extractProjectPrefix(tags: string[] | undefined): string | undefined;
43
+ export interface NormalizeResult {
44
+ data: any;
45
+ warnings: string[];
46
+ project?: {
47
+ prefix: string;
48
+ type?: ProjectObjectType;
49
+ version?: string;
50
+ };
51
+ }
52
+ export interface NormalizeInput {
53
+ operation_type: string;
54
+ data: any;
55
+ projectPrefix?: string;
56
+ role?: ProjectRole;
57
+ industry?: IndustryMode;
58
+ version?: string;
59
+ shareable?: boolean;
60
+ }
61
+ export declare function normalizeForProject(input: NormalizeInput): NormalizeResult;
62
+ export declare const NAMESPACE_VERSION = 1;
@@ -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,17 @@
1
+ import type { CallEnv } from "../schema/call/base.js";
2
+ import { type ConfirmLevel, type OperationPreview } from "../knowledge/safety-rules.js";
3
+ export declare function isConfirmGateEnabled(): boolean;
4
+ export type FailMode = "open" | "closed";
5
+ export type ConfirmResult = {
6
+ pass: true;
7
+ } | {
8
+ pass: false;
9
+ level: ConfirmLevel;
10
+ preview: OperationPreview;
11
+ rule_id: string;
12
+ };
13
+ export declare function getFailMode(level: ConfirmLevel): FailMode;
14
+ export declare function confirmGate(operation_type: string, data: any, env: any, userIntentPhrases?: string[]): ConfirmResult;
15
+ export declare function isExplicitlyConfirmed(env: CallEnv & {
16
+ confirmed?: boolean;
17
+ }): boolean;
@@ -0,0 +1,88 @@
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
+ const internalErrorCounts = {};
7
+ function logInternalError(context, error) {
8
+ const key = context;
9
+ internalErrorCounts[key] = (internalErrorCounts[key] ?? 0) + 1;
10
+ const count = internalErrorCounts[key];
11
+ console.warn(`[ConfirmGate] internal_error context="${context}" count=${count} error=${error instanceof Error ? error.message : String(error)}`);
12
+ }
13
+ export function getFailMode(level) {
14
+ switch (level) {
15
+ case "irreversible":
16
+ case "publish":
17
+ case "amount":
18
+ return "closed";
19
+ case "standard":
20
+ case "none":
21
+ default:
22
+ return "open";
23
+ }
24
+ }
25
+ function buildInternalErrorResult() {
26
+ return {
27
+ pass: false,
28
+ level: "irreversible",
29
+ preview: {
30
+ level: "irreversible",
31
+ operation: "unknown",
32
+ irreversible: true,
33
+ },
34
+ rule_id: "internal_error",
35
+ };
36
+ }
37
+ export function confirmGate(operation_type, data, env, userIntentPhrases) {
38
+ if (!isConfirmGateEnabled())
39
+ return { pass: true };
40
+ if (env?.confirmed === true)
41
+ return { pass: true };
42
+ let matched;
43
+ let ruleSearchError = null;
44
+ try {
45
+ matched = CONFIRMATION_RULES.find((r) => {
46
+ try {
47
+ return r.when(operation_type, data, env);
48
+ }
49
+ catch (e) {
50
+ logInternalError(`rule_when:${r.id}`, e);
51
+ if (getFailMode(r.level) === "closed") {
52
+ throw e;
53
+ }
54
+ return false;
55
+ }
56
+ });
57
+ }
58
+ catch (e) {
59
+ ruleSearchError = e;
60
+ }
61
+ if (ruleSearchError) {
62
+ logInternalError("rule_search", ruleSearchError);
63
+ return buildInternalErrorResult();
64
+ }
65
+ if (!matched)
66
+ return { pass: true };
67
+ if (matched.bypass_on_explicit_intent && userIntentPhrases && userIntentPhrases.length > 0) {
68
+ const lower = userIntentPhrases.map((p) => p.toLowerCase());
69
+ const bypass = matched.bypass_on_explicit_intent.some((p) => lower.some((u) => u.includes(p.toLowerCase())));
70
+ if (bypass)
71
+ return { pass: true };
72
+ }
73
+ let preview;
74
+ try {
75
+ preview = matched.preview(operation_type, data, env);
76
+ }
77
+ catch (e) {
78
+ logInternalError(`rule_preview:${matched.id}`, e);
79
+ if (getFailMode(matched.level) === "closed") {
80
+ return buildInternalErrorResult();
81
+ }
82
+ return { pass: true };
83
+ }
84
+ return { pass: false, level: matched.level, preview, rule_id: matched.id };
85
+ }
86
+ export function isExplicitlyConfirmed(env) {
87
+ return env?.confirmed === true;
88
+ }
@@ -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;