apcore-js 0.5.0 → 0.6.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 (314) hide show
  1. package/dist/acl.d.ts +27 -0
  2. package/dist/acl.d.ts.map +1 -0
  3. package/dist/acl.js +175 -0
  4. package/dist/acl.js.map +1 -0
  5. package/dist/async-task.d.ts +90 -0
  6. package/dist/async-task.d.ts.map +1 -0
  7. package/dist/async-task.js +215 -0
  8. package/dist/async-task.js.map +1 -0
  9. package/dist/bindings.d.ts +12 -0
  10. package/dist/bindings.d.ts.map +1 -0
  11. package/dist/bindings.js +185 -0
  12. package/dist/bindings.js.map +1 -0
  13. package/dist/cancel.d.ts +14 -0
  14. package/dist/cancel.d.ts.map +1 -0
  15. package/dist/cancel.js +27 -0
  16. package/dist/cancel.js.map +1 -0
  17. package/dist/config.d.ts +9 -0
  18. package/dist/config.d.ts.map +1 -0
  19. package/dist/config.js +23 -0
  20. package/dist/config.js.map +1 -0
  21. package/dist/context.d.ts +50 -0
  22. package/dist/context.d.ts.map +1 -0
  23. package/dist/context.js +87 -0
  24. package/dist/context.js.map +1 -0
  25. package/dist/decorator.d.ts +57 -0
  26. package/dist/decorator.d.ts.map +1 -0
  27. package/dist/decorator.js +74 -0
  28. package/dist/decorator.js.map +1 -0
  29. package/dist/errors.d.ts +215 -0
  30. package/dist/errors.d.ts.map +1 -0
  31. package/dist/errors.js +246 -0
  32. package/dist/errors.js.map +1 -0
  33. package/dist/executor.d.ts +67 -0
  34. package/dist/executor.d.ts.map +1 -0
  35. package/dist/executor.js +372 -0
  36. package/dist/executor.js.map +1 -0
  37. package/dist/extensions.d.ts +58 -0
  38. package/dist/extensions.d.ts.map +1 -0
  39. package/dist/extensions.js +220 -0
  40. package/dist/extensions.js.map +1 -0
  41. package/{src/index.ts → dist/index.d.ts} +3 -62
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +43 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/middleware/adapters.d.ts +18 -0
  46. package/dist/middleware/adapters.d.ts.map +1 -0
  47. package/dist/middleware/adapters.js +25 -0
  48. package/dist/middleware/adapters.js.map +1 -0
  49. package/dist/middleware/base.d.ts +10 -0
  50. package/dist/middleware/base.d.ts.map +1 -0
  51. package/dist/middleware/base.js +15 -0
  52. package/dist/middleware/base.js.map +1 -0
  53. package/{src/middleware/index.ts → dist/middleware/index.d.ts} +1 -0
  54. package/dist/middleware/index.d.ts.map +1 -0
  55. package/dist/middleware/index.js +5 -0
  56. package/dist/middleware/index.js.map +1 -0
  57. package/dist/middleware/logging.d.ts +25 -0
  58. package/dist/middleware/logging.d.ts.map +1 -0
  59. package/dist/middleware/logging.js +64 -0
  60. package/dist/middleware/logging.js.map +1 -0
  61. package/dist/middleware/manager.d.ts +21 -0
  62. package/dist/middleware/manager.d.ts.map +1 -0
  63. package/dist/middleware/manager.js +77 -0
  64. package/dist/middleware/manager.js.map +1 -0
  65. package/dist/module.d.ts +31 -0
  66. package/dist/module.d.ts.map +1 -0
  67. package/dist/module.js +12 -0
  68. package/dist/module.js.map +1 -0
  69. package/dist/observability/context-logger.d.ts +54 -0
  70. package/dist/observability/context-logger.d.ts.map +1 -0
  71. package/dist/observability/context-logger.js +151 -0
  72. package/dist/observability/context-logger.js.map +1 -0
  73. package/{src/observability/index.ts → dist/observability/index.d.ts} +1 -0
  74. package/dist/observability/index.d.ts.map +1 -0
  75. package/dist/observability/index.js +4 -0
  76. package/dist/observability/index.js.map +1 -0
  77. package/dist/observability/metrics.d.ts +30 -0
  78. package/dist/observability/metrics.d.ts.map +1 -0
  79. package/dist/observability/metrics.js +177 -0
  80. package/dist/observability/metrics.js.map +1 -0
  81. package/dist/observability/tracing.d.ts +62 -0
  82. package/dist/observability/tracing.d.ts.map +1 -0
  83. package/dist/observability/tracing.js +184 -0
  84. package/dist/observability/tracing.js.map +1 -0
  85. package/dist/registry/dependencies.d.ts +6 -0
  86. package/dist/registry/dependencies.d.ts.map +1 -0
  87. package/dist/registry/dependencies.js +83 -0
  88. package/dist/registry/dependencies.js.map +1 -0
  89. package/dist/registry/entry-point.d.ts +6 -0
  90. package/dist/registry/entry-point.d.ts.map +1 -0
  91. package/dist/registry/entry-point.js +55 -0
  92. package/dist/registry/entry-point.js.map +1 -0
  93. package/{src/registry/index.ts → dist/registry/index.d.ts} +1 -0
  94. package/dist/registry/index.d.ts.map +1 -0
  95. package/dist/registry/index.js +8 -0
  96. package/dist/registry/index.js.map +1 -0
  97. package/dist/registry/metadata.d.ts +9 -0
  98. package/dist/registry/metadata.d.ts.map +1 -0
  99. package/dist/registry/metadata.js +105 -0
  100. package/dist/registry/metadata.js.map +1 -0
  101. package/dist/registry/registry.d.ts +102 -0
  102. package/dist/registry/registry.d.ts.map +1 -0
  103. package/dist/registry/registry.js +534 -0
  104. package/dist/registry/registry.js.map +1 -0
  105. package/dist/registry/scanner.d.ts +7 -0
  106. package/dist/registry/scanner.d.ts.map +1 -0
  107. package/dist/registry/scanner.js +164 -0
  108. package/dist/registry/scanner.js.map +1 -0
  109. package/dist/registry/schema-export.d.ts +9 -0
  110. package/dist/registry/schema-export.d.ts.map +1 -0
  111. package/dist/registry/schema-export.js +132 -0
  112. package/dist/registry/schema-export.js.map +1 -0
  113. package/dist/registry/types.d.ts +29 -0
  114. package/dist/registry/types.d.ts.map +1 -0
  115. package/dist/registry/types.js +5 -0
  116. package/dist/registry/types.js.map +1 -0
  117. package/dist/registry/validation.d.ts +9 -0
  118. package/dist/registry/validation.d.ts.map +1 -0
  119. package/dist/registry/validation.js +33 -0
  120. package/dist/registry/validation.js.map +1 -0
  121. package/dist/schema/annotations.d.ts +8 -0
  122. package/dist/schema/annotations.d.ts.map +1 -0
  123. package/dist/schema/annotations.js +52 -0
  124. package/dist/schema/annotations.js.map +1 -0
  125. package/dist/schema/exporter.d.ts +13 -0
  126. package/dist/schema/exporter.d.ts.map +1 -0
  127. package/dist/schema/exporter.js +71 -0
  128. package/dist/schema/exporter.js.map +1 -0
  129. package/dist/schema/index.d.ts +9 -0
  130. package/dist/schema/index.d.ts.map +1 -0
  131. package/{src/schema/index.ts → dist/schema/index.js} +1 -7
  132. package/dist/schema/index.js.map +1 -0
  133. package/dist/schema/loader.d.ts +30 -0
  134. package/dist/schema/loader.d.ts.map +1 -0
  135. package/dist/schema/loader.js +260 -0
  136. package/dist/schema/loader.js.map +1 -0
  137. package/dist/schema/ref-resolver.d.ts +19 -0
  138. package/dist/schema/ref-resolver.d.ts.map +1 -0
  139. package/dist/schema/ref-resolver.js +212 -0
  140. package/dist/schema/ref-resolver.js.map +1 -0
  141. package/dist/schema/strict.d.ts +7 -0
  142. package/dist/schema/strict.d.ts.map +1 -0
  143. package/dist/schema/strict.js +127 -0
  144. package/dist/schema/strict.js.map +1 -0
  145. package/dist/schema/types.d.ts +53 -0
  146. package/dist/schema/types.d.ts.map +1 -0
  147. package/dist/schema/types.js +31 -0
  148. package/dist/schema/types.js.map +1 -0
  149. package/dist/schema/validator.d.ts +16 -0
  150. package/dist/schema/validator.d.ts.map +1 -0
  151. package/dist/schema/validator.js +71 -0
  152. package/dist/schema/validator.js.map +1 -0
  153. package/dist/trace-context.d.ts +35 -0
  154. package/dist/trace-context.d.ts.map +1 -0
  155. package/dist/trace-context.js +86 -0
  156. package/dist/trace-context.js.map +1 -0
  157. package/dist/utils/index.d.ts +11 -0
  158. package/dist/utils/index.d.ts.map +1 -0
  159. package/dist/utils/index.js +32 -0
  160. package/dist/utils/index.js.map +1 -0
  161. package/dist/utils/pattern.d.ts +5 -0
  162. package/dist/utils/pattern.d.ts.map +1 -0
  163. package/dist/utils/pattern.js +31 -0
  164. package/dist/utils/pattern.js.map +1 -0
  165. package/package.json +8 -2
  166. package/.claude/settings.local.json +0 -12
  167. package/.github/workflows/ci.yml +0 -39
  168. package/.gitmessage +0 -60
  169. package/.pre-commit-config.yaml +0 -28
  170. package/CHANGELOG.md +0 -214
  171. package/CLAUDE.md +0 -68
  172. package/apcore-logo.svg +0 -79
  173. package/planning/acl-system/overview.md +0 -54
  174. package/planning/acl-system/plan.md +0 -92
  175. package/planning/acl-system/state.json +0 -76
  176. package/planning/acl-system/tasks/acl-core.md +0 -226
  177. package/planning/acl-system/tasks/acl-rule.md +0 -92
  178. package/planning/acl-system/tasks/conditional-rules.md +0 -259
  179. package/planning/acl-system/tasks/pattern-matching.md +0 -152
  180. package/planning/acl-system/tasks/yaml-loading.md +0 -271
  181. package/planning/core-executor/overview.md +0 -53
  182. package/planning/core-executor/plan.md +0 -88
  183. package/planning/core-executor/state.json +0 -76
  184. package/planning/core-executor/tasks/async-support.md +0 -106
  185. package/planning/core-executor/tasks/execution-pipeline.md +0 -113
  186. package/planning/core-executor/tasks/redaction.md +0 -85
  187. package/planning/core-executor/tasks/safety-checks.md +0 -65
  188. package/planning/core-executor/tasks/setup.md +0 -75
  189. package/planning/decorator-bindings/overview.md +0 -62
  190. package/planning/decorator-bindings/plan.md +0 -104
  191. package/planning/decorator-bindings/state.json +0 -87
  192. package/planning/decorator-bindings/tasks/binding-directory.md +0 -79
  193. package/planning/decorator-bindings/tasks/binding-loader.md +0 -148
  194. package/planning/decorator-bindings/tasks/explicit-schemas.md +0 -85
  195. package/planning/decorator-bindings/tasks/function-module.md +0 -127
  196. package/planning/decorator-bindings/tasks/module-factory.md +0 -89
  197. package/planning/decorator-bindings/tasks/schema-modes.md +0 -142
  198. package/planning/middleware-system/overview.md +0 -48
  199. package/planning/middleware-system/plan.md +0 -102
  200. package/planning/middleware-system/state.json +0 -65
  201. package/planning/middleware-system/tasks/adapters.md +0 -170
  202. package/planning/middleware-system/tasks/base.md +0 -115
  203. package/planning/middleware-system/tasks/logging-middleware.md +0 -304
  204. package/planning/middleware-system/tasks/manager.md +0 -313
  205. package/planning/observability/overview.md +0 -53
  206. package/planning/observability/plan.md +0 -119
  207. package/planning/observability/state.json +0 -98
  208. package/planning/observability/tasks/context-logger.md +0 -201
  209. package/planning/observability/tasks/exporters.md +0 -121
  210. package/planning/observability/tasks/metrics-collector.md +0 -162
  211. package/planning/observability/tasks/metrics-middleware.md +0 -141
  212. package/planning/observability/tasks/obs-logging-middleware.md +0 -179
  213. package/planning/observability/tasks/span-model.md +0 -120
  214. package/planning/observability/tasks/tracing-middleware.md +0 -179
  215. package/planning/overview.md +0 -81
  216. package/planning/registry-system/overview.md +0 -57
  217. package/planning/registry-system/plan.md +0 -114
  218. package/planning/registry-system/state.json +0 -109
  219. package/planning/registry-system/tasks/dependencies.md +0 -157
  220. package/planning/registry-system/tasks/entry-point.md +0 -148
  221. package/planning/registry-system/tasks/metadata.md +0 -198
  222. package/planning/registry-system/tasks/registry-core.md +0 -323
  223. package/planning/registry-system/tasks/scanner.md +0 -172
  224. package/planning/registry-system/tasks/schema-export.md +0 -261
  225. package/planning/registry-system/tasks/types.md +0 -124
  226. package/planning/registry-system/tasks/validation.md +0 -177
  227. package/planning/schema-system/overview.md +0 -56
  228. package/planning/schema-system/plan.md +0 -121
  229. package/planning/schema-system/state.json +0 -98
  230. package/planning/schema-system/tasks/exporter.md +0 -153
  231. package/planning/schema-system/tasks/loader.md +0 -106
  232. package/planning/schema-system/tasks/ref-resolver.md +0 -133
  233. package/planning/schema-system/tasks/strict-mode.md +0 -140
  234. package/planning/schema-system/tasks/typebox-generation.md +0 -133
  235. package/planning/schema-system/tasks/types-and-annotations.md +0 -160
  236. package/planning/schema-system/tasks/validator.md +0 -149
  237. package/src/acl.ts +0 -200
  238. package/src/async-task.ts +0 -267
  239. package/src/bindings.ts +0 -207
  240. package/src/cancel.ts +0 -32
  241. package/src/config.ts +0 -24
  242. package/src/context.ts +0 -160
  243. package/src/decorator.ts +0 -110
  244. package/src/errors.ts +0 -429
  245. package/src/executor.ts +0 -493
  246. package/src/extensions.ts +0 -265
  247. package/src/middleware/adapters.ts +0 -54
  248. package/src/middleware/base.ts +0 -33
  249. package/src/middleware/logging.ts +0 -103
  250. package/src/middleware/manager.ts +0 -105
  251. package/src/module.ts +0 -43
  252. package/src/observability/context-logger.ts +0 -203
  253. package/src/observability/metrics.ts +0 -214
  254. package/src/observability/tracing.ts +0 -252
  255. package/src/registry/dependencies.ts +0 -99
  256. package/src/registry/entry-point.ts +0 -64
  257. package/src/registry/metadata.ts +0 -111
  258. package/src/registry/registry.ts +0 -580
  259. package/src/registry/scanner.ts +0 -168
  260. package/src/registry/schema-export.ts +0 -181
  261. package/src/registry/types.ts +0 -32
  262. package/src/registry/validation.ts +0 -38
  263. package/src/schema/annotations.ts +0 -68
  264. package/src/schema/exporter.ts +0 -90
  265. package/src/schema/loader.ts +0 -273
  266. package/src/schema/ref-resolver.ts +0 -244
  267. package/src/schema/strict.ts +0 -136
  268. package/src/schema/types.ts +0 -73
  269. package/src/schema/validator.ts +0 -82
  270. package/src/trace-context.ts +0 -102
  271. package/src/utils/index.ts +0 -5
  272. package/src/utils/pattern.ts +0 -30
  273. package/tests/async-task.test.ts +0 -335
  274. package/tests/helpers.ts +0 -30
  275. package/tests/integration/test-acl-safety.test.ts +0 -269
  276. package/tests/integration/test-binding-executor.test.ts +0 -194
  277. package/tests/integration/test-e2e-flow.test.ts +0 -117
  278. package/tests/integration/test-error-propagation.test.ts +0 -259
  279. package/tests/integration/test-middleware-chain.test.ts +0 -120
  280. package/tests/integration/test-observability-integration.test.ts +0 -438
  281. package/tests/observability/test-context-logger.test.ts +0 -123
  282. package/tests/observability/test-metrics.test.ts +0 -186
  283. package/tests/observability/test-tracing.test.ts +0 -303
  284. package/tests/registry/test-dependencies.test.ts +0 -70
  285. package/tests/registry/test-entry-point.test.ts +0 -133
  286. package/tests/registry/test-metadata.test.ts +0 -265
  287. package/tests/registry/test-registry.test.ts +0 -1397
  288. package/tests/registry/test-scanner.test.ts +0 -257
  289. package/tests/registry/test-schema-export.test.ts +0 -355
  290. package/tests/registry/test-validation.test.ts +0 -75
  291. package/tests/schema/test-annotations.test.ts +0 -137
  292. package/tests/schema/test-exporter.test.ts +0 -172
  293. package/tests/schema/test-loader.test.ts +0 -461
  294. package/tests/schema/test-ref-resolver.test.ts +0 -530
  295. package/tests/schema/test-strict.test.ts +0 -348
  296. package/tests/schema/test-validator.test.ts +0 -64
  297. package/tests/test-acl.test.ts +0 -423
  298. package/tests/test-bindings.test.ts +0 -227
  299. package/tests/test-cancel.test.ts +0 -71
  300. package/tests/test-config.test.ts +0 -76
  301. package/tests/test-context.test.ts +0 -266
  302. package/tests/test-decorator.test.ts +0 -173
  303. package/tests/test-errors.test.ts +0 -647
  304. package/tests/test-executor-stream.test.ts +0 -208
  305. package/tests/test-executor.test.ts +0 -252
  306. package/tests/test-extensions.test.ts +0 -310
  307. package/tests/test-logging-middleware.test.ts +0 -150
  308. package/tests/test-middleware-manager.test.ts +0 -185
  309. package/tests/test-middleware.test.ts +0 -86
  310. package/tests/test-trace-context.test.ts +0 -251
  311. package/tests/utils/test-pattern.test.ts +0 -109
  312. package/tsconfig.build.json +0 -8
  313. package/tsconfig.json +0 -20
  314. package/vitest.config.ts +0 -18
@@ -1,76 +0,0 @@
1
- {
2
- "feature": "acl-system",
3
- "created": "2026-02-16T00:00:00Z",
4
- "updated": "2026-02-16T00:00:00Z",
5
- "status": "completed",
6
- "execution_order": [
7
- "acl-rule",
8
- "pattern-matching",
9
- "conditional-rules",
10
- "acl-core",
11
- "yaml-loading"
12
- ],
13
- "progress": {
14
- "total_tasks": 5,
15
- "completed": 5,
16
- "in_progress": 0,
17
- "pending": 0
18
- },
19
- "tasks": [
20
- {
21
- "id": "acl-rule",
22
- "file": "tasks/acl-rule.md",
23
- "title": "ACLRule Interface Definition",
24
- "status": "completed",
25
- "started_at": "2026-02-16T08:00:00Z",
26
- "completed_at": "2026-02-16T08:45:00Z",
27
- "assignee": null,
28
- "commits": []
29
- },
30
- {
31
- "id": "pattern-matching",
32
- "file": "tasks/pattern-matching.md",
33
- "title": "matchPattern() Wildcard Matching (Algorithm A08)",
34
- "status": "completed",
35
- "started_at": "2026-02-16T08:45:00Z",
36
- "completed_at": "2026-02-16T10:15:00Z",
37
- "assignee": null,
38
- "commits": []
39
- },
40
- {
41
- "id": "conditional-rules",
42
- "file": "tasks/conditional-rules.md",
43
- "title": "Conditional Rule Evaluation (identity_types, roles, max_call_depth)",
44
- "status": "completed",
45
- "started_at": "2026-02-16T10:15:00Z",
46
- "completed_at": "2026-02-16T11:45:00Z",
47
- "assignee": null,
48
- "commits": []
49
- },
50
- {
51
- "id": "acl-core",
52
- "file": "tasks/acl-core.md",
53
- "title": "ACL Class with check(), addRule(), removeRule()",
54
- "status": "completed",
55
- "started_at": "2026-02-16T11:45:00Z",
56
- "completed_at": "2026-02-16T14:00:00Z",
57
- "assignee": null,
58
- "commits": []
59
- },
60
- {
61
- "id": "yaml-loading",
62
- "file": "tasks/yaml-loading.md",
63
- "title": "ACL.load() from YAML and reload() Support",
64
- "status": "completed",
65
- "started_at": "2026-02-16T14:00:00Z",
66
- "completed_at": "2026-02-16T15:30:00Z",
67
- "assignee": null,
68
- "commits": []
69
- }
70
- ],
71
- "metadata": {
72
- "source_doc": "planning/features/acl-system.md",
73
- "created_by": "code-forge",
74
- "version": "1.0"
75
- }
76
- }
@@ -1,226 +0,0 @@
1
- # Task: ACL Class with check(), addRule(), removeRule()
2
-
3
- ## Goal
4
-
5
- Implement the `ACL` class that manages an ordered list of `ACLRule` objects and provides first-match-wins permission evaluation via `check()`, runtime rule mutation via `addRule()` and `removeRule()`, and a configurable default effect.
6
-
7
- ## Files Involved
8
-
9
- - `src/acl.ts` -- ACL class implementation (~188 lines total including YAML loading)
10
- - `src/errors.ts` -- `ACLDeniedError` (used by executor, not ACL directly)
11
- - `src/context.ts` -- `Context` and `Identity` types consumed by `check()`
12
-
13
- ## Steps (TDD)
14
-
15
- ### 1. Write failing tests for ACL constructor and default behavior
16
-
17
- ```typescript
18
- // tests/acl.test.ts
19
- import { describe, it, expect } from 'vitest';
20
- import { ACL } from '../src/acl.js';
21
- import type { ACLRule } from '../src/acl.js';
22
-
23
- describe('ACL constructor', () => {
24
- it('should default to deny when no rules match', () => {
25
- const acl = new ACL([]);
26
- expect(acl.check('moduleA', 'moduleB')).toBe(false);
27
- });
28
-
29
- it('should respect custom default effect', () => {
30
- const acl = new ACL([], 'allow');
31
- expect(acl.check('moduleA', 'moduleB')).toBe(true);
32
- });
33
- });
34
- ```
35
-
36
- ### 2. Implement constructor with rules copy and default effect
37
-
38
- ```typescript
39
- export class ACL {
40
- private _rules: ACLRule[];
41
- private _defaultEffect: string;
42
-
43
- constructor(rules: ACLRule[], defaultEffect: string = 'deny') {
44
- this._rules = [...rules];
45
- this._defaultEffect = defaultEffect;
46
- }
47
- }
48
- ```
49
-
50
- ### 3. Write failing tests for check() first-match-wins
51
-
52
- ```typescript
53
- describe('ACL.check()', () => {
54
- it('should allow when first matching rule has allow effect', () => {
55
- const rules: ACLRule[] = [
56
- { callers: ['moduleA'], targets: ['moduleB'], effect: 'allow', description: 'test' },
57
- ];
58
- const acl = new ACL(rules);
59
- expect(acl.check('moduleA', 'moduleB')).toBe(true);
60
- });
61
-
62
- it('should deny when first matching rule has deny effect', () => {
63
- const rules: ACLRule[] = [
64
- { callers: ['moduleA'], targets: ['moduleB'], effect: 'deny', description: 'test' },
65
- ];
66
- const acl = new ACL(rules);
67
- expect(acl.check('moduleA', 'moduleB')).toBe(false);
68
- });
69
-
70
- it('should normalize null caller to @external', () => {
71
- const rules: ACLRule[] = [
72
- { callers: ['@external'], targets: ['auth'], effect: 'allow', description: 'test' },
73
- ];
74
- const acl = new ACL(rules);
75
- expect(acl.check(null, 'auth')).toBe(true);
76
- });
77
-
78
- it('should use first matching rule and ignore later rules', () => {
79
- const rules: ACLRule[] = [
80
- { callers: ['moduleA'], targets: ['moduleB'], effect: 'deny', description: 'deny first' },
81
- { callers: ['moduleA'], targets: ['moduleB'], effect: 'allow', description: 'allow second' },
82
- ];
83
- const acl = new ACL(rules);
84
- expect(acl.check('moduleA', 'moduleB')).toBe(false);
85
- });
86
-
87
- it('should fall through to default when no rules match', () => {
88
- const rules: ACLRule[] = [
89
- { callers: ['moduleX'], targets: ['moduleY'], effect: 'allow', description: 'unrelated' },
90
- ];
91
- const acl = new ACL(rules, 'deny');
92
- expect(acl.check('moduleA', 'moduleB')).toBe(false);
93
- });
94
- });
95
- ```
96
-
97
- ### 4. Implement check() with _matchesRule and _matchPattern
98
-
99
- ```typescript
100
- check(callerId: string | null, targetId: string, context?: Context | null): boolean {
101
- const effectiveCaller = callerId === null ? '@external' : callerId;
102
- const rules = [...this._rules];
103
-
104
- for (const rule of rules) {
105
- if (this._matchesRule(rule, effectiveCaller, targetId, context ?? null)) {
106
- return rule.effect === 'allow';
107
- }
108
- }
109
-
110
- return this._defaultEffect === 'allow';
111
- }
112
-
113
- private _matchPattern(pattern: string, value: string, context: Context | null): boolean {
114
- if (pattern === '@external') return value === '@external';
115
- if (pattern === '@system') {
116
- return context !== null && context.identity !== null && context.identity.type === 'system';
117
- }
118
- return matchPattern(pattern, value);
119
- }
120
-
121
- private _matchesRule(rule: ACLRule, caller: string, target: string, context: Context | null): boolean {
122
- const callerMatch = rule.callers.some((p) => this._matchPattern(p, caller, context));
123
- if (!callerMatch) return false;
124
-
125
- const targetMatch = rule.targets.some((p) => this._matchPattern(p, target, context));
126
- if (!targetMatch) return false;
127
-
128
- if (rule.conditions != null) {
129
- if (!this._checkConditions(rule.conditions, context)) return false;
130
- }
131
-
132
- return true;
133
- }
134
- ```
135
-
136
- ### 5. Write failing tests for addRule() and removeRule()
137
-
138
- ```typescript
139
- describe('ACL.addRule()', () => {
140
- it('should prepend rule to beginning of list', () => {
141
- const acl = new ACL([
142
- { callers: ['*'], targets: ['*'], effect: 'deny', description: 'deny all' },
143
- ]);
144
- acl.addRule({ callers: ['moduleA'], targets: ['moduleB'], effect: 'allow', description: 'allow A->B' });
145
- // New rule is first, so it should match before the deny-all
146
- expect(acl.check('moduleA', 'moduleB')).toBe(true);
147
- });
148
- });
149
-
150
- describe('ACL.removeRule()', () => {
151
- it('should remove rule matching callers and targets', () => {
152
- const acl = new ACL([
153
- { callers: ['moduleA'], targets: ['moduleB'], effect: 'allow', description: 'test' },
154
- ]);
155
- const removed = acl.removeRule(['moduleA'], ['moduleB']);
156
- expect(removed).toBe(true);
157
- expect(acl.check('moduleA', 'moduleB')).toBe(false); // falls to default deny
158
- });
159
-
160
- it('should return false when no matching rule found', () => {
161
- const acl = new ACL([]);
162
- expect(acl.removeRule(['moduleA'], ['moduleB'])).toBe(false);
163
- });
164
-
165
- it('should use JSON.stringify for array comparison', () => {
166
- const acl = new ACL([
167
- { callers: ['a', 'b'], targets: ['c'], effect: 'allow', description: 'test' },
168
- ]);
169
- // Different order should not match
170
- expect(acl.removeRule(['b', 'a'], ['c'])).toBe(false);
171
- // Same order should match
172
- expect(acl.removeRule(['a', 'b'], ['c'])).toBe(true);
173
- });
174
- });
175
- ```
176
-
177
- ### 6. Implement addRule() and removeRule()
178
-
179
- ```typescript
180
- addRule(rule: ACLRule): void {
181
- this._rules.unshift(rule);
182
- }
183
-
184
- removeRule(callers: string[], targets: string[]): boolean {
185
- for (let i = 0; i < this._rules.length; i++) {
186
- const rule = this._rules[i];
187
- if (
188
- JSON.stringify(rule.callers) === JSON.stringify(callers) &&
189
- JSON.stringify(rule.targets) === JSON.stringify(targets)
190
- ) {
191
- this._rules.splice(i, 1);
192
- return true;
193
- }
194
- }
195
- return false;
196
- }
197
- ```
198
-
199
- ### 7. Run full test suite and type-check
200
-
201
- Run `tsc --noEmit` and `vitest` to confirm everything passes.
202
-
203
- ## Acceptance Criteria
204
-
205
- - [x] `ACL` constructor accepts `rules` array and optional `defaultEffect` (default `'deny'`)
206
- - [x] Constructor shallow-copies the rules array to prevent external mutation
207
- - [x] `check()` returns `boolean` using first-match-wins evaluation
208
- - [x] Null `callerId` is normalized to `'@external'`
209
- - [x] `@external` pattern matches only the `@external` sentinel value
210
- - [x] `@system` pattern checks `context.identity.type === 'system'`
211
- - [x] Non-special patterns delegate to `matchPattern()` from `utils/pattern.ts`
212
- - [x] Falls through to `_defaultEffect` when no rule matches
213
- - [x] `addRule()` prepends the rule to the beginning of the list
214
- - [x] `removeRule()` uses `JSON.stringify` for caller/target array comparison and returns `boolean`
215
- - [x] `removeRule()` only removes the first matching rule
216
- - [x] All tests pass with `vitest`; zero errors from `tsc --noEmit`
217
-
218
- ## Dependencies
219
-
220
- - **acl-rule** -- ACLRule interface definition
221
- - **pattern-matching** -- matchPattern() utility
222
- - **conditional-rules** -- _checkConditions() method
223
-
224
- ## Estimated Time
225
-
226
- 3 hours
@@ -1,92 +0,0 @@
1
- # Task: ACLRule Interface Definition
2
-
3
- ## Goal
4
-
5
- Define the `ACLRule` TypeScript interface that represents a single access control rule, specifying caller patterns, target patterns, an effect (allow/deny), a human-readable description, and optional conditions for conditional evaluation.
6
-
7
- ## Files Involved
8
-
9
- - `src/acl.ts` -- Interface definition exported alongside the ACL class
10
-
11
- ## Steps (TDD)
12
-
13
- ### 1. Write failing tests for ACLRule shape
14
-
15
- ```typescript
16
- // tests/acl.test.ts
17
- import { describe, it, expect } from 'vitest';
18
- import type { ACLRule } from '../src/acl.js';
19
-
20
- describe('ACLRule interface', () => {
21
- it('should accept a fully-specified rule', () => {
22
- const rule: ACLRule = {
23
- callers: ['moduleA', 'moduleB'],
24
- targets: ['moduleC'],
25
- effect: 'allow',
26
- description: 'Allow A and B to call C',
27
- conditions: { roles: ['admin'] },
28
- };
29
- expect(rule.callers).toEqual(['moduleA', 'moduleB']);
30
- expect(rule.targets).toEqual(['moduleC']);
31
- expect(rule.effect).toBe('allow');
32
- expect(rule.description).toBe('Allow A and B to call C');
33
- expect(rule.conditions).toEqual({ roles: ['admin'] });
34
- });
35
-
36
- it('should accept a rule with no conditions', () => {
37
- const rule: ACLRule = {
38
- callers: ['*'],
39
- targets: ['*'],
40
- effect: 'deny',
41
- description: 'Deny all by default',
42
- };
43
- expect(rule.conditions).toBeUndefined();
44
- });
45
-
46
- it('should accept null conditions', () => {
47
- const rule: ACLRule = {
48
- callers: ['@external'],
49
- targets: ['auth.*'],
50
- effect: 'allow',
51
- description: 'Allow external to auth modules',
52
- conditions: null,
53
- };
54
- expect(rule.conditions).toBeNull();
55
- });
56
- });
57
- ```
58
-
59
- ### 2. Define the ACLRule interface
60
-
61
- ```typescript
62
- // src/acl.ts
63
- export interface ACLRule {
64
- callers: string[];
65
- targets: string[];
66
- effect: string;
67
- description: string;
68
- conditions?: Record<string, unknown> | null;
69
- }
70
- ```
71
-
72
- ### 3. Verify type-check and tests pass
73
-
74
- Run `tsc --noEmit` to confirm no type errors, then run `vitest` to confirm all tests pass.
75
-
76
- ## Acceptance Criteria
77
-
78
- - [x] `ACLRule` interface is exported from `src/acl.ts`
79
- - [x] `callers` is `string[]` representing caller module ID patterns
80
- - [x] `targets` is `string[]` representing target module ID patterns
81
- - [x] `effect` is `string` (validated as `'allow'` | `'deny'` at runtime during YAML loading)
82
- - [x] `description` is `string` for human-readable rule documentation
83
- - [x] `conditions` is optional `Record<string, unknown> | null` for conditional evaluation
84
- - [x] All tests pass with `vitest`; zero errors from `tsc --noEmit`
85
-
86
- ## Dependencies
87
-
88
- - None (this is a standalone type definition)
89
-
90
- ## Estimated Time
91
-
92
- 1 hour
@@ -1,259 +0,0 @@
1
- # Task: Conditional Rule Evaluation (_checkConditions)
2
-
3
- ## Goal
4
-
5
- Implement the `_checkConditions()` private method on the `ACL` class that evaluates optional conditions attached to ACL rules. Conditions use AND logic: all present condition keys must pass for the rule to match. Supported conditions are `identity_types`, `roles`, and `max_call_depth`.
6
-
7
- ## Files Involved
8
-
9
- - `src/acl.ts` -- `_checkConditions()` private method on the ACL class
10
- - `src/context.ts` -- `Context` class (provides `identity` and `callChain`) and `Identity` interface (provides `type` and `roles`)
11
-
12
- ## Steps (TDD)
13
-
14
- ### 1. Write failing tests for identity_types condition
15
-
16
- ```typescript
17
- // tests/acl.test.ts
18
- import { describe, it, expect } from 'vitest';
19
- import { ACL } from '../src/acl.js';
20
- import type { ACLRule } from '../src/acl.js';
21
- import type { Context } from '../src/context.js';
22
-
23
- // Helper to create a minimal mock context
24
- function mockContext(overrides: {
25
- identityType?: string;
26
- identityRoles?: string[];
27
- callChainLength?: number;
28
- } = {}): Context {
29
- return {
30
- identity: overrides.identityType !== undefined ? {
31
- id: 'test-user',
32
- type: overrides.identityType,
33
- roles: overrides.identityRoles ?? [],
34
- attrs: {},
35
- } : null,
36
- callChain: Array(overrides.callChainLength ?? 0).fill('module'),
37
- } as unknown as Context;
38
- }
39
-
40
- describe('_checkConditions via check()', () => {
41
- describe('identity_types condition', () => {
42
- const rules: ACLRule[] = [
43
- {
44
- callers: ['*'],
45
- targets: ['admin.*'],
46
- effect: 'allow',
47
- description: 'Allow system callers',
48
- conditions: { identity_types: ['system', 'service'] },
49
- },
50
- ];
51
-
52
- it('should allow when identity type matches', () => {
53
- const acl = new ACL(rules);
54
- const ctx = mockContext({ identityType: 'system' });
55
- expect(acl.check('moduleA', 'admin.panel', ctx)).toBe(true);
56
- });
57
-
58
- it('should deny when identity type does not match', () => {
59
- const acl = new ACL(rules);
60
- const ctx = mockContext({ identityType: 'user' });
61
- expect(acl.check('moduleA', 'admin.panel', ctx)).toBe(false);
62
- });
63
-
64
- it('should deny when identity is null', () => {
65
- const acl = new ACL(rules);
66
- const ctx = { identity: null, callChain: [] } as unknown as Context;
67
- expect(acl.check('moduleA', 'admin.panel', ctx)).toBe(false);
68
- });
69
- });
70
- });
71
- ```
72
-
73
- ### 2. Write failing tests for roles condition
74
-
75
- ```typescript
76
- describe('roles condition', () => {
77
- const rules: ACLRule[] = [
78
- {
79
- callers: ['*'],
80
- targets: ['admin.*'],
81
- effect: 'allow',
82
- description: 'Allow admin role',
83
- conditions: { roles: ['admin', 'superadmin'] },
84
- },
85
- ];
86
-
87
- it('should allow when identity has at least one matching role', () => {
88
- const acl = new ACL(rules);
89
- const ctx = mockContext({ identityType: 'user', identityRoles: ['admin'] });
90
- expect(acl.check('moduleA', 'admin.panel', ctx)).toBe(true);
91
- });
92
-
93
- it('should deny when identity has no matching roles', () => {
94
- const acl = new ACL(rules);
95
- const ctx = mockContext({ identityType: 'user', identityRoles: ['viewer'] });
96
- expect(acl.check('moduleA', 'admin.panel', ctx)).toBe(false);
97
- });
98
-
99
- it('should deny when identity is null', () => {
100
- const acl = new ACL(rules);
101
- const ctx = { identity: null, callChain: [] } as unknown as Context;
102
- expect(acl.check('moduleA', 'admin.panel', ctx)).toBe(false);
103
- });
104
- });
105
- ```
106
-
107
- ### 3. Write failing tests for max_call_depth condition
108
-
109
- ```typescript
110
- describe('max_call_depth condition', () => {
111
- const rules: ACLRule[] = [
112
- {
113
- callers: ['*'],
114
- targets: ['recursive.*'],
115
- effect: 'allow',
116
- description: 'Allow with depth limit',
117
- conditions: { max_call_depth: 3 },
118
- },
119
- ];
120
-
121
- it('should allow when call chain is within limit', () => {
122
- const acl = new ACL(rules);
123
- const ctx = mockContext({ identityType: 'user', callChainLength: 2 });
124
- expect(acl.check('moduleA', 'recursive.handler', ctx)).toBe(true);
125
- });
126
-
127
- it('should allow when call chain is exactly at limit', () => {
128
- const acl = new ACL(rules);
129
- const ctx = mockContext({ identityType: 'user', callChainLength: 3 });
130
- expect(acl.check('moduleA', 'recursive.handler', ctx)).toBe(true);
131
- });
132
-
133
- it('should deny when call chain exceeds limit', () => {
134
- const acl = new ACL(rules);
135
- const ctx = mockContext({ identityType: 'user', callChainLength: 4 });
136
- expect(acl.check('moduleA', 'recursive.handler', ctx)).toBe(false);
137
- });
138
- });
139
- ```
140
-
141
- ### 4. Write failing tests for AND logic across multiple conditions
142
-
143
- ```typescript
144
- describe('AND logic across conditions', () => {
145
- const rules: ACLRule[] = [
146
- {
147
- callers: ['*'],
148
- targets: ['sensitive.*'],
149
- effect: 'allow',
150
- description: 'Require admin role AND system type AND depth <= 2',
151
- conditions: {
152
- identity_types: ['system'],
153
- roles: ['admin'],
154
- max_call_depth: 2,
155
- },
156
- },
157
- ];
158
-
159
- it('should allow when all conditions pass', () => {
160
- const acl = new ACL(rules);
161
- const ctx = mockContext({ identityType: 'system', identityRoles: ['admin'], callChainLength: 1 });
162
- expect(acl.check('moduleA', 'sensitive.data', ctx)).toBe(true);
163
- });
164
-
165
- it('should deny when one condition fails (wrong type)', () => {
166
- const acl = new ACL(rules);
167
- const ctx = mockContext({ identityType: 'user', identityRoles: ['admin'], callChainLength: 1 });
168
- expect(acl.check('moduleA', 'sensitive.data', ctx)).toBe(false);
169
- });
170
-
171
- it('should deny when one condition fails (wrong role)', () => {
172
- const acl = new ACL(rules);
173
- const ctx = mockContext({ identityType: 'system', identityRoles: ['viewer'], callChainLength: 1 });
174
- expect(acl.check('moduleA', 'sensitive.data', ctx)).toBe(false);
175
- });
176
-
177
- it('should deny when one condition fails (depth exceeded)', () => {
178
- const acl = new ACL(rules);
179
- const ctx = mockContext({ identityType: 'system', identityRoles: ['admin'], callChainLength: 5 });
180
- expect(acl.check('moduleA', 'sensitive.data', ctx)).toBe(false);
181
- });
182
- });
183
- ```
184
-
185
- ### 5. Write failing test for null context with conditions
186
-
187
- ```typescript
188
- describe('null context with conditions', () => {
189
- it('should deny when context is null and conditions are present', () => {
190
- const rules: ACLRule[] = [
191
- {
192
- callers: ['*'],
193
- targets: ['*'],
194
- effect: 'allow',
195
- description: 'conditional rule',
196
- conditions: { roles: ['admin'] },
197
- },
198
- ];
199
- const acl = new ACL(rules);
200
- expect(acl.check('moduleA', 'moduleB', null)).toBe(false);
201
- });
202
- });
203
- ```
204
-
205
- ### 6. Implement _checkConditions()
206
-
207
- ```typescript
208
- private _checkConditions(conditions: Record<string, unknown>, context: Context | null): boolean {
209
- // Null context cannot satisfy any conditions
210
- if (context === null) return false;
211
-
212
- // identity_types: caller's identity.type must be in the list
213
- if ('identity_types' in conditions) {
214
- const types = conditions['identity_types'] as string[];
215
- if (context.identity === null || !types.includes(context.identity.type)) return false;
216
- }
217
-
218
- // roles: caller's identity must have at least one matching role (OR within roles, AND with other conditions)
219
- if ('roles' in conditions) {
220
- const roles = conditions['roles'] as string[];
221
- if (context.identity === null) return false;
222
- const identityRoles = new Set(context.identity.roles);
223
- if (!roles.some((r) => identityRoles.has(r))) return false;
224
- }
225
-
226
- // max_call_depth: call chain length must not exceed the limit
227
- if ('max_call_depth' in conditions) {
228
- const maxDepth = conditions['max_call_depth'] as number;
229
- if (context.callChain.length > maxDepth) return false;
230
- }
231
-
232
- return true;
233
- }
234
- ```
235
-
236
- ### 7. Run full test suite and type-check
237
-
238
- Run `tsc --noEmit` and `vitest` to confirm everything passes.
239
-
240
- ## Acceptance Criteria
241
-
242
- - [x] `_checkConditions()` returns `false` when context is `null`
243
- - [x] `identity_types` condition checks `context.identity.type` is in the allowed list
244
- - [x] `identity_types` returns `false` when `context.identity` is `null`
245
- - [x] `roles` condition checks that at least one role in the condition list matches a role in `context.identity.roles` (OR within roles)
246
- - [x] `roles` returns `false` when `context.identity` is `null`
247
- - [x] `roles` uses `Set` for efficient lookup on the identity's roles
248
- - [x] `max_call_depth` condition checks `context.callChain.length <= maxDepth`
249
- - [x] Multiple conditions use AND logic: all present conditions must pass
250
- - [x] Unknown condition keys are silently ignored (forward-compatible)
251
- - [x] All tests pass with `vitest`; zero errors from `tsc --noEmit`
252
-
253
- ## Dependencies
254
-
255
- - **acl-rule** -- ACLRule interface (conditions field definition)
256
-
257
- ## Estimated Time
258
-
259
- 2 hours