@cstack-protocol/pingala 1.0.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 (328) hide show
  1. package/.agent/CSD.md +39 -0
  2. package/.agent/MANIFEST.md +4 -0
  3. package/.agent/MANIFEST.md.template +4 -0
  4. package/.agent/agent-contractor.md +45 -0
  5. package/.agent/architecture/consent-model-fsm.md +77 -0
  6. package/.agent/architecture/governor-maturity-fsm.md +101 -0
  7. package/.agent/architecture/governor-validation-fsm.md +106 -0
  8. package/.agent/architecture/humanized-audit-fsm.md +76 -0
  9. package/.agent/architecture/pingala-csi-fsm.md +81 -0
  10. package/.agent/architecture.md +34 -0
  11. package/.agent/behavior.md +29 -0
  12. package/.agent/compute.md +32 -0
  13. package/.agent/consent-prompts.md +41 -0
  14. package/.agent/governance.yaml +5 -0
  15. package/.agent/identity.md +29 -0
  16. package/.agent/knowledge-lattice.json +96 -0
  17. package/.agent/knowledge-lattice.md +53 -0
  18. package/.agent/lattice-viz.html +157 -0
  19. package/.agent/mission.md +37 -0
  20. package/.agent/pairing-protocol.md +89 -0
  21. package/.agent/pairing.csp +108 -0
  22. package/.agent/personas/reflective-operator.md +67 -0
  23. package/.agent/personas/research.md +62 -0
  24. package/.agent/pingala.md +47 -0
  25. package/.agent/roadmap.md +56 -0
  26. package/.agent/scripts/lattice-extract.py +100 -0
  27. package/.agent/scripts/sync-agents.sh +82 -0
  28. package/.agent/scripts/vault-ingest.py +80 -0
  29. package/.agent/seo-strategy.md +71 -0
  30. package/.agent/skills/agent-orchestrator/SKILL.md +22 -0
  31. package/.agent/skills/agent-orchestrator/scripts/sync-agents.sh +61 -0
  32. package/.agent/skills/knowledge-lattice/SKILL.md +23 -0
  33. package/.agent/skills/knowledge-lattice/scripts/lattice-extract.py +107 -0
  34. package/.agent/skills/resource-vault/SKILL.md +30 -0
  35. package/.agent/skills/resource-vault/scripts/vault-ingest.py +80 -0
  36. package/.agent/skills/sites-integrity/SKILL.md +28 -0
  37. package/.agent/skills/stack-auditor/SKILL.md +25 -0
  38. package/.agent/sources.md +20 -0
  39. package/.agent/stack-auditor.md +47 -0
  40. package/.agent/standards.md +36 -0
  41. package/.agent/strategy.md +65 -0
  42. package/.agent/vault-schema.md +53 -0
  43. package/.agent/voice.md +27 -0
  44. package/.agent/workflows/sync-agents.md +14 -0
  45. package/.env.example +5 -0
  46. package/.env.production +3 -0
  47. package/DISTRIBUTION-PLAN.md +33 -0
  48. package/HOSTED_SETUP.md +54 -0
  49. package/LANDING_PAGE_DESIGN.md +46 -0
  50. package/MANUAL_VERCEL_STEPS.md +39 -0
  51. package/PRODUCT-ROADMAP.md +241 -0
  52. package/PROVISIONING_GUIDE.md +39 -0
  53. package/README.md +38 -0
  54. package/ROADMAP.md +21 -0
  55. package/SYNC-ENGINE-SPEC.md +257 -0
  56. package/build/core/531-protocol.d.ts +26 -0
  57. package/build/core/531-protocol.js +87 -0
  58. package/build/core/531-protocol.js.map +1 -0
  59. package/build/core/531-rule.d.ts +26 -0
  60. package/build/core/531-rule.js +106 -0
  61. package/build/core/531-rule.js.map +1 -0
  62. package/build/core/auth.d.ts +1 -0
  63. package/build/core/auth.js +24 -0
  64. package/build/core/auth.js.map +1 -0
  65. package/build/core/consent-manager.d.ts +17 -0
  66. package/build/core/consent-manager.js +104 -0
  67. package/build/core/consent-manager.js.map +1 -0
  68. package/build/core/csp.d.ts +12 -0
  69. package/build/core/csp.js +20 -0
  70. package/build/core/csp.js.map +1 -0
  71. package/build/core/engagement-analyzer.d.ts +42 -0
  72. package/build/core/engagement-analyzer.js +71 -0
  73. package/build/core/engagement-analyzer.js.map +1 -0
  74. package/build/core/governor.d.ts +106 -0
  75. package/build/core/governor.js +405 -0
  76. package/build/core/governor.js.map +1 -0
  77. package/build/core/life-area-mapper.d.ts +39 -0
  78. package/build/core/life-area-mapper.js +73 -0
  79. package/build/core/life-area-mapper.js.map +1 -0
  80. package/build/core/methodology.d.ts +39 -0
  81. package/build/core/methodology.js +164 -0
  82. package/build/core/methodology.js.map +1 -0
  83. package/build/core/pingala.d.ts +31 -0
  84. package/build/core/pingala.js +56 -0
  85. package/build/core/pingala.js.map +1 -0
  86. package/build/core/sdk-adapter.d.ts +6 -0
  87. package/build/core/sdk-adapter.js +33 -0
  88. package/build/core/sdk-adapter.js.map +1 -0
  89. package/build/cs-agent-core/sdk/index.d.ts +6 -0
  90. package/build/cs-agent-core/sdk/index.js +18 -0
  91. package/build/cs-agent-core/sdk/index.js.map +1 -0
  92. package/build/cs-agent-core/sdk/patterns/index.d.ts +3 -0
  93. package/build/cs-agent-core/sdk/patterns/index.js +37 -0
  94. package/build/cs-agent-core/sdk/patterns/index.js.map +1 -0
  95. package/build/cs-agent-core/sdk/patterns/registry.d.ts +4 -0
  96. package/build/cs-agent-core/sdk/patterns/registry.js +80 -0
  97. package/build/cs-agent-core/sdk/patterns/registry.js.map +1 -0
  98. package/build/cs-agent-core/sdk/telemetry/buffer.d.ts +9 -0
  99. package/build/cs-agent-core/sdk/telemetry/buffer.js +47 -0
  100. package/build/cs-agent-core/sdk/telemetry/buffer.js.map +1 -0
  101. package/build/cs-agent-core/sdk/telemetry/scrubber.d.ts +3 -0
  102. package/build/cs-agent-core/sdk/telemetry/scrubber.js +13 -0
  103. package/build/cs-agent-core/sdk/telemetry/scrubber.js.map +1 -0
  104. package/build/cs-agent-core/sdk/telemetry/types.d.ts +50 -0
  105. package/build/cs-agent-core/sdk/telemetry/types.js +2 -0
  106. package/build/cs-agent-core/sdk/telemetry/types.js.map +1 -0
  107. package/build/cs-agent-core/sdk/types/decision.d.ts +18 -0
  108. package/build/cs-agent-core/sdk/types/decision.js +2 -0
  109. package/build/cs-agent-core/sdk/types/decision.js.map +1 -0
  110. package/build/cs-agent-core/sdk/types/index.d.ts +4 -0
  111. package/build/cs-agent-core/sdk/types/index.js +5 -0
  112. package/build/cs-agent-core/sdk/types/index.js.map +1 -0
  113. package/build/cs-agent-core/sdk/types/pattern.d.ts +17 -0
  114. package/build/cs-agent-core/sdk/types/pattern.js +2 -0
  115. package/build/cs-agent-core/sdk/types/pattern.js.map +1 -0
  116. package/build/cs-agent-core/sdk/types/stack.d.ts +8 -0
  117. package/build/cs-agent-core/sdk/types/stack.js +2 -0
  118. package/build/cs-agent-core/sdk/types/stack.js.map +1 -0
  119. package/build/cs-agent-core/sdk/types/tool.d.ts +9 -0
  120. package/build/cs-agent-core/sdk/types/tool.js +2 -0
  121. package/build/cs-agent-core/sdk/types/tool.js.map +1 -0
  122. package/build/cs-agent-core/sdk/validator/csi.d.ts +2 -0
  123. package/build/cs-agent-core/sdk/validator/csi.js +24 -0
  124. package/build/cs-agent-core/sdk/validator/csi.js.map +1 -0
  125. package/build/cs-agent-core/sdk/validator/index.d.ts +2 -0
  126. package/build/cs-agent-core/sdk/validator/index.js +3 -0
  127. package/build/cs-agent-core/sdk/validator/index.js.map +1 -0
  128. package/build/cs-agent-core/sdk/validator/rules/geometry.d.ts +11 -0
  129. package/build/cs-agent-core/sdk/validator/rules/geometry.js +22 -0
  130. package/build/cs-agent-core/sdk/validator/rules/geometry.js.map +1 -0
  131. package/build/cs-agent-core/sdk/validator/validate.d.ts +2 -0
  132. package/build/cs-agent-core/sdk/validator/validate.js +46 -0
  133. package/build/cs-agent-core/sdk/validator/validate.js.map +1 -0
  134. package/build/index.d.ts +2 -0
  135. package/build/index.js +444 -0
  136. package/build/index.js.map +1 -0
  137. package/build/pingala-mcp/src/core/531-rule.d.ts +26 -0
  138. package/build/pingala-mcp/src/core/531-rule.js +96 -0
  139. package/build/pingala-mcp/src/core/531-rule.js.map +1 -0
  140. package/build/pingala-mcp/src/core/auth.d.ts +1 -0
  141. package/build/pingala-mcp/src/core/auth.js +15 -0
  142. package/build/pingala-mcp/src/core/auth.js.map +1 -0
  143. package/build/pingala-mcp/src/core/consent-manager.d.ts +17 -0
  144. package/build/pingala-mcp/src/core/consent-manager.js +104 -0
  145. package/build/pingala-mcp/src/core/consent-manager.js.map +1 -0
  146. package/build/pingala-mcp/src/core/csp.d.ts +12 -0
  147. package/build/pingala-mcp/src/core/csp.js +20 -0
  148. package/build/pingala-mcp/src/core/csp.js.map +1 -0
  149. package/build/pingala-mcp/src/core/engagement-analyzer.d.ts +42 -0
  150. package/build/pingala-mcp/src/core/engagement-analyzer.js +71 -0
  151. package/build/pingala-mcp/src/core/engagement-analyzer.js.map +1 -0
  152. package/build/pingala-mcp/src/core/governor.d.ts +104 -0
  153. package/build/pingala-mcp/src/core/governor.js +359 -0
  154. package/build/pingala-mcp/src/core/governor.js.map +1 -0
  155. package/build/pingala-mcp/src/core/life-area-mapper.d.ts +39 -0
  156. package/build/pingala-mcp/src/core/life-area-mapper.js +73 -0
  157. package/build/pingala-mcp/src/core/life-area-mapper.js.map +1 -0
  158. package/build/pingala-mcp/src/core/methodology.d.ts +39 -0
  159. package/build/pingala-mcp/src/core/methodology.js +164 -0
  160. package/build/pingala-mcp/src/core/methodology.js.map +1 -0
  161. package/build/pingala-mcp/src/core/pingala.d.ts +25 -0
  162. package/build/pingala-mcp/src/core/pingala.js +56 -0
  163. package/build/pingala-mcp/src/core/pingala.js.map +1 -0
  164. package/build/pingala-mcp/src/core/sdk-adapter.d.ts +6 -0
  165. package/build/pingala-mcp/src/core/sdk-adapter.js +33 -0
  166. package/build/pingala-mcp/src/core/sdk-adapter.js.map +1 -0
  167. package/build/pingala-mcp/src/index.d.ts +1 -0
  168. package/build/pingala-mcp/src/index.js +221 -0
  169. package/build/pingala-mcp/src/index.js.map +1 -0
  170. package/build/pingala-mcp/src/test-l3.d.ts +1 -0
  171. package/build/pingala-mcp/src/test-l3.js +35 -0
  172. package/build/pingala-mcp/src/test-l3.js.map +1 -0
  173. package/build/pingala-mcp/src/tools/audit-workspace.d.ts +16 -0
  174. package/build/pingala-mcp/src/tools/audit-workspace.js +39 -0
  175. package/build/pingala-mcp/src/tools/audit-workspace.js.map +1 -0
  176. package/build/pingala-mcp/src/tools/calculate-csi.d.ts +24 -0
  177. package/build/pingala-mcp/src/tools/calculate-csi.js +29 -0
  178. package/build/pingala-mcp/src/tools/calculate-csi.js.map +1 -0
  179. package/build/pingala-mcp/src/tools/cs-audit.d.ts +54 -0
  180. package/build/pingala-mcp/src/tools/cs-audit.js +310 -0
  181. package/build/pingala-mcp/src/tools/cs-audit.js.map +1 -0
  182. package/build/pingala-mcp/src/tools/get-governance-context.d.ts +11 -0
  183. package/build/pingala-mcp/src/tools/get-governance-context.js +16 -0
  184. package/build/pingala-mcp/src/tools/get-governance-context.js.map +1 -0
  185. package/build/pingala-mcp/src/tools/validate-stack-change.d.ts +41 -0
  186. package/build/pingala-mcp/src/tools/validate-stack-change.js +35 -0
  187. package/build/pingala-mcp/src/tools/validate-stack-change.js.map +1 -0
  188. package/build/sdk/index.d.ts +6 -0
  189. package/build/sdk/index.js +18 -0
  190. package/build/sdk/index.js.map +1 -0
  191. package/build/sdk/patterns/index.d.ts +3 -0
  192. package/build/sdk/patterns/index.js +37 -0
  193. package/build/sdk/patterns/index.js.map +1 -0
  194. package/build/sdk/patterns/registry.d.ts +4 -0
  195. package/build/sdk/patterns/registry.js +80 -0
  196. package/build/sdk/patterns/registry.js.map +1 -0
  197. package/build/sdk/telemetry/buffer.d.ts +9 -0
  198. package/build/sdk/telemetry/buffer.js +47 -0
  199. package/build/sdk/telemetry/buffer.js.map +1 -0
  200. package/build/sdk/telemetry/scrubber.d.ts +3 -0
  201. package/build/sdk/telemetry/scrubber.js +13 -0
  202. package/build/sdk/telemetry/scrubber.js.map +1 -0
  203. package/build/sdk/telemetry/types.d.ts +50 -0
  204. package/build/sdk/telemetry/types.js +2 -0
  205. package/build/sdk/telemetry/types.js.map +1 -0
  206. package/build/sdk/types/decision.d.ts +18 -0
  207. package/build/sdk/types/decision.js +2 -0
  208. package/build/sdk/types/decision.js.map +1 -0
  209. package/build/sdk/types/index.d.ts +4 -0
  210. package/build/sdk/types/index.js +5 -0
  211. package/build/sdk/types/index.js.map +1 -0
  212. package/build/sdk/types/pattern.d.ts +17 -0
  213. package/build/sdk/types/pattern.js +2 -0
  214. package/build/sdk/types/pattern.js.map +1 -0
  215. package/build/sdk/types/stack.d.ts +8 -0
  216. package/build/sdk/types/stack.js +2 -0
  217. package/build/sdk/types/stack.js.map +1 -0
  218. package/build/sdk/types/tool.d.ts +9 -0
  219. package/build/sdk/types/tool.js +2 -0
  220. package/build/sdk/types/tool.js.map +1 -0
  221. package/build/sdk/validator/csi.d.ts +2 -0
  222. package/build/sdk/validator/csi.js +24 -0
  223. package/build/sdk/validator/csi.js.map +1 -0
  224. package/build/sdk/validator/index.d.ts +2 -0
  225. package/build/sdk/validator/index.js +3 -0
  226. package/build/sdk/validator/index.js.map +1 -0
  227. package/build/sdk/validator/rules/geometry.d.ts +11 -0
  228. package/build/sdk/validator/rules/geometry.js +22 -0
  229. package/build/sdk/validator/rules/geometry.js.map +1 -0
  230. package/build/sdk/validator/validate.d.ts +2 -0
  231. package/build/sdk/validator/validate.js +46 -0
  232. package/build/sdk/validator/validate.js.map +1 -0
  233. package/build/src/core/531-rule.d.ts +26 -0
  234. package/build/src/core/531-rule.js +96 -0
  235. package/build/src/core/531-rule.js.map +1 -0
  236. package/build/src/core/auth.d.ts +1 -0
  237. package/build/src/core/auth.js +15 -0
  238. package/build/src/core/auth.js.map +1 -0
  239. package/build/src/core/consent-manager.d.ts +17 -0
  240. package/build/src/core/consent-manager.js +104 -0
  241. package/build/src/core/consent-manager.js.map +1 -0
  242. package/build/src/core/csp.d.ts +12 -0
  243. package/build/src/core/csp.js +20 -0
  244. package/build/src/core/csp.js.map +1 -0
  245. package/build/src/core/engagement-analyzer.d.ts +42 -0
  246. package/build/src/core/engagement-analyzer.js +71 -0
  247. package/build/src/core/engagement-analyzer.js.map +1 -0
  248. package/build/src/core/governor.d.ts +104 -0
  249. package/build/src/core/governor.js +371 -0
  250. package/build/src/core/governor.js.map +1 -0
  251. package/build/src/core/life-area-mapper.d.ts +39 -0
  252. package/build/src/core/life-area-mapper.js +73 -0
  253. package/build/src/core/life-area-mapper.js.map +1 -0
  254. package/build/src/core/methodology.d.ts +39 -0
  255. package/build/src/core/methodology.js +164 -0
  256. package/build/src/core/methodology.js.map +1 -0
  257. package/build/src/core/pingala.d.ts +25 -0
  258. package/build/src/core/pingala.js +56 -0
  259. package/build/src/core/pingala.js.map +1 -0
  260. package/build/src/core/sdk-adapter.d.ts +8 -0
  261. package/build/src/core/sdk-adapter.js +34 -0
  262. package/build/src/core/sdk-adapter.js.map +1 -0
  263. package/build/src/index.d.ts +2 -0
  264. package/build/src/index.js +333 -0
  265. package/build/src/index.js.map +1 -0
  266. package/build/src/test-l3.d.ts +1 -0
  267. package/build/src/test-l3.js +35 -0
  268. package/build/src/test-l3.js.map +1 -0
  269. package/build/src/tools/audit-workspace.d.ts +16 -0
  270. package/build/src/tools/audit-workspace.js +39 -0
  271. package/build/src/tools/audit-workspace.js.map +1 -0
  272. package/build/src/tools/calculate-csi.d.ts +24 -0
  273. package/build/src/tools/calculate-csi.js +29 -0
  274. package/build/src/tools/calculate-csi.js.map +1 -0
  275. package/build/src/tools/cs-audit.d.ts +54 -0
  276. package/build/src/tools/cs-audit.js +310 -0
  277. package/build/src/tools/cs-audit.js.map +1 -0
  278. package/build/src/tools/get-governance-context.d.ts +11 -0
  279. package/build/src/tools/get-governance-context.js +16 -0
  280. package/build/src/tools/get-governance-context.js.map +1 -0
  281. package/build/src/tools/validate-stack-change.d.ts +41 -0
  282. package/build/src/tools/validate-stack-change.js +35 -0
  283. package/build/src/tools/validate-stack-change.js.map +1 -0
  284. package/build/test-l3.d.ts +1 -0
  285. package/build/test-l3.js +35 -0
  286. package/build/test-l3.js.map +1 -0
  287. package/build/tools/analyze-stack.d.ts +40 -0
  288. package/build/tools/analyze-stack.js +121 -0
  289. package/build/tools/analyze-stack.js.map +1 -0
  290. package/build/tools/audit-workspace.d.ts +16 -0
  291. package/build/tools/audit-workspace.js +39 -0
  292. package/build/tools/audit-workspace.js.map +1 -0
  293. package/build/tools/calculate-csi.d.ts +26 -0
  294. package/build/tools/calculate-csi.js +30 -0
  295. package/build/tools/calculate-csi.js.map +1 -0
  296. package/build/tools/cs-audit.d.ts +43 -0
  297. package/build/tools/cs-audit.js +330 -0
  298. package/build/tools/cs-audit.js.map +1 -0
  299. package/build/tools/get-governance-context.d.ts +11 -0
  300. package/build/tools/get-governance-context.js +61 -0
  301. package/build/tools/get-governance-context.js.map +1 -0
  302. package/build/tools/validate-stack-change.d.ts +41 -0
  303. package/build/tools/validate-stack-change.js +54 -0
  304. package/build/tools/validate-stack-change.js.map +1 -0
  305. package/package.json +34 -0
  306. package/scripts/cloud-bridge.js +62 -0
  307. package/scripts/generate-token.js +13 -0
  308. package/src/core/531-rule.ts +148 -0
  309. package/src/core/auth.ts +42 -0
  310. package/src/core/consent-manager.ts +134 -0
  311. package/src/core/csp.ts +40 -0
  312. package/src/core/engagement-analyzer.ts +122 -0
  313. package/src/core/governor.ts +522 -0
  314. package/src/core/life-area-mapper.ts +138 -0
  315. package/src/core/methodology.ts +256 -0
  316. package/src/core/pingala.ts +77 -0
  317. package/src/core/sdk-adapter.ts +52 -0
  318. package/src/index.ts +562 -0
  319. package/src/test-l3.ts +45 -0
  320. package/src/tools/analyze-stack.ts +153 -0
  321. package/src/tools/audit-workspace.ts +50 -0
  322. package/src/tools/calculate-csi.ts +38 -0
  323. package/src/tools/cs-audit.ts +384 -0
  324. package/src/tools/get-governance-context.ts +69 -0
  325. package/src/tools/validate-stack-change.ts +71 -0
  326. package/src/types.d.ts +2 -0
  327. package/tsconfig.json +40 -0
  328. package/vercel.json +15 -0
@@ -0,0 +1,256 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import process from "node:process";
4
+
5
+ /**
6
+ * Methodology Loader: Runtime consumer of cs-agent-core definitions.
7
+ *
8
+ * Source Priority:
9
+ * 1. CSTACK_AGENT_CORE_PATH (Creator Mode - local path)
10
+ * 2. CSTACK_API_KEY (Public Mode - fetch from API, TODO)
11
+ * 3. Hardcoded fallback (resilience)
12
+ */
13
+
14
+ export interface CSIPillar {
15
+ name: string;
16
+ description: string;
17
+ weight: number;
18
+ }
19
+
20
+ export interface Protocol531Rules {
21
+ maxTools: number;
22
+ anchorCount: number;
23
+ activeCount: number;
24
+ supportingCount: number;
25
+ rawDescription?: string; // e.g. "1 Anchor, 3 Active, 5 Supporting"
26
+ }
27
+
28
+ export interface BaguaCategory {
29
+ name: string;
30
+ description: string;
31
+ userFacingLabel?: string;
32
+ }
33
+
34
+ export interface InnerDiamondCategory {
35
+ name: string;
36
+ description: string;
37
+ userFacingLabel?: string;
38
+ }
39
+
40
+ export interface ConsentPrompts {
41
+ l2: string;
42
+ l3: string;
43
+ }
44
+
45
+ export class MethodologyLoader {
46
+ private static basePath: string | null = null;
47
+ private static apiKey: string | null = null;
48
+
49
+ /**
50
+ * Initialize the loader by detecting the methodology source.
51
+ */
52
+ static init(): void {
53
+ this.basePath = process.env.CSTACK_AGENT_CORE_PATH || null;
54
+ this.apiKey = process.env.CSTACK_API_KEY || null;
55
+
56
+ if (this.basePath) {
57
+ console.error(`[MethodologyLoader] Creator Mode: Loading from ${this.basePath}`);
58
+ } else if (this.apiKey) {
59
+ console.error(`[MethodologyLoader] Public Mode: API key detected (API fetch TODO)`);
60
+ } else {
61
+ console.error(`[MethodologyLoader] Fallback Mode: Using hardcoded defaults`);
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Load CSI Pillars from stack-auditor.md or fallback.
67
+ */
68
+ static loadCSIPillars(): CSIPillar[] {
69
+ if (this.basePath) {
70
+ const filePath = path.join(this.basePath, "stack-auditor.md");
71
+ if (fs.existsSync(filePath)) {
72
+ // Parse from file (simplified for MVP)
73
+ // TODO: Proper markdown parsing
74
+ return this.parseCSIPillarsFromFile(filePath);
75
+ }
76
+ }
77
+
78
+ // Hardcoded fallback (from stack-auditor.md - CSI-Lite)
79
+ return [
80
+ { name: "Attention Depth (AD)", description: "Quality of deep work and focus (0–100)", weight: 0.35 },
81
+ { name: "Dependency Exposure (DE)", description: "Workflow independence from non-sovereign AI (0–100)", weight: 0.35 },
82
+ { name: "Decision Provenance (DP)", description: "Rationale clarity and protocol adherence (0–100)", weight: 0.30 },
83
+ { name: "Alignment (SAS)", description: "Adherence to CSP (5:3:1 Node) constraints", weight: 0.00 } // Alignment score is secondary
84
+ ];
85
+ }
86
+
87
+ /**
88
+ * Load 5:3:1 Rule constraints from identity.md or stack-auditor.md.
89
+ */
90
+ static load531Rules(): Protocol531Rules {
91
+ const defaults: Protocol531Rules = {
92
+ maxTools: 9,
93
+ anchorCount: 1,
94
+ activeCount: 3,
95
+ supportingCount: 5,
96
+ rawDescription: "1 Anchor, 3 Active, 5 Supporting"
97
+ };
98
+
99
+ if (this.basePath) {
100
+ const identityPath = path.join(this.basePath, "identity.md");
101
+ if (fs.existsSync(identityPath)) {
102
+ try {
103
+ const content = fs.readFileSync(identityPath, "utf-8");
104
+ const match = content.match(/\d+:\d+:\d+ Rule.*?\((.*?)\)/i);
105
+ if (match && match[1]) {
106
+ const desc = match[1]; // e.g. "1 Anchor, 3 Active tools, 5 Support elements"
107
+ return {
108
+ ...defaults,
109
+ rawDescription: desc
110
+ };
111
+ }
112
+ } catch (e) {
113
+ console.error("[MethodologyLoader] Error parsing 531 rules:", e);
114
+ }
115
+ }
116
+ }
117
+
118
+ return defaults;
119
+ }
120
+
121
+ /**
122
+ * Load Bāguà categories from architecture.md or fallback.
123
+ */
124
+ static loadBaguaCategories(): BaguaCategory[] {
125
+ if (this.basePath) {
126
+ const filePath = path.join(this.basePath, "architecture.md");
127
+ if (fs.existsSync(filePath)) {
128
+ return this.parseBaguaCategoriesFromFile(filePath);
129
+ }
130
+ }
131
+
132
+ // Hardcoded fallback
133
+ return [
134
+ { name: "Li", description: "Fame, reputation, how one is seen by the world.", userFacingLabel: "Social Connection & Visibility" },
135
+ { name: "Kun", description: "Love, partnerships, and intimate energy management.", userFacingLabel: "Relationships & Self-Care" },
136
+ { name: "Dui", description: "Creativity, joy, projects, and the 'inner child.'", userFacingLabel: "Creative Expression & Hobbies" },
137
+ { name: "Qian", description: "Helpful people, travel, and external systems.", userFacingLabel: "Communication & Networking" },
138
+ { name: "Kan", description: "Life path, professional trajectory, and deep purpose.", userFacingLabel: "Career & Goals" },
139
+ { name: "Gen", description: "Self-cultivation, knowledge, and wisdom building.", userFacingLabel: "Learning & Growth" },
140
+ { name: "Zhen", description: "Ancestry, fundamental support systems, and family.", userFacingLabel: "Family & Roots" },
141
+ { name: "Xun", description: "Wealth, abundance, and resource flow.", userFacingLabel: "Financial Management" },
142
+ { name: "Tai Ji", description: "The 'Operating System,' physical health, and core stability.", userFacingLabel: "Physical Health & Routines" }
143
+ ];
144
+ }
145
+
146
+ /**
147
+ * Load Inner Diamond categories for L3.
148
+ */
149
+ static loadInnerDiamondCategories(): InnerDiamondCategory[] {
150
+ // For now, these are not in architecture.md usually, so we use fallback
151
+ return [
152
+ { name: "Identity", description: "How your digital choices reflect who you are becoming.", userFacingLabel: "Identity Reflection" },
153
+ { name: "Purpose", description: "Alignment between your daily actions and your sovereign mission.", userFacingLabel: "Purpose Alignment" },
154
+ { name: "Sovereignty", description: "Your capacity to act independently of algorithmic nudge.", userFacingLabel: "Sovereignty Forecast" }
155
+ ];
156
+ }
157
+
158
+ /**
159
+ * Load Consent Prompts from consent-prompts.md.
160
+ */
161
+ static loadConsentPrompts(): ConsentPrompts {
162
+ const defaults: ConsentPrompts = {
163
+ l2: "Would you like me to include a life balance view?",
164
+ l3: "Want to explore your inner operating system?"
165
+ };
166
+
167
+ if (this.basePath) {
168
+ const filePath = path.join(this.basePath, "consent-prompts.md");
169
+ if (fs.existsSync(filePath)) {
170
+ try {
171
+ const content = fs.readFileSync(filePath, "utf-8");
172
+ const l2Match = content.match(/## Level 2.*?Prompt:\s*> "(.*?)"/s);
173
+ const l3Match = content.match(/## Level 3.*?Prompt:\s*> "(.*?)"/s);
174
+ return {
175
+ l2: l2Match ? l2Match[1].trim() : defaults.l2,
176
+ l3: l3Match ? l3Match[1].trim() : defaults.l3
177
+ };
178
+ } catch (e) {
179
+ console.error("[MethodologyLoader] Error parsing consent prompts:", e);
180
+ }
181
+ }
182
+ }
183
+
184
+ return defaults;
185
+ }
186
+
187
+ /**
188
+ * Parse CSI pillars from a markdown file.
189
+ * Simplified parser for MVP.
190
+ */
191
+ private static parseCSIPillarsFromFile(filePath: string): CSIPillar[] {
192
+ try {
193
+ const content = fs.readFileSync(filePath, "utf-8");
194
+
195
+ // Look for the CSI section (simplified pattern matching)
196
+ const csiMatch = content.match(/### Step 3: Compute CSI[\s\S]*?(?=###|$)/);
197
+ if (!csiMatch) {
198
+ return this.loadCSIPillars(); // Fallback
199
+ }
200
+
201
+ const pillars: CSIPillar[] = [];
202
+ const pillarPattern = /\d+\.\s*\*\*(\w+)\*\*:\s*(.+)/g;
203
+ let match;
204
+
205
+ while ((match = pillarPattern.exec(csiMatch[0])) !== null) {
206
+ pillars.push({
207
+ name: match[1],
208
+ description: match[2].trim(),
209
+ weight: 0.25 // Equal weight for now
210
+ });
211
+ }
212
+
213
+ return pillars.length > 0 ? pillars : this.loadCSIPillars();
214
+ } catch {
215
+ return this.loadCSIPillars();
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Parse Bagua categories from architecture.md.
221
+ */
222
+ private static parseBaguaCategoriesFromFile(filePath: string): BaguaCategory[] {
223
+ try {
224
+ const content = fs.readFileSync(filePath, "utf-8");
225
+ const categories: BaguaCategory[] = [];
226
+
227
+ // Match table rows: | Li | Social Connection & Visibility | Description... |
228
+ const tablePattern = /\|\s*\*\*?(\w+)\*\*?\s*\|\s*([^|]+)\s*\|\s*([^|]+)\s*\|/g;
229
+ let match;
230
+
231
+ while ((match = tablePattern.exec(content)) !== null) {
232
+ categories.push({
233
+ name: match[1],
234
+ userFacingLabel: match[2].trim(),
235
+ description: match[3].trim()
236
+ });
237
+ }
238
+
239
+ return categories.length > 0 ? categories : this.loadBaguaCategories();
240
+ } catch {
241
+ return this.loadBaguaCategories();
242
+ }
243
+ }
244
+
245
+ /**
246
+ * Check if methodology source is available.
247
+ */
248
+ static getSourceMode(): "creator" | "api" | "fallback" {
249
+ if (this.basePath) return "creator";
250
+ if (this.apiKey) return "api";
251
+ return "fallback";
252
+ }
253
+ }
254
+
255
+ // Initialize on module load
256
+ MethodologyLoader.init();
@@ -0,0 +1,77 @@
1
+ import { Rule531 } from './531-rule.js';
2
+ import { MethodologyLoader } from './methodology.js';
3
+ import { Governor } from './governor.js';
4
+ import type { StackConfiguration } from './531-rule.js';
5
+ import { EngagementAnalyzer } from './engagement-analyzer.js';
6
+
7
+ import { performSDKValidation } from './sdk-adapter.js';
8
+
9
+ /**
10
+ * Pingala Engine: The "Governor" intelligence.
11
+ * Responsible for high-level diagnosis and Conscious Stack Index (CSI) computation.
12
+ */
13
+ export interface DiagnoseOptions extends StackConfiguration {
14
+ scores?: {
15
+ attention_depth: number;
16
+ dependency_exposure: number;
17
+ };
18
+ }
19
+
20
+ export class PingalaEngine {
21
+ /**
22
+ * Diagnoses a workspace and computes the CSI using CSI-Lite pillars.
23
+ */
24
+ static async diagnose(config: DiagnoseOptions) {
25
+ // Run SDK Validation (Patterns, 5:3:1, CSI)
26
+ const sdkResult = await performSDKValidation(config.tools);
27
+
28
+ const sourceMode = MethodologyLoader.getSourceMode();
29
+ const state = Governor.getMaturityState();
30
+
31
+ // CSI Pillars (Augmented with SDK data, supporting stateless overrides)
32
+ const ad = config.scores?.attention_depth ?? state.telemetry?.attention_depth ?? 50;
33
+ const de = config.scores?.dependency_exposure ?? state.telemetry?.dependency_exposure ?? 50;
34
+ const dp = Governor.getDecisionProvenanceScore();
35
+ const fs = EngagementAnalyzer.getFragmentationScore(config.tools);
36
+
37
+ // Blend Pingala's internal scoring with SDK's logic-based CSI
38
+ const blendedCsi = Math.round((sdkResult.csi * 0.7) + (fs * 0.3));
39
+
40
+ Governor.updateCsi(blendedCsi);
41
+
42
+ return {
43
+ engine: "Pingala v0.3.0 (Powered by CSTACK SDK)",
44
+ methodology_source: sourceMode,
45
+ csi_score: blendedCsi,
46
+ pillars: {
47
+ attention_depth: ad,
48
+ dependency_exposure: de,
49
+ decision_provenance: dp,
50
+ fragmentation_score: fs
51
+ },
52
+ risk_band: this.getRiskBand(blendedCsi),
53
+ status: this.getStatusLabel(blendedCsi),
54
+ protocol_analysis: {
55
+ isValid: sdkResult.status === 'approved',
56
+ score: sdkResult.csi,
57
+ violations: sdkResult.violations.map(v => `${v.name}: ${v.description}`),
58
+ recommendations: sdkResult.recommendations
59
+ },
60
+ attribution: "CSI framework powered by the Conscious Stack Protocol (CSP) Registry."
61
+ };
62
+ }
63
+
64
+ static getRiskBand(csi: number): string {
65
+ if (csi >= 85) return "safe";
66
+ if (csi >= 70) return "stable";
67
+ if (csi >= 50) return "erosion";
68
+ return "system_risk";
69
+ }
70
+
71
+ private static getStatusLabel(score: number): string {
72
+ if (score >= 85) return "Sovereign Resonance";
73
+ if (score >= 70) return "Aligned Flow";
74
+ if (score >= 50) return "Congested Flux";
75
+ return "Conscious Debt Crisis";
76
+ }
77
+ }
@@ -0,0 +1,52 @@
1
+ import { ToolInstance } from './531-rule.js';
2
+ import { validate as sdkValidate, initTelemetry as sdkInitTelemetry } from '@cstack-protocol/sdk';
3
+ import type { StackProfile, Tool, StackRole } from '@cstack-protocol/sdk';
4
+
5
+ /**
6
+ * Maps Pingala's ToolInstance to the SDK's Tool schema.
7
+ * Handles the casing and naming differences in roles.
8
+ */
9
+ function mapRole(role: string): StackRole {
10
+ switch (role) {
11
+ case 'Anchor': return 'anchor';
12
+ case 'Active': return 'utility';
13
+ case 'Supporting': return 'periphery';
14
+ default: return 'periphery';
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Converts Pingala's internal tool list to an SDK-compatible StackProfile.
20
+ */
21
+ export function mapToSDK(tools: ToolInstance[], operatorId?: string): StackProfile {
22
+ return {
23
+ id: `pingala-${Date.now()}`,
24
+ operatorId: operatorId || 'anonymous-pingala',
25
+ tools: tools.map((t, idx) => ({
26
+ id: t.functionId || `t-${idx}`,
27
+ name: t.name,
28
+ category: t.category,
29
+ role: mapRole(t.role)
30
+ })),
31
+ createdAt: new Date(),
32
+ updatedAt: new Date()
33
+ };
34
+ }
35
+
36
+ /**
37
+ * Bridge for the validation logic.
38
+ * Wraps the SDK's async validate() for use within Pingala's diagnostic loop.
39
+ */
40
+ export async function performSDKValidation(tools: ToolInstance[], operatorId?: string) {
41
+ const profile = mapToSDK(tools, operatorId);
42
+ return await sdkValidate(profile);
43
+ }
44
+
45
+ /**
46
+ * Initializes the telemetry system for Pingala.
47
+ */
48
+ export function initPingalaTelemetry(consentTier: 'observer' | 'contributor' | 'sentinel' = 'contributor') {
49
+ sdkInitTelemetry({ consentTier });
50
+ console.log(`🛡️ Pingala: Telemetry initialized with tier: ${consentTier}`);
51
+ }
52
+ export { getRegistryMode, flushTelemetry } from '@cstack-protocol/sdk';