chainlesschain 0.143.0 → 0.145.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 (133) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +157 -27
  4. package/src/commands/agent.js +587 -103
  5. package/src/commands/audit.js +206 -0
  6. package/src/commands/bi.js +152 -27
  7. package/src/commands/bm25.js +111 -27
  8. package/src/commands/browse.js +190 -29
  9. package/src/commands/ccron.js +128 -28
  10. package/src/commands/chat.js +207 -0
  11. package/src/commands/compliance.js +414 -34
  12. package/src/commands/compt.js +127 -29
  13. package/src/commands/consol.js +8 -2
  14. package/src/commands/cowork.js +580 -34
  15. package/src/commands/crosschain.js +182 -28
  16. package/src/commands/dao.js +182 -28
  17. package/src/commands/dlp.js +172 -27
  18. package/src/commands/economy.js +205 -50
  19. package/src/commands/evolution.js +203 -50
  20. package/src/commands/evomap.js +182 -27
  21. package/src/commands/fflag.js +74 -22
  22. package/src/commands/git.js +177 -37
  23. package/src/commands/hardening.js +209 -0
  24. package/src/commands/hmemory.js +204 -50
  25. package/src/commands/incentive.js +209 -0
  26. package/src/commands/inference.js +170 -34
  27. package/src/commands/itbudget.js +149 -33
  28. package/src/commands/kg.js +206 -0
  29. package/src/commands/lowcode.js +195 -38
  30. package/src/commands/marketplace.js +206 -0
  31. package/src/commands/matrix.js +179 -27
  32. package/src/commands/mcpscaf.js +145 -33
  33. package/src/commands/meminj.js +145 -33
  34. package/src/commands/nostr.js +178 -27
  35. package/src/commands/orchestrate.js +217 -0
  36. package/src/commands/orchgov.js +144 -33
  37. package/src/commands/pdfp.js +109 -27
  38. package/src/commands/perf.js +169 -32
  39. package/src/commands/perm.js +144 -33
  40. package/src/commands/pipeline.js +207 -52
  41. package/src/commands/planmode.js +141 -32
  42. package/src/commands/privacy.js +203 -0
  43. package/src/commands/promcomp.js +111 -27
  44. package/src/commands/recommend.js +177 -34
  45. package/src/commands/reputation.js +208 -0
  46. package/src/commands/sandbox.js +206 -0
  47. package/src/commands/seshhook.js +145 -33
  48. package/src/commands/seshsearch.js +141 -33
  49. package/src/commands/seshtail.js +144 -33
  50. package/src/commands/seshu.js +152 -33
  51. package/src/commands/sganal.js +123 -29
  52. package/src/commands/siem.js +201 -34
  53. package/src/commands/sla.js +212 -0
  54. package/src/commands/slotfill.js +146 -33
  55. package/src/commands/social.js +157 -32
  56. package/src/commands/stress.js +206 -0
  57. package/src/commands/svccont.js +145 -33
  58. package/src/commands/terraform.js +206 -0
  59. package/src/commands/tms.js +171 -33
  60. package/src/commands/topiccls.js +146 -33
  61. package/src/commands/uprof.js +141 -32
  62. package/src/commands/vcheck.js +122 -28
  63. package/src/commands/webfetch.js +141 -32
  64. package/src/commands/zkp.js +184 -28
  65. package/src/index.js +40 -0
  66. package/src/lib/a2a-protocol.js +319 -51
  67. package/src/lib/activitypub-bridge.js +288 -50
  68. package/src/lib/agent-economy.js +304 -51
  69. package/src/lib/app-builder.js +279 -46
  70. package/src/lib/audit-logger.js +321 -0
  71. package/src/lib/autonomous-agent.js +284 -48
  72. package/src/lib/bi-engine.js +283 -49
  73. package/src/lib/bm25-search.js +301 -49
  74. package/src/lib/browser-automation.js +296 -49
  75. package/src/lib/chat-core.js +336 -0
  76. package/src/lib/claude-code-bridge.js +341 -0
  77. package/src/lib/compliance-framework-reporter.js +305 -51
  78. package/src/lib/compliance-manager.js +330 -0
  79. package/src/lib/compression-telemetry.js +301 -49
  80. package/src/lib/content-recommender.js +317 -52
  81. package/src/lib/cowork-cron.js +298 -49
  82. package/src/lib/cowork-learning.js +333 -0
  83. package/src/lib/cowork-task-runner.js +308 -51
  84. package/src/lib/cowork-workflow.js +327 -0
  85. package/src/lib/cross-chain.js +311 -51
  86. package/src/lib/dao-governance.js +280 -46
  87. package/src/lib/dlp-engine.js +287 -49
  88. package/src/lib/evolution-system.js +278 -47
  89. package/src/lib/evomap-manager.js +280 -46
  90. package/src/lib/execution-backend.js +294 -48
  91. package/src/lib/feature-flags.js +294 -49
  92. package/src/lib/git-integration.js +285 -47
  93. package/src/lib/hardening-manager.js +341 -0
  94. package/src/lib/hierarchical-memory.js +284 -48
  95. package/src/lib/inference-network.js +308 -51
  96. package/src/lib/iteration-budget.js +302 -50
  97. package/src/lib/knowledge-graph.js +333 -0
  98. package/src/lib/matrix-bridge.js +281 -47
  99. package/src/lib/mcp-scaffold.js +318 -54
  100. package/src/lib/memory-injection.js +288 -49
  101. package/src/lib/nostr-bridge.js +286 -49
  102. package/src/lib/orchestrator.js +293 -48
  103. package/src/lib/pdf-parser.js +298 -49
  104. package/src/lib/perf-tuning.js +309 -50
  105. package/src/lib/permission-engine.js +287 -49
  106. package/src/lib/pipeline-orchestrator.js +289 -49
  107. package/src/lib/plan-mode.js +298 -51
  108. package/src/lib/privacy-computing.js +335 -0
  109. package/src/lib/reputation-optimizer.js +340 -0
  110. package/src/lib/sandbox-v2.js +327 -0
  111. package/src/lib/service-container.js +313 -52
  112. package/src/lib/session-consolidator.js +296 -49
  113. package/src/lib/session-hooks.js +312 -53
  114. package/src/lib/session-search.js +304 -51
  115. package/src/lib/session-tail.js +288 -49
  116. package/src/lib/session-usage.js +298 -52
  117. package/src/lib/siem-exporter.js +298 -51
  118. package/src/lib/skill-marketplace.js +345 -0
  119. package/src/lib/sla-manager.js +341 -0
  120. package/src/lib/slot-filler.js +303 -51
  121. package/src/lib/social-graph-analytics.js +295 -49
  122. package/src/lib/social-graph.js +272 -49
  123. package/src/lib/stress-tester.js +342 -0
  124. package/src/lib/sub-agent-registry.js +302 -53
  125. package/src/lib/task-model-selector.js +302 -50
  126. package/src/lib/terraform-manager.js +333 -0
  127. package/src/lib/todo-manager.js +281 -47
  128. package/src/lib/token-incentive.js +341 -0
  129. package/src/lib/topic-classifier.js +297 -49
  130. package/src/lib/user-profile.js +294 -50
  131. package/src/lib/version-checker.js +304 -50
  132. package/src/lib/web-fetch.js +292 -51
  133. package/src/lib/zkp-engine.js +286 -49
@@ -864,25 +864,53 @@ export function _resetState() {
864
864
  };
865
865
  }
866
866
 
867
-
868
867
  // ===== V2 Surface: DAO Governance overlay (CLI v0.136.0) =====
869
868
  export const DAO_ORG_MATURITY_V2 = Object.freeze({
870
- PENDING: "pending", ACTIVE: "active", PAUSED: "paused", DISSOLVED: "dissolved",
869
+ PENDING: "pending",
870
+ ACTIVE: "active",
871
+ PAUSED: "paused",
872
+ DISSOLVED: "dissolved",
871
873
  });
872
874
  export const DAO_PROPOSAL_LIFECYCLE_V2 = Object.freeze({
873
- QUEUED: "queued", VOTING: "voting", PASSED: "passed", FAILED: "failed", CANCELLED: "cancelled",
875
+ QUEUED: "queued",
876
+ VOTING: "voting",
877
+ PASSED: "passed",
878
+ FAILED: "failed",
879
+ CANCELLED: "cancelled",
874
880
  });
875
881
 
876
882
  const _daoOrgTrans = new Map([
877
- [DAO_ORG_MATURITY_V2.PENDING, new Set([DAO_ORG_MATURITY_V2.ACTIVE, DAO_ORG_MATURITY_V2.DISSOLVED])],
878
- [DAO_ORG_MATURITY_V2.ACTIVE, new Set([DAO_ORG_MATURITY_V2.PAUSED, DAO_ORG_MATURITY_V2.DISSOLVED])],
879
- [DAO_ORG_MATURITY_V2.PAUSED, new Set([DAO_ORG_MATURITY_V2.ACTIVE, DAO_ORG_MATURITY_V2.DISSOLVED])],
883
+ [
884
+ DAO_ORG_MATURITY_V2.PENDING,
885
+ new Set([DAO_ORG_MATURITY_V2.ACTIVE, DAO_ORG_MATURITY_V2.DISSOLVED]),
886
+ ],
887
+ [
888
+ DAO_ORG_MATURITY_V2.ACTIVE,
889
+ new Set([DAO_ORG_MATURITY_V2.PAUSED, DAO_ORG_MATURITY_V2.DISSOLVED]),
890
+ ],
891
+ [
892
+ DAO_ORG_MATURITY_V2.PAUSED,
893
+ new Set([DAO_ORG_MATURITY_V2.ACTIVE, DAO_ORG_MATURITY_V2.DISSOLVED]),
894
+ ],
880
895
  [DAO_ORG_MATURITY_V2.DISSOLVED, new Set()],
881
896
  ]);
882
897
  const _daoOrgTerminal = new Set([DAO_ORG_MATURITY_V2.DISSOLVED]);
883
898
  const _daoPropTrans = new Map([
884
- [DAO_PROPOSAL_LIFECYCLE_V2.QUEUED, new Set([DAO_PROPOSAL_LIFECYCLE_V2.VOTING, DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED])],
885
- [DAO_PROPOSAL_LIFECYCLE_V2.VOTING, new Set([DAO_PROPOSAL_LIFECYCLE_V2.PASSED, DAO_PROPOSAL_LIFECYCLE_V2.FAILED, DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED])],
899
+ [
900
+ DAO_PROPOSAL_LIFECYCLE_V2.QUEUED,
901
+ new Set([
902
+ DAO_PROPOSAL_LIFECYCLE_V2.VOTING,
903
+ DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED,
904
+ ]),
905
+ ],
906
+ [
907
+ DAO_PROPOSAL_LIFECYCLE_V2.VOTING,
908
+ new Set([
909
+ DAO_PROPOSAL_LIFECYCLE_V2.PASSED,
910
+ DAO_PROPOSAL_LIFECYCLE_V2.FAILED,
911
+ DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED,
912
+ ]),
913
+ ],
886
914
  [DAO_PROPOSAL_LIFECYCLE_V2.PASSED, new Set()],
887
915
  [DAO_PROPOSAL_LIFECYCLE_V2.FAILED, new Set()],
888
916
  [DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED, new Set()],
@@ -895,21 +923,45 @@ let _daoMaxPendingPerOrg = 50;
895
923
  let _daoOrgIdleMs = 7 * 24 * 60 * 60 * 1000;
896
924
  let _daoPropStuckMs = 2 * 60 * 1000;
897
925
 
898
- function _daoPos(n, lbl) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${lbl} must be positive integer`); return v; }
926
+ function _daoPos(n, lbl) {
927
+ const v = Math.floor(Number(n));
928
+ if (!Number.isFinite(v) || v <= 0)
929
+ throw new Error(`${lbl} must be positive integer`);
930
+ return v;
931
+ }
899
932
 
900
- export function setMaxActiveDaoOrgsPerOwnerV2(n) { _daoMaxActivePerOwner = _daoPos(n, "maxActiveDaoOrgsPerOwner"); }
901
- export function getMaxActiveDaoOrgsPerOwnerV2() { return _daoMaxActivePerOwner; }
902
- export function setMaxPendingDaoProposalsPerOrgV2(n) { _daoMaxPendingPerOrg = _daoPos(n, "maxPendingDaoProposalsPerOrg"); }
903
- export function getMaxPendingDaoProposalsPerOrgV2() { return _daoMaxPendingPerOrg; }
904
- export function setDaoOrgIdleMsV2(n) { _daoOrgIdleMs = _daoPos(n, "daoOrgIdleMs"); }
905
- export function getDaoOrgIdleMsV2() { return _daoOrgIdleMs; }
906
- export function setDaoProposalStuckMsV2(n) { _daoPropStuckMs = _daoPos(n, "daoProposalStuckMs"); }
907
- export function getDaoProposalStuckMsV2() { return _daoPropStuckMs; }
933
+ export function setMaxActiveDaoOrgsPerOwnerV2(n) {
934
+ _daoMaxActivePerOwner = _daoPos(n, "maxActiveDaoOrgsPerOwner");
935
+ }
936
+ export function getMaxActiveDaoOrgsPerOwnerV2() {
937
+ return _daoMaxActivePerOwner;
938
+ }
939
+ export function setMaxPendingDaoProposalsPerOrgV2(n) {
940
+ _daoMaxPendingPerOrg = _daoPos(n, "maxPendingDaoProposalsPerOrg");
941
+ }
942
+ export function getMaxPendingDaoProposalsPerOrgV2() {
943
+ return _daoMaxPendingPerOrg;
944
+ }
945
+ export function setDaoOrgIdleMsV2(n) {
946
+ _daoOrgIdleMs = _daoPos(n, "daoOrgIdleMs");
947
+ }
948
+ export function getDaoOrgIdleMsV2() {
949
+ return _daoOrgIdleMs;
950
+ }
951
+ export function setDaoProposalStuckMsV2(n) {
952
+ _daoPropStuckMs = _daoPos(n, "daoProposalStuckMs");
953
+ }
954
+ export function getDaoProposalStuckMsV2() {
955
+ return _daoPropStuckMs;
956
+ }
908
957
 
909
958
  export function _resetStateDaoGovernanceV2() {
910
- _daoOrgs.clear(); _daoProps.clear();
911
- _daoMaxActivePerOwner = 8; _daoMaxPendingPerOrg = 50;
912
- _daoOrgIdleMs = 7 * 24 * 60 * 60 * 1000; _daoPropStuckMs = 2 * 60 * 1000;
959
+ _daoOrgs.clear();
960
+ _daoProps.clear();
961
+ _daoMaxActivePerOwner = 8;
962
+ _daoMaxPendingPerOrg = 50;
963
+ _daoOrgIdleMs = 7 * 24 * 60 * 60 * 1000;
964
+ _daoPropStuckMs = 2 * 60 * 1000;
913
965
  }
914
966
 
915
967
  export function registerDaoOrgV2({ id, owner, name, metadata } = {}) {
@@ -917,28 +969,103 @@ export function registerDaoOrgV2({ id, owner, name, metadata } = {}) {
917
969
  if (!owner || typeof owner !== "string") throw new Error("owner is required");
918
970
  if (_daoOrgs.has(id)) throw new Error(`dao org ${id} already registered`);
919
971
  const now = Date.now();
920
- const o = { id, owner, name: name || id, status: DAO_ORG_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, dissolvedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
972
+ const o = {
973
+ id,
974
+ owner,
975
+ name: name || id,
976
+ status: DAO_ORG_MATURITY_V2.PENDING,
977
+ createdAt: now,
978
+ updatedAt: now,
979
+ activatedAt: null,
980
+ dissolvedAt: null,
981
+ lastTouchedAt: now,
982
+ metadata: { ...(metadata || {}) },
983
+ };
921
984
  _daoOrgs.set(id, o);
922
985
  return { ...o, metadata: { ...o.metadata } };
923
986
  }
924
- function _daoCheckO(from, to) { const a = _daoOrgTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid dao org transition ${from} → ${to}`); }
925
- function _daoCountActive(owner) { let n = 0; for (const o of _daoOrgs.values()) if (o.owner === owner && o.status === DAO_ORG_MATURITY_V2.ACTIVE) n++; return n; }
987
+ function _daoCheckO(from, to) {
988
+ const a = _daoOrgTrans.get(from);
989
+ if (!a || !a.has(to))
990
+ throw new Error(`invalid dao org transition ${from} → ${to}`);
991
+ }
992
+ function _daoCountActive(owner) {
993
+ let n = 0;
994
+ for (const o of _daoOrgs.values())
995
+ if (o.owner === owner && o.status === DAO_ORG_MATURITY_V2.ACTIVE) n++;
996
+ return n;
997
+ }
926
998
 
927
999
  export function activateDaoOrgV2(id) {
928
- const o = _daoOrgs.get(id); if (!o) throw new Error(`dao org ${id} not found`);
1000
+ const o = _daoOrgs.get(id);
1001
+ if (!o) throw new Error(`dao org ${id} not found`);
929
1002
  _daoCheckO(o.status, DAO_ORG_MATURITY_V2.ACTIVE);
930
1003
  const recovery = o.status === DAO_ORG_MATURITY_V2.PAUSED;
931
- if (!recovery) { const a = _daoCountActive(o.owner); if (a >= _daoMaxActivePerOwner) throw new Error(`max active dao orgs per owner (${_daoMaxActivePerOwner}) reached for ${o.owner}`); }
932
- const now = Date.now(); o.status = DAO_ORG_MATURITY_V2.ACTIVE; o.updatedAt = now; o.lastTouchedAt = now; if (!o.activatedAt) o.activatedAt = now;
1004
+ if (!recovery) {
1005
+ const a = _daoCountActive(o.owner);
1006
+ if (a >= _daoMaxActivePerOwner)
1007
+ throw new Error(
1008
+ `max active dao orgs per owner (${_daoMaxActivePerOwner}) reached for ${o.owner}`,
1009
+ );
1010
+ }
1011
+ const now = Date.now();
1012
+ o.status = DAO_ORG_MATURITY_V2.ACTIVE;
1013
+ o.updatedAt = now;
1014
+ o.lastTouchedAt = now;
1015
+ if (!o.activatedAt) o.activatedAt = now;
1016
+ return { ...o, metadata: { ...o.metadata } };
1017
+ }
1018
+ export function pauseDaoOrgV2(id) {
1019
+ const o = _daoOrgs.get(id);
1020
+ if (!o) throw new Error(`dao org ${id} not found`);
1021
+ _daoCheckO(o.status, DAO_ORG_MATURITY_V2.PAUSED);
1022
+ o.status = DAO_ORG_MATURITY_V2.PAUSED;
1023
+ o.updatedAt = Date.now();
1024
+ return { ...o, metadata: { ...o.metadata } };
1025
+ }
1026
+ export function dissolveDaoOrgV2(id) {
1027
+ const o = _daoOrgs.get(id);
1028
+ if (!o) throw new Error(`dao org ${id} not found`);
1029
+ _daoCheckO(o.status, DAO_ORG_MATURITY_V2.DISSOLVED);
1030
+ const now = Date.now();
1031
+ o.status = DAO_ORG_MATURITY_V2.DISSOLVED;
1032
+ o.updatedAt = now;
1033
+ if (!o.dissolvedAt) o.dissolvedAt = now;
1034
+ return { ...o, metadata: { ...o.metadata } };
1035
+ }
1036
+ export function touchDaoOrgV2(id) {
1037
+ const o = _daoOrgs.get(id);
1038
+ if (!o) throw new Error(`dao org ${id} not found`);
1039
+ if (_daoOrgTerminal.has(o.status))
1040
+ throw new Error(`cannot touch terminal dao org ${id}`);
1041
+ const now = Date.now();
1042
+ o.lastTouchedAt = now;
1043
+ o.updatedAt = now;
1044
+ return { ...o, metadata: { ...o.metadata } };
1045
+ }
1046
+ export function getDaoOrgV2(id) {
1047
+ const o = _daoOrgs.get(id);
1048
+ if (!o) return null;
933
1049
  return { ...o, metadata: { ...o.metadata } };
934
1050
  }
935
- export function pauseDaoOrgV2(id) { const o = _daoOrgs.get(id); if (!o) throw new Error(`dao org ${id} not found`); _daoCheckO(o.status, DAO_ORG_MATURITY_V2.PAUSED); o.status = DAO_ORG_MATURITY_V2.PAUSED; o.updatedAt = Date.now(); return { ...o, metadata: { ...o.metadata } }; }
936
- export function dissolveDaoOrgV2(id) { const o = _daoOrgs.get(id); if (!o) throw new Error(`dao org ${id} not found`); _daoCheckO(o.status, DAO_ORG_MATURITY_V2.DISSOLVED); const now = Date.now(); o.status = DAO_ORG_MATURITY_V2.DISSOLVED; o.updatedAt = now; if (!o.dissolvedAt) o.dissolvedAt = now; return { ...o, metadata: { ...o.metadata } }; }
937
- export function touchDaoOrgV2(id) { const o = _daoOrgs.get(id); if (!o) throw new Error(`dao org ${id} not found`); if (_daoOrgTerminal.has(o.status)) throw new Error(`cannot touch terminal dao org ${id}`); const now = Date.now(); o.lastTouchedAt = now; o.updatedAt = now; return { ...o, metadata: { ...o.metadata } }; }
938
- export function getDaoOrgV2(id) { const o = _daoOrgs.get(id); if (!o) return null; return { ...o, metadata: { ...o.metadata } }; }
939
- export function listDaoOrgsV2() { return [..._daoOrgs.values()].map((o) => ({ ...o, metadata: { ...o.metadata } })); }
1051
+ export function listDaoOrgsV2() {
1052
+ return [..._daoOrgs.values()].map((o) => ({
1053
+ ...o,
1054
+ metadata: { ...o.metadata },
1055
+ }));
1056
+ }
940
1057
 
941
- function _daoCountPending(oid) { let n = 0; for (const p of _daoProps.values()) if (p.orgId === oid && (p.status === DAO_PROPOSAL_LIFECYCLE_V2.QUEUED || p.status === DAO_PROPOSAL_LIFECYCLE_V2.VOTING)) n++; return n; }
1058
+ function _daoCountPending(oid) {
1059
+ let n = 0;
1060
+ for (const p of _daoProps.values())
1061
+ if (
1062
+ p.orgId === oid &&
1063
+ (p.status === DAO_PROPOSAL_LIFECYCLE_V2.QUEUED ||
1064
+ p.status === DAO_PROPOSAL_LIFECYCLE_V2.VOTING)
1065
+ )
1066
+ n++;
1067
+ return n;
1068
+ }
942
1069
 
943
1070
  export function createDaoProposalV2({ id, orgId, title, metadata } = {}) {
944
1071
  if (!id || typeof id !== "string") throw new Error("id is required");
@@ -946,25 +1073,132 @@ export function createDaoProposalV2({ id, orgId, title, metadata } = {}) {
946
1073
  if (_daoProps.has(id)) throw new Error(`dao proposal ${id} already exists`);
947
1074
  if (!_daoOrgs.has(orgId)) throw new Error(`dao org ${orgId} not found`);
948
1075
  const pending = _daoCountPending(orgId);
949
- if (pending >= _daoMaxPendingPerOrg) throw new Error(`max pending dao proposals per org (${_daoMaxPendingPerOrg}) reached for ${orgId}`);
1076
+ if (pending >= _daoMaxPendingPerOrg)
1077
+ throw new Error(
1078
+ `max pending dao proposals per org (${_daoMaxPendingPerOrg}) reached for ${orgId}`,
1079
+ );
950
1080
  const now = Date.now();
951
- const p = { id, orgId, title: title || id, status: DAO_PROPOSAL_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
1081
+ const p = {
1082
+ id,
1083
+ orgId,
1084
+ title: title || id,
1085
+ status: DAO_PROPOSAL_LIFECYCLE_V2.QUEUED,
1086
+ createdAt: now,
1087
+ updatedAt: now,
1088
+ startedAt: null,
1089
+ settledAt: null,
1090
+ metadata: { ...(metadata || {}) },
1091
+ };
952
1092
  _daoProps.set(id, p);
953
1093
  return { ...p, metadata: { ...p.metadata } };
954
1094
  }
955
- function _daoCheckP(from, to) { const a = _daoPropTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid dao proposal transition ${from} → ${to}`); }
956
- export function startDaoProposalV2(id) { const p = _daoProps.get(id); if (!p) throw new Error(`dao proposal ${id} not found`); _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.VOTING); const now = Date.now(); p.status = DAO_PROPOSAL_LIFECYCLE_V2.VOTING; p.updatedAt = now; if (!p.startedAt) p.startedAt = now; return { ...p, metadata: { ...p.metadata } }; }
957
- export function passDaoProposalV2(id) { const p = _daoProps.get(id); if (!p) throw new Error(`dao proposal ${id} not found`); _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.PASSED); const now = Date.now(); p.status = DAO_PROPOSAL_LIFECYCLE_V2.PASSED; p.updatedAt = now; if (!p.settledAt) p.settledAt = now; return { ...p, metadata: { ...p.metadata } }; }
958
- export function failDaoProposalV2(id, reason) { const p = _daoProps.get(id); if (!p) throw new Error(`dao proposal ${id} not found`); _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.FAILED); const now = Date.now(); p.status = DAO_PROPOSAL_LIFECYCLE_V2.FAILED; p.updatedAt = now; if (!p.settledAt) p.settledAt = now; if (reason) p.metadata.failReason = String(reason); return { ...p, metadata: { ...p.metadata } }; }
959
- export function cancelDaoProposalV2(id, reason) { const p = _daoProps.get(id); if (!p) throw new Error(`dao proposal ${id} not found`); _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED); const now = Date.now(); p.status = DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED; p.updatedAt = now; if (!p.settledAt) p.settledAt = now; if (reason) p.metadata.cancelReason = String(reason); return { ...p, metadata: { ...p.metadata } }; }
960
- export function getDaoProposalV2(id) { const p = _daoProps.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
961
- export function listDaoProposalsV2() { return [..._daoProps.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
1095
+ function _daoCheckP(from, to) {
1096
+ const a = _daoPropTrans.get(from);
1097
+ if (!a || !a.has(to))
1098
+ throw new Error(`invalid dao proposal transition ${from} ${to}`);
1099
+ }
1100
+ export function startDaoProposalV2(id) {
1101
+ const p = _daoProps.get(id);
1102
+ if (!p) throw new Error(`dao proposal ${id} not found`);
1103
+ _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.VOTING);
1104
+ const now = Date.now();
1105
+ p.status = DAO_PROPOSAL_LIFECYCLE_V2.VOTING;
1106
+ p.updatedAt = now;
1107
+ if (!p.startedAt) p.startedAt = now;
1108
+ return { ...p, metadata: { ...p.metadata } };
1109
+ }
1110
+ export function passDaoProposalV2(id) {
1111
+ const p = _daoProps.get(id);
1112
+ if (!p) throw new Error(`dao proposal ${id} not found`);
1113
+ _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.PASSED);
1114
+ const now = Date.now();
1115
+ p.status = DAO_PROPOSAL_LIFECYCLE_V2.PASSED;
1116
+ p.updatedAt = now;
1117
+ if (!p.settledAt) p.settledAt = now;
1118
+ return { ...p, metadata: { ...p.metadata } };
1119
+ }
1120
+ export function failDaoProposalV2(id, reason) {
1121
+ const p = _daoProps.get(id);
1122
+ if (!p) throw new Error(`dao proposal ${id} not found`);
1123
+ _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.FAILED);
1124
+ const now = Date.now();
1125
+ p.status = DAO_PROPOSAL_LIFECYCLE_V2.FAILED;
1126
+ p.updatedAt = now;
1127
+ if (!p.settledAt) p.settledAt = now;
1128
+ if (reason) p.metadata.failReason = String(reason);
1129
+ return { ...p, metadata: { ...p.metadata } };
1130
+ }
1131
+ export function cancelDaoProposalV2(id, reason) {
1132
+ const p = _daoProps.get(id);
1133
+ if (!p) throw new Error(`dao proposal ${id} not found`);
1134
+ _daoCheckP(p.status, DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED);
1135
+ const now = Date.now();
1136
+ p.status = DAO_PROPOSAL_LIFECYCLE_V2.CANCELLED;
1137
+ p.updatedAt = now;
1138
+ if (!p.settledAt) p.settledAt = now;
1139
+ if (reason) p.metadata.cancelReason = String(reason);
1140
+ return { ...p, metadata: { ...p.metadata } };
1141
+ }
1142
+ export function getDaoProposalV2(id) {
1143
+ const p = _daoProps.get(id);
1144
+ if (!p) return null;
1145
+ return { ...p, metadata: { ...p.metadata } };
1146
+ }
1147
+ export function listDaoProposalsV2() {
1148
+ return [..._daoProps.values()].map((p) => ({
1149
+ ...p,
1150
+ metadata: { ...p.metadata },
1151
+ }));
1152
+ }
962
1153
 
963
- export function autoPauseIdleDaoOrgsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const o of _daoOrgs.values()) if (o.status === DAO_ORG_MATURITY_V2.ACTIVE && (t - o.lastTouchedAt) >= _daoOrgIdleMs) { o.status = DAO_ORG_MATURITY_V2.PAUSED; o.updatedAt = t; flipped.push(o.id); } return { flipped, count: flipped.length }; }
964
- export function autoFailStuckDaoProposalsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _daoProps.values()) if (p.status === DAO_PROPOSAL_LIFECYCLE_V2.VOTING && p.startedAt != null && (t - p.startedAt) >= _daoPropStuckMs) { p.status = DAO_PROPOSAL_LIFECYCLE_V2.FAILED; p.updatedAt = t; if (!p.settledAt) p.settledAt = t; p.metadata.failReason = "auto-fail-stuck"; flipped.push(p.id); } return { flipped, count: flipped.length }; }
1154
+ export function autoPauseIdleDaoOrgsV2({ now } = {}) {
1155
+ const t = now ?? Date.now();
1156
+ const flipped = [];
1157
+ for (const o of _daoOrgs.values())
1158
+ if (
1159
+ o.status === DAO_ORG_MATURITY_V2.ACTIVE &&
1160
+ t - o.lastTouchedAt >= _daoOrgIdleMs
1161
+ ) {
1162
+ o.status = DAO_ORG_MATURITY_V2.PAUSED;
1163
+ o.updatedAt = t;
1164
+ flipped.push(o.id);
1165
+ }
1166
+ return { flipped, count: flipped.length };
1167
+ }
1168
+ export function autoFailStuckDaoProposalsV2({ now } = {}) {
1169
+ const t = now ?? Date.now();
1170
+ const flipped = [];
1171
+ for (const p of _daoProps.values())
1172
+ if (
1173
+ p.status === DAO_PROPOSAL_LIFECYCLE_V2.VOTING &&
1174
+ p.startedAt != null &&
1175
+ t - p.startedAt >= _daoPropStuckMs
1176
+ ) {
1177
+ p.status = DAO_PROPOSAL_LIFECYCLE_V2.FAILED;
1178
+ p.updatedAt = t;
1179
+ if (!p.settledAt) p.settledAt = t;
1180
+ p.metadata.failReason = "auto-fail-stuck";
1181
+ flipped.push(p.id);
1182
+ }
1183
+ return { flipped, count: flipped.length };
1184
+ }
965
1185
 
966
1186
  export function getDaoGovernanceGovStatsV2() {
967
- const orgsByStatus = {}; for (const s of Object.values(DAO_ORG_MATURITY_V2)) orgsByStatus[s] = 0; for (const o of _daoOrgs.values()) orgsByStatus[o.status]++;
968
- const proposalsByStatus = {}; for (const s of Object.values(DAO_PROPOSAL_LIFECYCLE_V2)) proposalsByStatus[s] = 0; for (const p of _daoProps.values()) proposalsByStatus[p.status]++;
969
- return { totalOrgsV2: _daoOrgs.size, totalProposalsV2: _daoProps.size, maxActiveDaoOrgsPerOwner: _daoMaxActivePerOwner, maxPendingDaoProposalsPerOrg: _daoMaxPendingPerOrg, daoOrgIdleMs: _daoOrgIdleMs, daoProposalStuckMs: _daoPropStuckMs, orgsByStatus, proposalsByStatus };
1187
+ const orgsByStatus = {};
1188
+ for (const s of Object.values(DAO_ORG_MATURITY_V2)) orgsByStatus[s] = 0;
1189
+ for (const o of _daoOrgs.values()) orgsByStatus[o.status]++;
1190
+ const proposalsByStatus = {};
1191
+ for (const s of Object.values(DAO_PROPOSAL_LIFECYCLE_V2))
1192
+ proposalsByStatus[s] = 0;
1193
+ for (const p of _daoProps.values()) proposalsByStatus[p.status]++;
1194
+ return {
1195
+ totalOrgsV2: _daoOrgs.size,
1196
+ totalProposalsV2: _daoProps.size,
1197
+ maxActiveDaoOrgsPerOwner: _daoMaxActivePerOwner,
1198
+ maxPendingDaoProposalsPerOrg: _daoMaxPendingPerOrg,
1199
+ daoOrgIdleMs: _daoOrgIdleMs,
1200
+ daoProposalStuckMs: _daoPropStuckMs,
1201
+ orgsByStatus,
1202
+ proposalsByStatus,
1203
+ };
970
1204
  }