@ftai/dsh-plugin-acn 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/LICENSE-APACHE +201 -0
  3. package/LICENSE-MIT +19 -0
  4. package/README.md +55 -2
  5. package/README_EN.md +56 -0
  6. package/cordis.patch.yml +29 -0
  7. package/docs/acn-compat.md +33 -0
  8. package/docs/architecture.md +129 -0
  9. package/docs/assets/activity-view.png +0 -0
  10. package/docs/assets/install-package.png +0 -0
  11. package/docs/assets/knowledge-model.png +0 -0
  12. package/docs/assets/knowledge-view.png +0 -0
  13. package/docs/assets/personal-configuration.png +0 -0
  14. package/docs/assets/session-upstream.png +0 -0
  15. package/docs/assets/upstream-settings.png +0 -0
  16. package/docs/assets/upstream-team.png +0 -0
  17. package/docs/command-reference.md +201 -0
  18. package/docs/config.md +243 -0
  19. package/docs/development.md +197 -0
  20. package/docs/dsh-compat.md +59 -0
  21. package/docs/index.md +16 -0
  22. package/docs/outstanding-issues.md +61 -0
  23. package/docs/user_guide.md +183 -0
  24. package/icon.svg +8 -0
  25. package/lib/activities-LRoCwpzw.js +327 -0
  26. package/lib/alignment-CwH0nBf-.js +80 -0
  27. package/lib/auth-DFI9yowX.js +71 -0
  28. package/lib/checkpoint-Bmt8q2vB.js +188 -0
  29. package/lib/checkpoint-RgcdqifN.js +318 -0
  30. package/lib/claim-DOAGe8ZK.js +168 -0
  31. package/lib/client.js +18420 -0
  32. package/lib/deliver-BuYQaPRW.js +168 -0
  33. package/lib/delivery-status-D5m3178s.js +87 -0
  34. package/lib/dispute-CtrInHzf.js +20 -0
  35. package/lib/disputes-ByEmi43j.js +51 -0
  36. package/lib/dream-agent-DBszTHXY.js +249 -0
  37. package/lib/dream.js +4 -0
  38. package/lib/effects-DJ4Xa7Tx.js +268 -0
  39. package/lib/errors-Bp_2WXBr.js +19 -0
  40. package/lib/errors-pPumDOGD.js +18 -0
  41. package/lib/evidence-store-DLFvSuNa.js +1030 -0
  42. package/lib/formation-D4LO31WW.js +187 -0
  43. package/lib/formation-replay-CEOy5FkI.js +87 -0
  44. package/lib/formation.js +9 -0
  45. package/lib/inbox-2CugZZQm.js +188 -0
  46. package/lib/inbox-DFtE2fOp.js +71 -0
  47. package/lib/inbox.js +3 -0
  48. package/lib/index.js +1377 -0
  49. package/lib/lock-DbmlKOoX.js +332 -0
  50. package/lib/pages-BEWC3kmZ.js +51 -0
  51. package/lib/paths-CDYV5UH9.js +154 -0
  52. package/lib/plugins/commands.js +590 -0
  53. package/lib/plugins/dream.js +66 -0
  54. package/lib/plugins/formation.js +66 -0
  55. package/lib/plugins/inbox.js +53 -0
  56. package/lib/plugins/knowledge.js +1111 -0
  57. package/lib/plugins/prompt.js +102 -0
  58. package/lib/plugins/tools.js +280 -0
  59. package/lib/policy-DnyHh7Bl.js +16 -0
  60. package/lib/prepare-DwHZudbA.js +134 -0
  61. package/lib/presentation-BlLjgDjP.js +47 -0
  62. package/lib/protocol.js +8 -0
  63. package/lib/queue-M917xHPS.js +153 -0
  64. package/lib/regular-file-BFpqMoub.js +136 -0
  65. package/lib/render-CJaVcKKC.js +48 -0
  66. package/lib/reported-sets-DdEKdeVb.js +122 -0
  67. package/lib/revision-DeoL_IUN.js +11 -0
  68. package/lib/scheduler-MaUEbXr3.js +64 -0
  69. package/lib/service-B7AI5jds.js +344 -0
  70. package/lib/service-BcHV5mc7.js +305 -0
  71. package/lib/service-CNjqHCBR.js +505 -0
  72. package/lib/service-C_i3BzdP.js +1106 -0
  73. package/lib/session-binding-BQrOGhZI.js +151 -0
  74. package/lib/session-state-CYqUhC95.js +38 -0
  75. package/lib/sessions-C2xuPFQv.js +218 -0
  76. package/lib/store.js +16 -0
  77. package/lib/structured-lyQCK-Zk.js +452 -0
  78. package/lib/subagent-yJsFxHmH.js +9 -0
  79. package/lib/team-credentials-C9xHrPIi.js +579 -0
  80. package/lib/team.js +3 -0
  81. package/lib/tool-schema-3b4gH1zf.js +28 -0
  82. package/lib/trace-Da0RnL5R.js +14 -0
  83. package/lib/traces-CHBo8y1z.js +11 -0
  84. package/lib/types/activities.d.ts +71 -0
  85. package/lib/types/advanced-configuration.d.ts +11 -0
  86. package/lib/types/client/ActivityDetails.d.ts +18 -0
  87. package/lib/types/client/AdvancedPreferences.d.ts +8 -0
  88. package/lib/types/client/BlankCommandFeedback.d.ts +10 -0
  89. package/lib/types/client/ComposerMenu.d.ts +24 -0
  90. package/lib/types/client/ConfigurationPage.d.ts +11 -0
  91. package/lib/types/client/ConnectionCheckDialog.d.ts +12 -0
  92. package/lib/types/client/KnowledgeDetail.d.ts +6 -0
  93. package/lib/types/client/KnowledgeDirectoryField.d.ts +11 -0
  94. package/lib/types/client/KnowledgePanel.d.ts +12 -0
  95. package/lib/types/client/KnowledgeReference.d.ts +13 -0
  96. package/lib/types/client/SessionToolbar.d.ts +16 -0
  97. package/lib/types/client/SettingsToast.d.ts +3 -0
  98. package/lib/types/client/SourceSessionLink.d.ts +15 -0
  99. package/lib/types/client/TeamCredentialField.d.ts +16 -0
  100. package/lib/types/client/TeamSettingsPage.d.ts +30 -0
  101. package/lib/types/client/configuration-errors.d.ts +2 -0
  102. package/lib/types/client/interaction-styles.d.ts +1 -0
  103. package/lib/types/client/interaction-ui.d.ts +30 -0
  104. package/lib/types/client/knowledge-labels.d.ts +5 -0
  105. package/lib/types/client/locales.d.ts +51 -0
  106. package/lib/types/commands/claim.d.ts +4 -0
  107. package/lib/types/commands/import.d.ts +10 -0
  108. package/lib/types/commands/status.d.ts +5 -0
  109. package/lib/types/config.d.ts +122 -0
  110. package/lib/types/configuration.d.ts +259 -0
  111. package/lib/types/credentials.d.ts +65 -0
  112. package/lib/types/dream/audit.d.ts +4 -0
  113. package/lib/types/dream/autonomous.d.ts +185 -0
  114. package/lib/types/dream/candidates.d.ts +34 -0
  115. package/lib/types/dream/checkpoint.d.ts +35 -0
  116. package/lib/types/dream/evidence-files.d.ts +10 -0
  117. package/lib/types/dream/evidence-store.d.ts +103 -0
  118. package/lib/types/dream/evidence.d.ts +30 -0
  119. package/lib/types/dream/index.d.ts +10 -0
  120. package/lib/types/dream/plan.d.ts +18 -0
  121. package/lib/types/dream/preservation.d.ts +6 -0
  122. package/lib/types/dream/review.d.ts +10 -0
  123. package/lib/types/dream/schema.d.ts +1475 -0
  124. package/lib/types/dream/service.d.ts +56 -0
  125. package/lib/types/dream/sync.d.ts +147 -0
  126. package/lib/types/dsh-adapter/configuration-remote.d.ts +1 -0
  127. package/lib/types/dsh-adapter/configuration-service.d.ts +28 -0
  128. package/lib/types/dsh-adapter/dream-agent.d.ts +4 -0
  129. package/lib/types/dsh-adapter/dream-evidence.d.ts +3 -0
  130. package/lib/types/dsh-adapter/formation-archive.d.ts +3 -0
  131. package/lib/types/dsh-adapter/formation-replay.d.ts +5 -0
  132. package/lib/types/dsh-adapter/formation.d.ts +4 -0
  133. package/lib/types/dsh-adapter/interaction-service.d.ts +13 -0
  134. package/lib/types/dsh-adapter/knowledge-paths.d.ts +3 -0
  135. package/lib/types/dsh-adapter/llm.d.ts +10 -0
  136. package/lib/types/dsh-adapter/project-upstream.d.ts +4 -0
  137. package/lib/types/dsh-adapter/runtime-pool.d.ts +110 -0
  138. package/lib/types/dsh-adapter/session-binding.d.ts +43 -0
  139. package/lib/types/dsh-adapter/source-sessions.d.ts +3 -0
  140. package/lib/types/dsh-adapter/team-credentials.d.ts +5 -0
  141. package/lib/types/dsh-adapter/tool-schema.d.ts +4 -0
  142. package/lib/types/dsh-adapter/tools.d.ts +5 -0
  143. package/lib/types/formation/capture.d.ts +19 -0
  144. package/lib/types/formation/checkpoint.d.ts +136 -0
  145. package/lib/types/formation/index.d.ts +10 -0
  146. package/lib/types/formation/prepare.d.ts +16 -0
  147. package/lib/types/formation/schema.d.ts +45 -0
  148. package/lib/types/formation/service.d.ts +58 -0
  149. package/lib/types/formation/transcript.d.ts +75 -0
  150. package/lib/types/formation/triggers.d.ts +3 -0
  151. package/lib/types/inbox/cascade.d.ts +3 -0
  152. package/lib/types/inbox/effects.d.ts +275 -0
  153. package/lib/types/inbox/index.d.ts +5 -0
  154. package/lib/types/inbox/prepare.d.ts +380 -0
  155. package/lib/types/inbox/service.d.ts +26 -0
  156. package/lib/types/inbox/sync.d.ts +9 -0
  157. package/lib/types/index.d.ts +1 -0
  158. package/lib/types/interaction-messages.d.ts +69 -0
  159. package/lib/types/interaction.d.ts +550 -0
  160. package/lib/types/knowledge/alignment.d.ts +49 -0
  161. package/lib/types/knowledge/catalog.d.ts +5 -0
  162. package/lib/types/knowledge/changes.d.ts +32 -0
  163. package/lib/types/knowledge/disputes.d.ts +3 -0
  164. package/lib/types/knowledge/errors.d.ts +9 -0
  165. package/lib/types/knowledge/ordering.d.ts +7 -0
  166. package/lib/types/knowledge/pages.d.ts +7 -0
  167. package/lib/types/knowledge/safety.d.ts +2 -0
  168. package/lib/types/knowledge/service.d.ts +52 -0
  169. package/lib/types/knowledge/sessions.d.ts +59 -0
  170. package/lib/types/knowledge/sources.d.ts +2 -0
  171. package/lib/types/knowledge/timestamps.d.ts +1 -0
  172. package/lib/types/knowledge/types.d.ts +84 -0
  173. package/lib/types/llm/response.d.ts +1 -0
  174. package/lib/types/llm/structured.d.ts +27 -0
  175. package/lib/types/local-name.d.ts +1 -0
  176. package/lib/types/plugins/client.d.ts +9 -0
  177. package/lib/types/plugins/commands.d.ts +11 -0
  178. package/lib/types/plugins/configuration.d.ts +8 -0
  179. package/lib/types/plugins/dream.d.ts +16 -0
  180. package/lib/types/plugins/formation.d.ts +16 -0
  181. package/lib/types/plugins/inbox.d.ts +16 -0
  182. package/lib/types/plugins/knowledge.d.ts +19 -0
  183. package/lib/types/plugins/prompt.d.ts +17 -0
  184. package/lib/types/plugins/tools.d.ts +10 -0
  185. package/lib/types/prompt/render.d.ts +2 -0
  186. package/lib/types/protocol/arbitration.d.ts +154 -0
  187. package/lib/types/protocol/auth.d.ts +31 -0
  188. package/lib/types/protocol/claim.d.ts +36 -0
  189. package/lib/types/protocol/dispute.d.ts +17 -0
  190. package/lib/types/protocol/ids.d.ts +20 -0
  191. package/lib/types/protocol/inbox.d.ts +141 -0
  192. package/lib/types/protocol/index.d.ts +11 -0
  193. package/lib/types/protocol/policy.d.ts +21 -0
  194. package/lib/types/protocol/revision.d.ts +2 -0
  195. package/lib/types/protocol/router.d.ts +114 -0
  196. package/lib/types/protocol/schema.d.ts +4 -0
  197. package/lib/types/protocol/time.d.ts +5 -0
  198. package/lib/types/protocol/trace.d.ts +11 -0
  199. package/lib/types/store/atomic.d.ts +8 -0
  200. package/lib/types/store/claim-edits.d.ts +33 -0
  201. package/lib/types/store/claims.d.ts +7 -0
  202. package/lib/types/store/context.d.ts +13 -0
  203. package/lib/types/store/delivery-status.d.ts +47 -0
  204. package/lib/types/store/disputes.d.ts +6 -0
  205. package/lib/types/store/entities.d.ts +16 -0
  206. package/lib/types/store/errors.d.ts +8 -0
  207. package/lib/types/store/inbox.d.ts +27 -0
  208. package/lib/types/store/index.d.ts +16 -0
  209. package/lib/types/store/jobs.d.ts +5 -0
  210. package/lib/types/store/lock.d.ts +11 -0
  211. package/lib/types/store/path-names.d.ts +2 -0
  212. package/lib/types/store/paths.d.ts +45 -0
  213. package/lib/types/store/presentation.d.ts +13 -0
  214. package/lib/types/store/regular-file.d.ts +2 -0
  215. package/lib/types/store/rejected-disputes.d.ts +18 -0
  216. package/lib/types/store/rename.d.ts +1 -0
  217. package/lib/types/store/reported-sets.d.ts +24 -0
  218. package/lib/types/store/session-state.d.ts +17 -0
  219. package/lib/types/store/traces.d.ts +6 -0
  220. package/lib/types/store/uploads.d.ts +312 -0
  221. package/lib/types/store/yaml.d.ts +8 -0
  222. package/lib/types/team/errors.d.ts +10 -0
  223. package/lib/types/team/http.d.ts +20 -0
  224. package/lib/types/team/index.d.ts +5 -0
  225. package/lib/types/team/maintainer-client.d.ts +18 -0
  226. package/lib/types/team/router-client.d.ts +14 -0
  227. package/lib/types/team/service.d.ts +28 -0
  228. package/lib/types/team/system-proxy.d.ts +9 -0
  229. package/lib/types/tools/claim.d.ts +63 -0
  230. package/lib/types/tools/consult-router.d.ts +11 -0
  231. package/lib/types/tools/subagent.d.ts +8 -0
  232. package/lib/types/tools/validation.d.ts +2 -0
  233. package/lib/types/upload/consolidation.d.ts +63 -0
  234. package/lib/types/upload/deliver.d.ts +15 -0
  235. package/lib/types/upload/index.d.ts +2 -0
  236. package/lib/types/upload/scheduler.d.ts +19 -0
  237. package/lib/types/upstreams.d.ts +5 -0
  238. package/lib/types/worker/queue.d.ts +17 -0
  239. package/lib/types/worker/types.d.ts +51 -0
  240. package/lib/types/worker/worker.d.ts +39 -0
  241. package/lib/types-C2ST2Zdg.js +17 -0
  242. package/lib/upload.js +3 -0
  243. package/lib/uploads-BCA2p92b.js +210 -0
  244. package/lib/worker-BBTYP2RE.js +185 -0
  245. package/locale/commands/en.json +1 -0
  246. package/locale/commands/zh.json +1 -0
  247. package/locale/dream/en.json +1 -0
  248. package/locale/dream/zh.json +1 -0
  249. package/locale/en.json +7 -0
  250. package/locale/formation/en.json +1 -0
  251. package/locale/formation/zh.json +1 -0
  252. package/locale/inbox/en.json +1 -0
  253. package/locale/inbox/zh.json +1 -0
  254. package/locale/knowledge/en.json +1 -0
  255. package/locale/knowledge/zh.json +1 -0
  256. package/locale/prompt/en.json +1 -0
  257. package/locale/prompt/zh.json +1 -0
  258. package/locale/tools/en.json +1 -0
  259. package/locale/tools/zh.json +1 -0
  260. package/locale/zh.json +7 -0
  261. package/package.json +262 -3
  262. package/prompts/claim_dream.j2 +77 -0
  263. package/prompts/claim_dream_legacy.j2 +63 -0
  264. package/prompts/dream_compaction.j2 +11 -0
  265. package/prompts/dream_evidence.j2 +5 -0
  266. package/prompts/inbox_claim_attribute_update_internalize.j2 +112 -0
  267. package/prompts/inbox_policy_update_internalize.j2 +87 -0
  268. package/prompts/knowledge.j2 +38 -0
  269. package/prompts/session_recap.j2 +113 -0
  270. package/prompts/what_is_claim.j2 +51 -0
  271. package/prompts/what_is_dispute.j2 +21 -0
  272. package/prompts/what_is_policy.j2 +22 -0
@@ -0,0 +1,579 @@
1
+ import { S as timestampNanos, c as AgentIdSchema, i as effectiveUpdatedAt, x as nowSeconds } from "./claim-DOAGe8ZK.js";
2
+ import { R as nextClaimUpdateAt } from "./evidence-store-DLFvSuNa.js";
3
+ import { n as claimRevision } from "./revision-DeoL_IUN.js";
4
+ import { n as RevisionConflict, t as KnowledgeError } from "./errors-Bp_2WXBr.js";
5
+ import { n as validateClaimText } from "./regular-file-BFpqMoub.js";
6
+ import { C as StoreError, S as LockTimeoutError, d as removeFile, n as withFileLock, u as cleanupAtomicTemps, w as hasCode } from "./lock-DbmlKOoX.js";
7
+ import { n as AnalysisReadBoundary, r as KnowledgeBusy } from "./alignment-CwH0nBf-.js";
8
+ import { i as ClaimStore } from "./reported-sets-DdEKdeVb.js";
9
+ import { t as TraceStore } from "./traces-CHBo8y1z.js";
10
+ import { r as UploadStore } from "./uploads-BCA2p92b.js";
11
+ import { t as DreamStore } from "./checkpoint-RgcdqifN.js";
12
+ import { a as assertStorageName, n as agentHomePath, t as AgentPaths } from "./paths-CDYV5UH9.js";
13
+ import { n as ClaimEditStore } from "./disputes-ByEmi43j.js";
14
+ import { n as FormationStore } from "./checkpoint-Bmt8q2vB.js";
15
+ import { n as InboxEffectStore } from "./effects-DJ4Xa7Tx.js";
16
+ import { t as TeamFacade } from "./service-B7AI5jds.js";
17
+ import { t as DurableWorker } from "./worker-BBTYP2RE.js";
18
+ import { r as MAX_TRACE_TASK_PAGE_LIMIT, t as ClaimUpdateSchema } from "./types-C2ST2Zdg.js";
19
+ import { a as validatePage, n as claimListPage, r as page } from "./pages-BEWC3kmZ.js";
20
+ import { t as PresentationStore } from "./presentation-BlLjgDjP.js";
21
+ import { z } from "zod";
22
+ import { createHash } from "node:crypto";
23
+ import fs, { realpath } from "node:fs/promises";
24
+ import { join, resolve } from "node:path";
25
+ //#region src/config.ts
26
+ const positive = () => z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
27
+ const nonnegative = () => z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
28
+ const endpoint = z.string().refine((value) => {
29
+ if (value === "") return true;
30
+ try {
31
+ const url = new URL(value);
32
+ return ["http:", "https:"].includes(url.protocol) && !url.username && !url.password && !url.search && !url.hash;
33
+ } catch {
34
+ return false;
35
+ }
36
+ });
37
+ const UpstreamNameSchema = z.string().regex(/^[a-z0-9_-]+$/).refine((value) => ![
38
+ "data",
39
+ "skills",
40
+ "config.toml",
41
+ "acn.md",
42
+ "logs",
43
+ "tmp",
44
+ ".git"
45
+ ].includes(value));
46
+ const UpstreamSchema = z.strictObject({
47
+ name: z.string().trim().max(80).default(""),
48
+ agentId: AgentIdSchema,
49
+ enabled: z.boolean().default(true),
50
+ routerEndpoint: endpoint.default(""),
51
+ maintainerEndpoint: endpoint.default(""),
52
+ keyEnv: z.string().regex(/^(?:[A-Za-z_][A-Za-z0-9_]*)?$/).default(""),
53
+ timeoutMs: positive().default(15e3),
54
+ legacyStorage: z.enum([
55
+ "base",
56
+ "personal",
57
+ "connection"
58
+ ]).optional(),
59
+ legacyKey: z.string().regex(/^[a-zA-Z0-9_-]{1,80}$/).optional()
60
+ }).superRefine((value, ctx) => {
61
+ if (Boolean(value.routerEndpoint) !== Boolean(value.maintainerEndpoint)) ctx.addIssue({
62
+ code: "custom",
63
+ path: ["routerEndpoint"],
64
+ message: "Configure both team endpoints or neither."
65
+ });
66
+ if (value.legacyStorage === "connection" !== (value.legacyKey !== void 0)) ctx.addIssue({
67
+ code: "custom",
68
+ path: ["legacyStorage"],
69
+ message: "Invalid legacy storage mapping."
70
+ });
71
+ });
72
+ const ConnectionSchema = z.strictObject({
73
+ id: z.string().regex(/^[a-zA-Z0-9_-]{1,80}$/).refine((id) => !["personal", "legacy"].includes(id)),
74
+ name: z.string().trim().min(1).max(80),
75
+ enabled: z.boolean().default(true),
76
+ agentId: AgentIdSchema,
77
+ routerEndpoint: endpoint.refine(Boolean),
78
+ maintainerEndpoint: endpoint.refine(Boolean),
79
+ keyEnv: z.string().regex(/^(?:[A-Za-z_][A-Za-z0-9_]*)?$/).default(""),
80
+ timeoutMs: positive().default(15e3)
81
+ });
82
+ const ConfigSchema = z.strictObject({
83
+ upstream: z.string().default(""),
84
+ upstreams: z.record(UpstreamNameSchema, UpstreamSchema).optional(),
85
+ agentId: z.union([z.literal(""), AgentIdSchema]).default(""),
86
+ home: z.string().trim().min(1).default("~/.acn-dsh"),
87
+ sessionEpoch: nonnegative().default(0),
88
+ connections: z.array(ConnectionSchema).max(50).default([]),
89
+ defaultConnection: z.string().default(""),
90
+ legacyEnabled: z.boolean().default(true),
91
+ showCompletion: z.boolean().default(true),
92
+ team: z.strictObject({
93
+ routerEndpoint: endpoint.default(""),
94
+ maintainerEndpoint: endpoint.default(""),
95
+ keyEnv: z.string().regex(/^(?:[A-Za-z_][A-Za-z0-9_]*)?$/).default(""),
96
+ timeoutMs: positive().default(15e3),
97
+ routerTimeoutMs: positive().default(5e4),
98
+ retryCount: nonnegative().default(3),
99
+ retryBaseDelayMs: positive().default(500),
100
+ retryMaxDelayMs: positive().default(8e3)
101
+ }).prefault({}),
102
+ llm: z.strictObject({
103
+ provider: z.string().default(""),
104
+ model: z.string().default(""),
105
+ maxOutputTokens: positive().default(32768),
106
+ timeoutMs: positive().default(6e5),
107
+ structuredRetries: positive().default(5)
108
+ }).prefault({}),
109
+ catalog: z.strictObject({
110
+ maxClaims: positive().default(20),
111
+ maxChars: positive().default(24e3)
112
+ }).prefault({}),
113
+ formation: z.strictObject({
114
+ recapOnCompaction: z.boolean().default(true),
115
+ idleRecap: z.boolean().default(true),
116
+ recapMinTurns: positive().default(10),
117
+ recapMinTokens: positive().default(1e5),
118
+ recapBatchIdleMinutes: positive().default(5),
119
+ recapTailIdleMinutes: positive().default(60),
120
+ recapScanSeconds: positive().default(30),
121
+ finalizeIdleMinutes: nonnegative().default(0),
122
+ finalizeOnDispose: z.boolean().default(false)
123
+ }).prefault({}),
124
+ inbox: z.strictObject({
125
+ pullOnSessionStart: z.boolean().default(true),
126
+ processingStaleAfterSecs: positive().default(600)
127
+ }).prefault({}),
128
+ dream: z.strictObject({
129
+ enabled: z.boolean().default(true),
130
+ minIntervalHours: positive().default(24),
131
+ minChangedClaims: positive().default(5),
132
+ checkIntervalHours: positive().default(4),
133
+ evidenceCalibration: z.boolean().default(false),
134
+ maxModelSteps: positive().max(128).default(24),
135
+ maxWrapUpSteps: positive().max(8).default(3),
136
+ evidenceMaxCalls: positive().max(256).default(32),
137
+ evidenceMaxSteps: positive().max(128).default(24),
138
+ evidenceMaxBytes: positive().max(16777216).default(1048576),
139
+ evidenceMaxChars: positive().max(64e3).default(16e3),
140
+ evidenceMaxFiles: positive().max(4096).default(256)
141
+ }).prefault({})
142
+ }).superRefine((config, ctx) => {
143
+ if (config.upstreams !== void 0) {
144
+ if (config.upstream !== "" && config.upstreams[config.upstream]?.enabled !== true) ctx.addIssue({
145
+ code: "custom",
146
+ path: ["upstream"],
147
+ message: "Select an enabled upstream."
148
+ });
149
+ }
150
+ if (new Set(config.connections.map((item) => item.id)).size !== config.connections.length) ctx.addIssue({
151
+ code: "custom",
152
+ path: ["connections"],
153
+ message: "Connection identifiers must be unique."
154
+ });
155
+ if (config.defaultConnection !== "" && config.defaultConnection !== "legacy" && !config.connections.some((item) => item.id === config.defaultConnection && item.enabled)) ctx.addIssue({
156
+ code: "custom",
157
+ path: ["defaultConnection"],
158
+ message: "Default connection must be enabled."
159
+ });
160
+ if (Boolean(config.team.routerEndpoint) !== Boolean(config.team.maintainerEndpoint)) ctx.addIssue({
161
+ code: "custom",
162
+ path: ["team"],
163
+ message: "Configure both team endpoints or neither."
164
+ });
165
+ if (Boolean(config.llm.provider.trim()) !== Boolean(config.llm.model.trim())) ctx.addIssue({
166
+ code: "custom",
167
+ path: ["llm"],
168
+ message: "Configure both provider and model or neither."
169
+ });
170
+ if (config.team.retryMaxDelayMs < config.team.retryBaseDelayMs) ctx.addIssue({
171
+ code: "custom",
172
+ path: ["team", "retryMaxDelayMs"],
173
+ message: "Maximum retry delay must not be smaller than the base delay."
174
+ });
175
+ });
176
+ var ConfigError = class extends Error {
177
+ fields;
178
+ kind = "config";
179
+ constructor(fields) {
180
+ super(`Invalid ACN configuration: ${fields.join(", ")}`);
181
+ this.fields = fields;
182
+ this.name = "ConfigError";
183
+ }
184
+ };
185
+ function resolveConfig(input) {
186
+ let value = input;
187
+ if (typeof input === "object" && input !== null && !Array.isArray(input)) {
188
+ const compatible = { ...input };
189
+ delete compatible["projectUpstreams"];
190
+ delete compatible["memory"];
191
+ value = compatible;
192
+ }
193
+ const parsed = ConfigSchema.safeParse(value);
194
+ if (!parsed.success) throw new ConfigError([...new Set(parsed.error.issues.map((issue) => issue.path.join(".") || "config"))]);
195
+ return parsed.data;
196
+ }
197
+ function upstreamsOf(config) {
198
+ if (config.upstreams !== void 0) return config.upstreams;
199
+ const items = {};
200
+ if (config.agentId !== "") {
201
+ items["personal"] = UpstreamSchema.parse({
202
+ name: "个人知识",
203
+ agentId: config.agentId,
204
+ legacyStorage: config.team.routerEndpoint ? "personal" : "base"
205
+ });
206
+ if (config.team.routerEndpoint) items["legacy"] = UpstreamSchema.parse({
207
+ name: "原有团队",
208
+ agentId: config.agentId,
209
+ enabled: config.legacyEnabled,
210
+ routerEndpoint: config.team.routerEndpoint,
211
+ maintainerEndpoint: config.team.maintainerEndpoint,
212
+ keyEnv: config.team.keyEnv,
213
+ timeoutMs: config.team.timeoutMs,
214
+ legacyStorage: "base"
215
+ });
216
+ }
217
+ for (const connection of config.connections) {
218
+ const { id, ...value } = connection;
219
+ let key = id.toLowerCase();
220
+ while (items[key] !== void 0 || [
221
+ "data",
222
+ "skills",
223
+ "logs",
224
+ "tmp"
225
+ ].includes(key)) key = `${key}_copy`;
226
+ items[key] = UpstreamSchema.parse({
227
+ ...value,
228
+ legacyStorage: "connection",
229
+ legacyKey: id
230
+ });
231
+ }
232
+ return items;
233
+ }
234
+ //#endregion
235
+ //#region src/upstreams.ts
236
+ function resolveUpstream(config, key, includeDisabled = false) {
237
+ const profile = upstreamsOf(config)[key];
238
+ if (profile === void 0 || !profile.enabled && !includeDisabled) return void 0;
239
+ assertStorageName(key);
240
+ if (profile.legacyKey !== void 0) assertStorageName(profile.legacyKey);
241
+ const home = profile.legacyStorage === "base" ? config.home : profile.legacyStorage === "personal" ? join(config.home, "personal") : profile.legacyStorage === "connection" ? join(config.home, "connections", profile.legacyKey ?? "") : join(config.home, key, "data");
242
+ return resolveConfig({
243
+ ...config,
244
+ upstreams: void 0,
245
+ upstream: "",
246
+ connections: [],
247
+ defaultConnection: "",
248
+ sessionEpoch: 0,
249
+ home,
250
+ agentId: profile.agentId,
251
+ legacyEnabled: true,
252
+ team: {
253
+ ...config.team,
254
+ routerEndpoint: profile.routerEndpoint,
255
+ maintainerEndpoint: profile.maintainerEndpoint,
256
+ keyEnv: profile.keyEnv,
257
+ timeoutMs: profile.timeoutMs
258
+ }
259
+ });
260
+ }
261
+ function defaultUpstream(config) {
262
+ return config.upstreams === void 0 ? config.agentId ? "personal" : "" : config.upstream;
263
+ }
264
+ async function canonicalProjectPath(cwd) {
265
+ const path = resolve(cwd);
266
+ try {
267
+ return await realpath(path);
268
+ } catch {
269
+ return path;
270
+ }
271
+ }
272
+ //#endregion
273
+ //#region src/knowledge/service.ts
274
+ function missing(error) {
275
+ return hasCode(error, "ENOENT") || error instanceof StoreError && error.kind === "io" && hasCode(error.cause, "ENOENT");
276
+ }
277
+ var AcnKnowledge = class {
278
+ config;
279
+ logger;
280
+ agentId;
281
+ mode;
282
+ storeContext;
283
+ team;
284
+ jobs;
285
+ cache;
286
+ listeners = /* @__PURE__ */ new Set();
287
+ constructor(config, logger, credential) {
288
+ this.config = config;
289
+ this.logger = logger;
290
+ this.agentId = config.agentId || null;
291
+ this.mode = config.team.routerEndpoint ? "team" : "solo";
292
+ this.storeContext = this.agentId === null ? null : {
293
+ agentId: this.agentId,
294
+ paths: new AgentPaths(agentHomePath(config.home, this.agentId)),
295
+ mode: this.mode,
296
+ logger
297
+ };
298
+ this.team = this.agentId !== null && this.mode === "team" ? new TeamFacade(config.team, this.agentId, logger, credential) : null;
299
+ this.jobs = this.storeContext === null ? null : new DurableWorker(this.storeContext);
300
+ }
301
+ get active() {
302
+ return this.mode === "solo" || this.config.legacyEnabled;
303
+ }
304
+ get configured() {
305
+ return this.agentId !== null;
306
+ }
307
+ teamStatus() {
308
+ return this.team?.status() ?? {
309
+ mode: "solo",
310
+ router: { state: "unknown" },
311
+ maintainer: { state: "unknown" }
312
+ };
313
+ }
314
+ context() {
315
+ if (this.storeContext === null) throw new KnowledgeError("unconfigured", "Configure agentId on the acn-knowledge row first.");
316
+ return this.storeContext;
317
+ }
318
+ async initialize() {
319
+ if (!this.configured) return;
320
+ await new PresentationStore(this.context()).initialize();
321
+ await cleanupAtomicTemps(this.context().paths.root, this.logger);
322
+ await new DreamStore(this.context()).recover();
323
+ await new ClaimEditStore(this.context()).recover();
324
+ await new FormationStore(this.context()).recover();
325
+ await new InboxEffectStore(this.context()).recover();
326
+ }
327
+ async snapshot(signal, lockTimeoutMs) {
328
+ return this.consistentRead(async () => {
329
+ const context = this.context();
330
+ let stamp;
331
+ try {
332
+ const stat = await fs.stat(context.paths.claims, { bigint: true });
333
+ stamp = `${stat.mtimeNs}:${stat.ctimeNs}`;
334
+ } catch (error) {
335
+ if (!hasCode(error, "ENOENT")) throw error;
336
+ stamp = "missing";
337
+ }
338
+ if (this.cache !== void 0 && this.cache.stamp === stamp && performance.now() - this.cache.checked < 2e3) return structuredClone({
339
+ claims: this.cache.claims,
340
+ version: this.cache.version
341
+ });
342
+ const claims = await new ClaimStore(context).list();
343
+ const revisions = [...claims].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0).map((claim) => `${claim.id}:${claimRevision(claim)}`).join("\n");
344
+ const version = { claimsDigest: createHash("sha256").update(revisions).digest("hex") };
345
+ this.cache = {
346
+ stamp,
347
+ checked: performance.now(),
348
+ claims,
349
+ version
350
+ };
351
+ return structuredClone({
352
+ claims,
353
+ version
354
+ });
355
+ }, signal, lockTimeoutMs);
356
+ }
357
+ async knowledgeVersion(signal, lockTimeoutMs) {
358
+ return (await this.snapshot(signal, lockTimeoutMs)).version;
359
+ }
360
+ async listClaims(query = {}, signal) {
361
+ return this.consistentRead(async () => {
362
+ return claimListPage(await new ClaimStore(this.context()).list(), query);
363
+ }, signal);
364
+ }
365
+ async readClaim(id, signal) {
366
+ return this.consistentRead(async () => {
367
+ const claim = await this.readOwnedClaim(id);
368
+ return {
369
+ claim,
370
+ revision: claimRevision(claim)
371
+ };
372
+ }, signal);
373
+ }
374
+ async readOwnedClaim(id) {
375
+ let claim;
376
+ try {
377
+ claim = await new ClaimStore(this.context()).read(id);
378
+ } catch (error) {
379
+ if (missing(error)) throw new KnowledgeError("not_found", `Claim ${id} was not found.`);
380
+ throw error;
381
+ }
382
+ if (claim.holder !== this.agentId) throw new KnowledgeError("ownership", `Claim ${id} is not held by this agent.`);
383
+ return claim;
384
+ }
385
+ async updateClaim(input, signal) {
386
+ const parsed = ClaimUpdateSchema.safeParse(input);
387
+ if (!parsed.success) throw new KnowledgeError("validation", "Invalid Claim update fields.");
388
+ const { id, expected_revision, ...fields } = parsed.data;
389
+ if (!Object.values(fields).some((value) => value !== void 0)) throw new KnowledgeError("validation", "Claim update requires at least one editable field.");
390
+ const context = this.context();
391
+ const result = await withFileLock(context.paths.knowledgeLock, async () => {
392
+ signal?.throwIfAborted();
393
+ await new DreamStore(context).recoverLocked();
394
+ await new ClaimEditStore(context).recoverLocked();
395
+ await new FormationStore(context).recoverLocked();
396
+ await new InboxEffectStore(context).recoverLocked();
397
+ const current = await this.readOwnedClaim(id);
398
+ const revision = claimRevision(current);
399
+ if (expected_revision !== revision) throw new RevisionConflict(revision);
400
+ const next = { ...current };
401
+ for (const key of [
402
+ "name",
403
+ "statement",
404
+ "scope",
405
+ "evidence_summary",
406
+ "confidence",
407
+ "status"
408
+ ]) {
409
+ const value = fields[key];
410
+ if (value !== void 0) Object.assign(next, { [key]: value });
411
+ }
412
+ validateClaimText({
413
+ name: next.name,
414
+ statement: next.statement,
415
+ scope: next.scope,
416
+ evidence_summary: next.evidence_summary
417
+ });
418
+ next.updated_at = nextClaimUpdateAt(nowSeconds(), effectiveUpdatedAt(current));
419
+ signal?.throwIfAborted();
420
+ if (context.mode === "team") await new ClaimEditStore(context).write({
421
+ expected_revision: revision,
422
+ target: next
423
+ });
424
+ await new ClaimStore(context).write(next);
425
+ if (context.mode === "team") {
426
+ await new UploadStore(context).enqueue([next], [], true);
427
+ await removeFile(context.paths.claimEditPending, this.logger);
428
+ }
429
+ this.cache = void 0;
430
+ return {
431
+ claim: next,
432
+ revision: claimRevision(next),
433
+ sync_pending: context.mode === "team",
434
+ ...context.mode === "team" ? { sync_warning: "Claim 已保存到本地,等待团队同步。" } : {}
435
+ };
436
+ }, {
437
+ signal,
438
+ timeoutMs: context.lockTimeoutMs
439
+ });
440
+ await this.notifyChanged(signal);
441
+ return result;
442
+ }
443
+ async listTraces(query = {}, signal) {
444
+ return this.consistentRead(async () => {
445
+ const offset = query.offset ?? 0;
446
+ const limit = query.limit ?? 20;
447
+ validatePage(offset, limit);
448
+ const traces = (await new TraceStore(this.context()).list()).filter((trace) => trace.agent === this.agentId && (query.claimId === void 0 || trace.input_claims.includes(query.claimId) || trace.output_claims.includes(query.claimId)));
449
+ traces.sort((a, b) => {
450
+ const delta = timestampNanos(b.created_at) - timestampNanos(a.created_at);
451
+ return delta === 0n ? a.id < b.id ? -1 : a.id > b.id ? 1 : 0 : delta > 0n ? 1 : -1;
452
+ });
453
+ return page(traces.map(({ id, name, created_at, input_claims, output_claims }) => ({
454
+ id,
455
+ name,
456
+ created_at,
457
+ input_claims,
458
+ output_claims
459
+ })), offset, limit);
460
+ }, signal);
461
+ }
462
+ async readTrace(id, options = {}, signal) {
463
+ return this.consistentRead(async () => {
464
+ const offset = options.taskOffset ?? 0;
465
+ const limit = options.taskLimit ?? 4e3;
466
+ validatePage(offset, limit, MAX_TRACE_TASK_PAGE_LIMIT);
467
+ let trace;
468
+ try {
469
+ trace = await new TraceStore(this.context()).read(id);
470
+ } catch (error) {
471
+ if (missing(error)) throw new KnowledgeError("not_found", `Trace ${id} was not found.`);
472
+ throw error;
473
+ }
474
+ if (trace.agent !== this.agentId) throw new KnowledgeError("ownership", `Trace ${id} is not owned by this agent.`);
475
+ const chars = Array.from(trace.task);
476
+ const end = Math.min(offset + limit, chars.length);
477
+ return {
478
+ ...trace,
479
+ task: chars.slice(offset, end).join(""),
480
+ task_offset: offset,
481
+ task_limit: limit,
482
+ task_omitted: chars.length - end,
483
+ next_task_offset: end < chars.length ? end : null
484
+ };
485
+ }, signal);
486
+ }
487
+ onClaimsChanged(listener) {
488
+ this.listeners.add(listener);
489
+ return () => {
490
+ this.listeners.delete(listener);
491
+ };
492
+ }
493
+ async applyFormation(...args) {
494
+ const result = await new FormationStore(this.context()).commit(...args);
495
+ if (result.applied) await this.notifyChanged(args[1].signal);
496
+ return result;
497
+ }
498
+ async applyInboxEffect(...args) {
499
+ const result = await new InboxEffectStore(this.context()).commit(...args);
500
+ if (result.applied > 0) await this.notifyChanged(args[3].signal);
501
+ return result;
502
+ }
503
+ async consistentRead(action, signal, lockTimeoutMs) {
504
+ const context = this.context();
505
+ try {
506
+ return await withFileLock(context.paths.knowledgeLock, async () => {
507
+ signal?.throwIfAborted();
508
+ await new DreamStore(context).recoverLocked();
509
+ await new ClaimEditStore(context).recoverLocked();
510
+ await new FormationStore(context).recoverLocked();
511
+ await new InboxEffectStore(context).recoverLocked();
512
+ const boundary = await AnalysisReadBoundary.begin(context.paths.root);
513
+ const result = await action();
514
+ await boundary.finish(context.paths.root);
515
+ signal?.throwIfAborted();
516
+ return result;
517
+ }, {
518
+ signal,
519
+ timeoutMs: lockTimeoutMs ?? context.lockTimeoutMs
520
+ });
521
+ } catch (error) {
522
+ signal?.throwIfAborted();
523
+ if (error instanceof LockTimeoutError) throw new KnowledgeBusy();
524
+ throw error;
525
+ }
526
+ }
527
+ async notifyChanged(signal) {
528
+ this.cache = void 0;
529
+ try {
530
+ const version = await this.knowledgeVersion(signal);
531
+ for (const listener of this.listeners) try {
532
+ listener(version);
533
+ } catch {
534
+ this.logger.warn("Claim change observer failed.");
535
+ }
536
+ } catch {
537
+ this.logger.warn("Knowledge was committed; its change notice will be checked on the next foreground step.");
538
+ }
539
+ }
540
+ dreamStore() {
541
+ return new DreamStore(this.context(), async () => {
542
+ await new ClaimEditStore(this.context()).recoverLocked();
543
+ await new FormationStore(this.context()).recoverLocked();
544
+ await new InboxEffectStore(this.context()).recoverLocked();
545
+ });
546
+ }
547
+ async dreamSnapshot(signal) {
548
+ return withFileLock(this.context().paths.knowledgeLock, async () => {
549
+ await new DreamStore(this.context()).recoverLocked();
550
+ await new ClaimEditStore(this.context()).recoverLocked();
551
+ await new FormationStore(this.context()).recoverLocked();
552
+ await new InboxEffectStore(this.context()).recoverLocked();
553
+ signal.throwIfAborted();
554
+ return new ClaimStore(this.context()).list();
555
+ }, {
556
+ signal,
557
+ timeoutMs: this.context().lockTimeoutMs
558
+ });
559
+ }
560
+ async applyDreamGroup(...args) {
561
+ const result = await this.dreamStore().commitGroup(...args);
562
+ await this.notifyChanged(args[6].signal);
563
+ return result;
564
+ }
565
+ };
566
+ //#endregion
567
+ //#region src/dsh-adapter/team-credentials.ts
568
+ function credentialReference(reference) {
569
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(reference)) throw new ConfigError(["team.keyEnv"]);
570
+ return reference;
571
+ }
572
+ function teamCredentials(ctx) {
573
+ return async (reference) => {
574
+ const provider = ctx.get("credentials");
575
+ return provider === void 0 ? process.env[reference] : (await provider.resolve(credentialReference(reference)))?.value;
576
+ };
577
+ }
578
+ //#endregion
579
+ export { defaultUpstream as a, ConnectionSchema as c, resolveConfig as d, upstreamsOf as f, canonicalProjectPath as i, UpstreamNameSchema as l, teamCredentials as n, resolveUpstream as o, AcnKnowledge as r, ConfigError as s, credentialReference as t, UpstreamSchema as u };
package/lib/team.js ADDED
@@ -0,0 +1,3 @@
1
+ import { t as TeamError } from "./errors-pPumDOGD.js";
2
+ import { a as bypassProxy, i as TeamHttp, n as MaintainerClient, o as teamUrl, r as RouterClient, t as TeamFacade } from "./service-B7AI5jds.js";
3
+ export { MaintainerClient, RouterClient, TeamError, TeamFacade, TeamHttp, bypassProxy, teamUrl };
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+ //#region src/dsh-adapter/tool-schema.ts
3
+ const JsonObject = z.record(z.string(), z.json());
4
+ function toolParameters(schema) {
5
+ const root = JsonObject.parse(JSON.parse(JSON.stringify(z.toJSONSchema(schema))));
6
+ if (!Array.isArray(root.oneOf)) return root;
7
+ const variants = root.oneOf.map((value) => JsonObject.parse(value));
8
+ const fields = variants.map((variant) => JsonObject.parse(variant.properties));
9
+ const keys = [...new Set(fields.flatMap((field) => Object.keys(field)))];
10
+ const properties = Object.fromEntries(keys.map((key) => {
11
+ const distinct = [...new Map(fields.filter((field) => field[key] !== void 0).map((field) => [JSON.stringify(field[key]), JsonObject.parse(field[key])])).values()];
12
+ const values = distinct.map((field) => field.const);
13
+ return [key, distinct.length === 1 ? distinct[0] : values.every((value) => typeof value === "string") ? {
14
+ type: "string",
15
+ enum: values
16
+ } : { anyOf: distinct }];
17
+ }));
18
+ const requiredSets = variants.map((variant) => z.array(z.string()).parse(variant.required ?? []));
19
+ const required = (requiredSets[0] ?? []).filter((key) => requiredSets.every((set) => set.includes(key)));
20
+ return JsonObject.parse({
21
+ ...root,
22
+ type: "object",
23
+ properties,
24
+ required
25
+ });
26
+ }
27
+ //#endregion
28
+ export { toolParameters as t };
@@ -0,0 +1,14 @@
1
+ import { a as TextSchema, c as AgentIdSchema, h as TraceIdSchema, l as ClaimIdSchema, m as SourceIdSchema, y as TimestampSchema } from "./claim-DOAGe8ZK.js";
2
+ import { z } from "zod";
3
+ //#region src/protocol/trace.ts
4
+ const TraceSchema = z.object({
5
+ id: TraceIdSchema,
6
+ name: TextSchema,
7
+ task: TextSchema,
8
+ agent: AgentIdSchema,
9
+ input_claims: z.array(SourceIdSchema).default([]),
10
+ output_claims: z.array(ClaimIdSchema).default([]),
11
+ created_at: TimestampSchema
12
+ });
13
+ //#endregion
14
+ export { TraceSchema as t };
@@ -0,0 +1,11 @@
1
+ import { h as TraceIdSchema } from "./claim-DOAGe8ZK.js";
2
+ import { a as EntityStore } from "./reported-sets-DdEKdeVb.js";
3
+ import { t as TraceSchema } from "./trace-Da0RnL5R.js";
4
+ //#region src/store/traces.ts
5
+ var TraceStore = class extends EntityStore {
6
+ constructor(context) {
7
+ super(context, context.paths.traces, TraceSchema, TraceIdSchema);
8
+ }
9
+ };
10
+ //#endregion
11
+ export { TraceStore as t };