@agentic-sdlc-kit/mod-sdk 0.0.0-stage → 0.9.1

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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/dist/capabilities/analyzer.d.ts +13 -0
  3. package/dist/capabilities/analyzer.d.ts.map +1 -0
  4. package/dist/capabilities/analyzer.js +58 -0
  5. package/dist/capabilities/analyzer.js.map +1 -0
  6. package/dist/capabilities/index.d.ts +2 -0
  7. package/dist/capabilities/index.d.ts.map +1 -0
  8. package/dist/capabilities/index.js +3 -0
  9. package/dist/capabilities/index.js.map +1 -0
  10. package/dist/capabilities/manifest.d.ts +40 -0
  11. package/dist/capabilities/manifest.d.ts.map +1 -0
  12. package/dist/capabilities/manifest.js +35 -0
  13. package/dist/capabilities/manifest.js.map +1 -0
  14. package/dist/claude-code-shim.d.ts +22 -0
  15. package/dist/claude-code-shim.d.ts.map +1 -0
  16. package/dist/claude-code-shim.js +30 -0
  17. package/dist/claude-code-shim.js.map +1 -0
  18. package/dist/index.d.ts +5 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +14 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/middleware/compose.d.ts +3 -0
  23. package/dist/middleware/compose.d.ts.map +1 -0
  24. package/dist/middleware/compose.js +28 -0
  25. package/dist/middleware/compose.js.map +1 -0
  26. package/dist/middleware/index.d.ts +2 -0
  27. package/dist/middleware/index.d.ts.map +1 -0
  28. package/dist/middleware/index.js +3 -0
  29. package/dist/middleware/index.js.map +1 -0
  30. package/dist/testing/index.d.ts +2 -0
  31. package/dist/testing/index.d.ts.map +1 -0
  32. package/dist/testing/index.js +3 -0
  33. package/dist/testing/index.js.map +1 -0
  34. package/dist/testing/mock-runtime.d.ts +96 -0
  35. package/dist/testing/mock-runtime.d.ts.map +1 -0
  36. package/dist/testing/mock-runtime.js +379 -0
  37. package/dist/testing/mock-runtime.js.map +1 -0
  38. package/dist/types/events.d.ts +158 -0
  39. package/dist/types/events.d.ts.map +1 -0
  40. package/dist/types/events.js +35 -0
  41. package/dist/types/events.js.map +1 -0
  42. package/dist/types/index.d.ts +2 -0
  43. package/dist/types/index.d.ts.map +1 -0
  44. package/dist/types/index.js +3 -0
  45. package/dist/types/index.js.map +1 -0
  46. package/package.json +37 -3
  47. package/src/capabilities/analyzer.test.ts +77 -0
  48. package/src/capabilities/analyzer.ts +68 -0
  49. package/src/capabilities/index.ts +2 -0
  50. package/src/capabilities/manifest.ts +38 -0
  51. package/src/claude-code-shim.ts +43 -0
  52. package/src/index.ts +14 -0
  53. package/src/middleware/compose.test.ts +70 -0
  54. package/src/middleware/compose.ts +29 -0
  55. package/src/middleware/index.ts +2 -0
  56. package/src/testing/index.ts +2 -0
  57. package/src/testing/mock-runtime.test.ts +264 -0
  58. package/src/testing/mock-runtime.ts +452 -0
  59. package/src/types/events.ts +275 -0
  60. package/src/types/index.ts +2 -0
  61. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agentic SDLC Kit contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ import type { ModCapabilities } from './manifest.js';
2
+ export interface AnalysisResult {
3
+ declaredHooks: string[];
4
+ declaredApiAccess: string[];
5
+ mismatches: string[];
6
+ }
7
+ /**
8
+ * Analyze a register.ts source string for declared events and API calls.
9
+ * Returns the extracted surface and any mismatches against the declared
10
+ * capabilities.
11
+ */
12
+ export declare function analyzeRegisterSource(source: string, declared: ModCapabilities): AnalysisResult;
13
+ //# sourceMappingURL=analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../../src/capabilities/analyzer.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,cAAc,CA6C/F"}
@@ -0,0 +1,58 @@
1
+ // packages/mod-sdk/src/capabilities/analyzer.ts
2
+ //
3
+ // Static capability analyzer. Parses a Mod's register.ts source to extract
4
+ // declared events and API calls, then compares against the declared
5
+ // ModCapabilities manifest.
6
+ //
7
+ // This is a lightweight text-based analyzer; it does not load the module.
8
+ // It looks for `on('event.name', ...)` and `$.namespace.method(...)` calls.
9
+ /**
10
+ * Analyze a register.ts source string for declared events and API calls.
11
+ * Returns the extracted surface and any mismatches against the declared
12
+ * capabilities.
13
+ */
14
+ export function analyzeRegisterSource(source, declared) {
15
+ const declaredHooks = new Set();
16
+ const declaredApiAccess = new Set();
17
+ // Find on('event.name', ...) and on("event.name", ...) calls.
18
+ const onRegex = /\bon\(\s*['"]([a-z.]+)['"]/g;
19
+ let m;
20
+ while ((m = onRegex.exec(source)) !== null) {
21
+ const ev = m[1];
22
+ if (ev)
23
+ declaredHooks.add(ev);
24
+ }
25
+ // Find $.namespace.method( calls.
26
+ const apiRegex = /\$\.\s*([a-zA-Z]+)\.([a-zA-Z]+)/g;
27
+ while ((m = apiRegex.exec(source)) !== null) {
28
+ const ns = m[1];
29
+ const method = m[2];
30
+ if (ns && method)
31
+ declaredApiAccess.add(`${ns}.${method}`);
32
+ }
33
+ // Check for mismatches.
34
+ const mismatches = [];
35
+ for (const h of declaredHooks) {
36
+ if (!declared.hooks.includes(h)) {
37
+ mismatches.push(`source registers hook '${h}' but manifest does not declare it`);
38
+ }
39
+ }
40
+ for (const a of declaredApiAccess) {
41
+ if (!declared.apiAccess.includes(a)) {
42
+ mismatches.push(`source uses API '${a}' but manifest does not declare it`);
43
+ }
44
+ }
45
+ // Check network/process usage.
46
+ if (declared.networkAccess === false && /\$\.http\.fetch/.test(source)) {
47
+ mismatches.push('source uses $.http.fetch but manifest declares networkAccess=false');
48
+ }
49
+ if (declared.processExecution === false && /\$\.process\.run/.test(source)) {
50
+ mismatches.push('source uses $.process.run but manifest declares processExecution=false');
51
+ }
52
+ return {
53
+ declaredHooks: Array.from(declaredHooks),
54
+ declaredApiAccess: Array.from(declaredApiAccess),
55
+ mismatches,
56
+ };
57
+ }
58
+ //# sourceMappingURL=analyzer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzer.js","sourceRoot":"","sources":["../../src/capabilities/analyzer.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,EAAE;AACF,2EAA2E;AAC3E,oEAAoE;AACpE,4BAA4B;AAC5B,EAAE;AACF,0EAA0E;AAC1E,4EAA4E;AAU5E;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAc,EAAE,QAAyB;IAC7E,MAAM,aAAa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C;QAC7E,CAAC;IACH,CAAC;IACD,+BAA+B;IAC/B,IAAI,QAAQ,CAAC,aAAa,KAAK,KAAK,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACvE,UAAU,CAAC,IAAI,CAAC,oEAAoE,CAAC,CAAC;IACxF,CAAC;IACD,IAAI,QAAQ,CAAC,gBAAgB,KAAK,KAAK,IAAI,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3E,UAAU,CAAC,IAAI,CAAC,wEAAwE,CAAC,CAAC;IAC5F,CAAC;IAED,OAAO;QACL,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC;QACxC,iBAAiB,EAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC;QAChD,UAAU;KACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './manifest.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/capabilities/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ // packages/mod-sdk/src/capabilities/index.ts
2
+ export * from './manifest.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/capabilities/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,cAAc,eAAe,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { z } from 'zod';
2
+ export declare const ModCapabilitiesSchema: z.ZodObject<{
3
+ id: z.ZodString;
4
+ version: z.ZodString;
5
+ hooks: z.ZodArray<z.ZodString, "many">;
6
+ apiAccess: z.ZodArray<z.ZodString, "many">;
7
+ filesystemAccess: z.ZodArray<z.ZodString, "many">;
8
+ networkAccess: z.ZodDefault<z.ZodBoolean>;
9
+ processExecution: z.ZodDefault<z.ZodBoolean>;
10
+ modifiesPrompts: z.ZodDefault<z.ZodBoolean>;
11
+ modifiesToolCalls: z.ZodDefault<z.ZodBoolean>;
12
+ modifiesModels: z.ZodDefault<z.ZodBoolean>;
13
+ learningAutonomyLevel: z.ZodDefault<z.ZodEnum<["L0", "L1", "L2", "L3", "L4", "L5", "L6"]>>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ id: string;
16
+ version: string;
17
+ hooks: string[];
18
+ apiAccess: string[];
19
+ filesystemAccess: string[];
20
+ networkAccess: boolean;
21
+ processExecution: boolean;
22
+ modifiesPrompts: boolean;
23
+ modifiesToolCalls: boolean;
24
+ modifiesModels: boolean;
25
+ learningAutonomyLevel: "L0" | "L1" | "L2" | "L3" | "L4" | "L5" | "L6";
26
+ }, {
27
+ id: string;
28
+ version: string;
29
+ hooks: string[];
30
+ apiAccess: string[];
31
+ filesystemAccess: string[];
32
+ networkAccess?: boolean | undefined;
33
+ processExecution?: boolean | undefined;
34
+ modifiesPrompts?: boolean | undefined;
35
+ modifiesToolCalls?: boolean | undefined;
36
+ modifiesModels?: boolean | undefined;
37
+ learningAutonomyLevel?: "L0" | "L1" | "L2" | "L3" | "L4" | "L5" | "L6" | undefined;
38
+ }>;
39
+ export type ModCapabilities = z.infer<typeof ModCapabilitiesSchema>;
40
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/capabilities/manifest.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuBhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ // packages/mod-sdk/src/capabilities/manifest.ts
2
+ //
3
+ // Mod capability manifest (RESEARCH.md §9). Every Mod declares its
4
+ // capabilities so the installer (M15) and validator can inspect them
5
+ // before enabling the Mod.
6
+ //
7
+ // This is the SDK's own policy model, NOT a replacement for Claude Code's
8
+ // plugin manifest. It gives the installer, validator, and security auditor
9
+ // a consistent contract to inspect before a Mod is enabled.
10
+ import { z } from 'zod';
11
+ export const ModCapabilitiesSchema = z.object({
12
+ // The Mod's unique id (kebab-case).
13
+ id: z.string().regex(/^[a-z][a-z0-9-]*$/),
14
+ version: z.string().regex(/^\d+\.\d+\.\d+$/, 'semver'),
15
+ // Event names this Mod registers handlers for.
16
+ hooks: z.array(z.string()),
17
+ // Mods API namespaces the Mod calls (e.g., ["ui.log", "fs.read"]).
18
+ apiAccess: z.array(z.string()),
19
+ // Filesystem paths or path patterns the Mod reads or writes.
20
+ filesystemAccess: z.array(z.string()),
21
+ // Whether the Mod makes network requests.
22
+ networkAccess: z.boolean().default(false),
23
+ // Whether the Mod spawns processes.
24
+ processExecution: z.boolean().default(false),
25
+ // Whether the Mod modifies submitted prompts or context.
26
+ modifiesPrompts: z.boolean().default(false),
27
+ // Whether the Mod modifies tool calls or arguments.
28
+ modifiesToolCalls: z.boolean().default(false),
29
+ // Whether the Mod changes model selection or effort.
30
+ modifiesModels: z.boolean().default(false),
31
+ // The autonomy level this Mod is allowed to operate at (for learning
32
+ // Mods; non-learning Mods default to L0 — collect evidence only).
33
+ learningAutonomyLevel: z.enum(['L0', 'L1', 'L2', 'L3', 'L4', 'L5', 'L6']).default('L0'),
34
+ });
35
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/capabilities/manifest.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,EAAE;AACF,mEAAmE;AACnE,qEAAqE;AACrE,2BAA2B;AAC3B,EAAE;AACF,0EAA0E;AAC1E,2EAA2E;AAC3E,4DAA4D;AAE5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,qBAAqB,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{
4
+ readonly ref: {
5
+ readonly plugin: string;
6
+ readonly key: string;
7
+ };
8
+ readonly initial: T;
9
+ }
10
+ /** Create an atom over one state slot; `initial` is the read fallback. */
11
+ export declare function atom<T>(ref: {
12
+ plugin: string;
13
+ key: string;
14
+ } & object, initial: T): Atom<T>;
15
+ /** The $ surface the helpers need (a real `$` or the MockRuntime's). */
16
+ type StateApi = Pick<ModsApi, 'state'>;
17
+ /** Resolve the atom's stored value, or its initial when nothing is set. */
18
+ export declare function read<T>($: StateApi, a: Atom<T>): Promise<T>;
19
+ /** Apply fn to the current value (initial when unset) and store it. */
20
+ export declare function update<T>($: StateApi, a: Atom<T>, fn: (value: T) => T): Promise<T>;
21
+ export {};
22
+ //# sourceMappingURL=claude-code-shim.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude-code-shim.d.ts","sourceRoot":"","sources":["../src/claude-code-shim.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,2DAA2D;AAC3D,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;CACrB;AAED,0EAA0E;AAC1E,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAE1F;AAED,wEAAwE;AACxE,KAAK,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAEvC,2EAA2E;AAC3E,wBAAsB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAGjE;AAED,uEAAuE;AACvE,wBAAsB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIxF"}
@@ -0,0 +1,30 @@
1
+ // packages/mod-sdk/src/claude-code-shim.ts
2
+ //
3
+ // Test-time implementation of the RUNTIME values a hooks module imports
4
+ // from the bare 'claude-code' specifier (the official state helpers
5
+ // atom / read / update — see plugins/<name>/hooks/register.ts). In a
6
+ // real session the Claude Code engine supplies them; in the kit's tests
7
+ // each plugin's vitest.config.ts aliases 'claude-code' to this module,
8
+ // whose helpers are thin wrappers over the MockRuntime's $.state (the
9
+ // same place the engine's own helpers bottom out).
10
+ //
11
+ // The signatures mirror the vendored official declarations in
12
+ // plugins/<name>/.claude-plugin/types/claude-code/index.d.ts: read()
13
+ // resolves to the stored value or the atom's initial; update() applies
14
+ // fn to the current value and stores the result.
15
+ /** Create an atom over one state slot; `initial` is the read fallback. */
16
+ export function atom(ref, initial) {
17
+ return { ref, initial };
18
+ }
19
+ /** Resolve the atom's stored value, or its initial when nothing is set. */
20
+ export async function read($, a) {
21
+ const stored = await $.state.get(a.ref);
22
+ return stored.value ?? a.initial;
23
+ }
24
+ /** Apply fn to the current value (initial when unset) and store it. */
25
+ export async function update($, a, fn) {
26
+ const value = fn(await read($, a));
27
+ await $.state.set(a.ref, value);
28
+ return value;
29
+ }
30
+ //# sourceMappingURL=claude-code-shim.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude-code-shim.js","sourceRoot":"","sources":["../src/claude-code-shim.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,EAAE;AACF,wEAAwE;AACxE,oEAAoE;AACpE,qEAAqE;AACrE,wEAAwE;AACxE,uEAAuE;AACvE,sEAAsE;AACtE,mDAAmD;AACnD,EAAE;AACF,8DAA8D;AAC9D,qEAAqE;AACrE,uEAAuE;AACvE,iDAAiD;AAUjD,0EAA0E;AAC1E,MAAM,UAAU,IAAI,CAAI,GAA6C,EAAE,OAAU;IAC/E,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;AAC1B,CAAC;AAKD,2EAA2E;AAC3E,MAAM,CAAC,KAAK,UAAU,IAAI,CAAI,CAAW,EAAE,CAAU;IACnD,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IAC3C,OAAO,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,CAAC;AACnC,CAAC;AAED,uEAAuE;AACvE,MAAM,CAAC,KAAK,UAAU,MAAM,CAAI,CAAW,EAAE,CAAU,EAAE,EAAmB;IAC1E,MAAM,KAAK,GAAG,EAAE,CAAC,MAAM,IAAI,CAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACtC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAChC,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './types/index.js';
2
+ export * from './capabilities/index.js';
3
+ export * from './middleware/index.js';
4
+ export * from './testing/index.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ // packages/mod-sdk/src/index.ts
2
+ //
3
+ // Barrel for @agentic-sdlc-kit/mod-sdk.
4
+ //
5
+ // Architectural invariant: this package imports from
6
+ // @agentic-sdlc-kit/contracts and @agentic-sdlc-kit/core (for the policy
7
+ // evaluator and secret detector that Mods consume). It does NOT import
8
+ // `claude-code`. The host SDK types are declared by the SDK itself (see
9
+ // types/events.ts).
10
+ export * from './types/index.js';
11
+ export * from './capabilities/index.js';
12
+ export * from './middleware/index.js';
13
+ export * from './testing/index.js';
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,EAAE;AACF,wCAAwC;AACxC,EAAE;AACF,qDAAqD;AACrD,yEAAyE;AACzE,uEAAuE;AACvE,wEAAwE;AACxE,oBAAoB;AAEpB,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Handler, EventName } from '../types/events.js';
2
+ export declare function compose<N extends EventName>(handlers: ReadonlyArray<Handler<N>>): Handler<N>;
3
+ //# sourceMappingURL=compose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/middleware/compose.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAoB,MAAM,oBAAoB,CAAC;AAE/E,wBAAgB,OAAO,CAAC,CAAC,SAAS,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAe5F"}
@@ -0,0 +1,28 @@
1
+ // packages/mod-sdk/src/middleware/compose.ts
2
+ //
3
+ // Compose multiple handlers for the same event into a single handler.
4
+ // Handlers run in registration order. Each handler decides whether to
5
+ // call next(e) (observe/rewrite and forward) or return a result without
6
+ // calling next (answer).
7
+ //
8
+ // This lets a Mod register multiple policies for `tool.call` (e.g., a
9
+ // shell policy, a git policy, a migration policy) without each policy
10
+ // needing to know about the others.
11
+ export function compose(handlers) {
12
+ return async ($, e, next) => {
13
+ // Build the chain from the inside out: the last handler's next is the
14
+ // caller's next; the previous handler's next is a function that calls
15
+ // the last handler with the caller's next as its next; etc.
16
+ let chain = next;
17
+ for (let i = handlers.length - 1; i >= 0; i--) {
18
+ const h = handlers[i];
19
+ if (!h)
20
+ continue;
21
+ const currentNext = chain;
22
+ const currentHandler = h;
23
+ chain = (ev) => currentHandler($, ev, currentNext);
24
+ }
25
+ return chain(e);
26
+ };
27
+ }
28
+ //# sourceMappingURL=compose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/middleware/compose.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,wEAAwE;AACxE,yBAAyB;AACzB,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,oCAAoC;AAIpC,MAAM,UAAU,OAAO,CAAsB,QAAmC;IAC9E,OAAO,KAAK,EAAE,CAAU,EAAE,CAAa,EAAE,IAAmD,EAAE,EAAE;QAC9F,sEAAsE;QACtE,sEAAsE;QACtE,4DAA4D;QAC5D,IAAI,KAAK,GAAkD,IAAI,CAAC;QAChE,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9C,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;YACtB,IAAI,CAAC,CAAC;gBAAE,SAAS;YACjB,MAAM,WAAW,GAAG,KAAK,CAAC;YAC1B,MAAM,cAAc,GAAG,CAAC,CAAC;YACzB,KAAK,GAAG,CAAC,EAAc,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './compose.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,3 @@
1
+ // packages/mod-sdk/src/middleware/index.ts
2
+ export * from './compose.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,cAAc,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './mock-runtime.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ // packages/mod-sdk/src/testing/index.ts
2
+ export * from './mock-runtime.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,96 @@
1
+ import type { EventName, EventOf, ModsApi, On, RegisterFn, StateRef } from '../types/events.js';
2
+ export interface FireResult {
3
+ value: unknown;
4
+ answered: boolean;
5
+ forwarded: boolean;
6
+ terminalEvent?: unknown;
7
+ chunks: unknown[];
8
+ }
9
+ export declare class MockRuntime {
10
+ private registrations;
11
+ private logs;
12
+ private statuses;
13
+ private stateStore;
14
+ private poisonedStateKeys;
15
+ private fsStore;
16
+ private fsListings;
17
+ private askAnswers;
18
+ private processResults;
19
+ private processCalls;
20
+ private registeredCommands;
21
+ private clockNowMs;
22
+ private sessionIdentifier;
23
+ private sessionCwd;
24
+ private hostResult;
25
+ private hostChunks;
26
+ constructor(nowMs?: number);
27
+ readonly api: ModsApi;
28
+ /**
29
+ * The `on` function passed to a Mod's register(). Captures registrations
30
+ * and returns a registration object with a .catch(handler) method, the
31
+ * same shape the real host returns.
32
+ */
33
+ readonly on: On;
34
+ /**
35
+ * Load a Mod by calling its register function with this runtime's `on`.
36
+ */
37
+ load(register: RegisterFn): void;
38
+ /**
39
+ * Fire an event. Builds the middleware chain from every registration
40
+ * whose matcher accepts the event (registration order = outside-in, the
41
+ * same order the host stacks hooks) and returns what the host would see.
42
+ */
43
+ fire<N extends EventName>(event: N, e: EventOf<N>): Promise<FireResult>;
44
+ /**
45
+ * Get the captured UI logs (from $.ui.log calls).
46
+ */
47
+ getLogs(): string[];
48
+ /**
49
+ * Get the captured status lines (from $.ui.status calls).
50
+ */
51
+ getStatuses(): string[];
52
+ /**
53
+ * Get the number of registrations for a given event.
54
+ */
55
+ registrationCount(event?: EventName): number;
56
+ /** Set mock filesystem content for $.fs.read. */
57
+ setFile(path: string, content: string): void;
58
+ /** Set a mock directory listing for $.fs.list. */
59
+ setListing(path: string, entries: string[]): void;
60
+ /** Get the recorded state (for assertions). */
61
+ getState<T>(ref: StateRef): T | undefined;
62
+ /** Set state a test wants a hook to read via $.state.get. */
63
+ setState<T>(ref: StateRef, value: T): void;
64
+ /** Make $.state.get throw for a key (to exercise fail-closed .catch). */
65
+ poisonState(plugin: string, key: string): void;
66
+ /** Queue the labels $.ui.ask resolves to, in order (FIFO). */
67
+ queueAskAnswers(...answers: string[]): void;
68
+ /** Queue $.process.run results, in order (FIFO). */
69
+ queueProcessResults(...results: Array<{
70
+ stdout: string;
71
+ stderr?: string;
72
+ exitCode?: number;
73
+ }>): void;
74
+ /** The argument arrays $.process.run was called with, in order. */
75
+ getProcessCalls(): Array<ReadonlyArray<string>>;
76
+ /** Commands registered via $.command.register. */
77
+ getRegisteredCommands(): Array<{
78
+ name: string;
79
+ description: string;
80
+ }>;
81
+ /** Set what the host's own behavior resolves to (the terminal next). */
82
+ setHostResult(value: unknown): void;
83
+ /** Set the chunks the host streams for turn.step. */
84
+ setHostChunks(chunks: unknown[]): void;
85
+ /** Set the mock clock (ms since epoch) — `await $.clock.now()` returns it. */
86
+ setNow(nowMs: number): void;
87
+ /** Advance the mock clock. */
88
+ advanceClock(ms: number): void;
89
+ /** The current mock clock value. */
90
+ now(): number;
91
+ /** Set the session identity `await $.session.id()` returns. */
92
+ setSession(sessionId: string, cwd?: string): void;
93
+ private static refKey;
94
+ private matcherMatches;
95
+ }
96
+ //# sourceMappingURL=mock-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock-runtime.d.ts","sourceRoot":"","sources":["../../src/testing/mock-runtime.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EAEP,OAAO,EACP,EAAE,EACF,UAAU,EAEV,QAAQ,EACT,MAAM,oBAAoB,CAAC;AAW5B,MAAM,WAAW,UAAU;IAGzB,KAAK,EAAE,OAAO,CAAC;IAEf,QAAQ,EAAE,OAAO,CAAC;IAElB,SAAS,EAAE,OAAO,CAAC;IAGnB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAqBD,qBAAa,WAAW;IACtB,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,IAAI,CAAgB;IAC5B,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,iBAAiB,CAAqB;IAC9C,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,UAAU,CAAgC;IAGlD,OAAO,CAAC,UAAU,CAAgB;IAGlC,OAAO,CAAC,cAAc,CAAmE;IACzF,OAAO,CAAC,YAAY,CAAoC;IACxD,OAAO,CAAC,kBAAkB,CAAoD;IAC9E,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,iBAAiB,CAAkB;IAC3C,O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