@davidorex/pi-jit-agents 0.14.6

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 (50) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/README.md +45 -0
  3. package/dist/agent-spec.d.ts +24 -0
  4. package/dist/agent-spec.d.ts.map +1 -0
  5. package/dist/agent-spec.js +126 -0
  6. package/dist/agent-spec.js.map +1 -0
  7. package/dist/agent-trace-sdk.d.ts +42 -0
  8. package/dist/agent-trace-sdk.d.ts.map +1 -0
  9. package/dist/agent-trace-sdk.js +177 -0
  10. package/dist/agent-trace-sdk.js.map +1 -0
  11. package/dist/compile.d.ts +17 -0
  12. package/dist/compile.d.ts.map +1 -0
  13. package/dist/compile.js +118 -0
  14. package/dist/compile.js.map +1 -0
  15. package/dist/errors.d.ts +36 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/errors.js +56 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/index.d.ts +22 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +18 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/introspect.d.ts +17 -0
  24. package/dist/introspect.d.ts.map +1 -0
  25. package/dist/introspect.js +22 -0
  26. package/dist/introspect.js.map +1 -0
  27. package/dist/jit-runtime.d.ts +106 -0
  28. package/dist/jit-runtime.d.ts.map +1 -0
  29. package/dist/jit-runtime.js +583 -0
  30. package/dist/jit-runtime.js.map +1 -0
  31. package/dist/template.d.ts +36 -0
  32. package/dist/template.d.ts.map +1 -0
  33. package/dist/template.js +78 -0
  34. package/dist/template.js.map +1 -0
  35. package/dist/trace-redactor.d.ts +43 -0
  36. package/dist/trace-redactor.d.ts.map +1 -0
  37. package/dist/trace-redactor.js +173 -0
  38. package/dist/trace-redactor.js.map +1 -0
  39. package/dist/trace-writer.d.ts +13 -0
  40. package/dist/trace-writer.d.ts.map +1 -0
  41. package/dist/trace-writer.js +112 -0
  42. package/dist/trace-writer.js.map +1 -0
  43. package/dist/types.d.ts +185 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/types.js +2 -0
  46. package/dist/types.js.map +1 -0
  47. package/package.json +71 -0
  48. package/schemas/agent-trace.schema.json +191 -0
  49. package/schemas/trace-config.schema.json +58 -0
  50. package/schemas/verdict.schema.json +14 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@davidorex/pi-jit-agents",
3
+ "version": "0.14.6",
4
+ "description": "Agent spec compilation and in-process dispatch runtime — the package that owns everything between 'I have a spec' and 'I have a typed result'",
5
+ "license": "MIT",
6
+ "author": "David Ryan",
7
+ "type": "module",
8
+ "keywords": [
9
+ "pi-package"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/davidorex/pi-project-workflows.git",
14
+ "directory": "packages/pi-jit-agents"
15
+ },
16
+ "homepage": "https://github.com/davidorex/pi-project-workflows/tree/main/packages/pi-jit-agents",
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "./types": {
25
+ "types": "./dist/types.d.ts",
26
+ "default": "./dist/types.js"
27
+ },
28
+ "./agent-spec": {
29
+ "types": "./dist/agent-spec.d.ts",
30
+ "default": "./dist/agent-spec.js"
31
+ },
32
+ "./template": {
33
+ "types": "./dist/template.d.ts",
34
+ "default": "./dist/template.js"
35
+ },
36
+ "./compile": {
37
+ "types": "./dist/compile.d.ts",
38
+ "default": "./dist/compile.js"
39
+ },
40
+ "./runtime": {
41
+ "types": "./dist/jit-runtime.d.ts",
42
+ "default": "./dist/jit-runtime.js"
43
+ },
44
+ "./introspect": {
45
+ "types": "./dist/introspect.d.ts",
46
+ "default": "./dist/introspect.js"
47
+ }
48
+ },
49
+ "files": [
50
+ "dist/",
51
+ "schemas/",
52
+ "*.md"
53
+ ],
54
+ "scripts": {
55
+ "clean": "rm -rf dist",
56
+ "build": "tsc -p tsconfig.build.json",
57
+ "prepublishOnly": "npm run clean && npm run build",
58
+ "test": "tsx --test src/*.test.ts"
59
+ },
60
+ "dependencies": {
61
+ "@davidorex/pi-project": "^0.14.6",
62
+ "@mariozechner/pi-ai": "^0.70.2",
63
+ "nunjucks": "^3.2.4",
64
+ "proper-lockfile": "^4.1.2",
65
+ "yaml": "^2.7.1"
66
+ },
67
+ "devDependencies": {
68
+ "@types/nunjucks": "^3.2.6",
69
+ "@types/proper-lockfile": "^4.1.4"
70
+ }
71
+ }
@@ -0,0 +1,191 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Agent Trace Entry",
4
+ "description": "Discriminated union of trace events emitted during pi-jit-agents executeAgent invocations for monitor-classify pipelines. Each entry validates a single JSONL line; the .jsonl file as a whole is not a single JSON document. Per DEC-0004 the structural shape ({ type, id, parentId, timestamp, ...extra }) mirrors pi-coding-agent's SessionEntry but is deliberately a separate schema namespace — there is no literal inheritance. Per DEC-0005 these entries are produced by a push-write trace stream divergent from pi-mono's pull/replay model, so each variant is fired at the moment of occurrence inside executeAgent rather than reconstructed after the fact. The six variants form a parent-chained tree: session_start (root) → classify_call → { classify_response, context_collection } → verdict_decision; trace_end closes the session at the executeAgent exit boundary.",
5
+ "oneOf": [
6
+ { "$ref": "#/definitions/session_start" },
7
+ { "$ref": "#/definitions/classify_call" },
8
+ { "$ref": "#/definitions/classify_response" },
9
+ { "$ref": "#/definitions/context_collection" },
10
+ { "$ref": "#/definitions/verdict_decision" },
11
+ { "$ref": "#/definitions/trace_end" }
12
+ ],
13
+ "definitions": {
14
+ "traceId": {
15
+ "type": "string",
16
+ "pattern": "^[0-9A-HJKMNP-TV-Z]{26}$",
17
+ "description": "ULID — 26-character Crockford base32, lexicographically sortable, monotonic-by-timestamp. Chosen over UUIDv4 because trace lines are append-ordered and parent/child pairs benefit from sortable IDs; chosen over a monotonic counter because ULIDs do not require shared-state coordination across concurrent executeAgent calls."
18
+ },
19
+ "isoTimestamp": {
20
+ "type": "string",
21
+ "format": "date-time",
22
+ "description": "ISO 8601 timestamp captured at event emission."
23
+ },
24
+ "verdictResult": {
25
+ "type": "object",
26
+ "additionalProperties": false,
27
+ "required": ["verdict"],
28
+ "properties": {
29
+ "verdict": {
30
+ "type": "string",
31
+ "enum": ["clean", "flag", "new", "error"],
32
+ "description": "Final classification verdict. clean/flag/new mirror the verdict.schema.json contract; error indicates the dispatch itself failed before a verdict could be produced."
33
+ },
34
+ "description": { "type": "string" },
35
+ "severity": { "type": "string" },
36
+ "newPattern": { "type": "string" }
37
+ }
38
+ },
39
+ "usage": {
40
+ "type": "object",
41
+ "additionalProperties": false,
42
+ "required": ["inputTokens", "outputTokens", "totalTokens"],
43
+ "properties": {
44
+ "inputTokens": { "type": "number" },
45
+ "outputTokens": { "type": "number" },
46
+ "cacheRead": { "type": "number" },
47
+ "cacheWrite": { "type": "number" },
48
+ "totalTokens": { "type": "number" }
49
+ }
50
+ },
51
+ "contentBlock": {
52
+ "type": "object",
53
+ "required": ["type"],
54
+ "properties": {
55
+ "type": {
56
+ "type": "string",
57
+ "enum": ["text", "thinking", "toolCall"]
58
+ }
59
+ },
60
+ "description": "Permissive content-block shape. pi-ai's content payload schema evolves (text, thinking blocks, tool calls with arbitrary arguments); we pin the discriminator field but leave the rest open so trace capture does not break on upstream additions."
61
+ },
62
+ "session_start": {
63
+ "type": "object",
64
+ "additionalProperties": false,
65
+ "required": ["type", "id", "parentId", "timestamp", "sessionId", "agentName", "model", "cwd"],
66
+ "properties": {
67
+ "type": { "const": "session_start" },
68
+ "id": { "$ref": "#/definitions/traceId" },
69
+ "parentId": {
70
+ "type": "null",
71
+ "description": "session_start is the trace root; parentId is always null."
72
+ },
73
+ "timestamp": { "$ref": "#/definitions/isoTimestamp" },
74
+ "sessionId": {
75
+ "type": "string",
76
+ "description": "Identifier for the trace session — typically the same ULID as id, used as a foreign key from downstream variants for filesystem-level grouping."
77
+ },
78
+ "monitorName": {
79
+ "type": ["string", "null"],
80
+ "description": "Monitor name when the agent is dispatched as a monitor classifier; null or absent for non-monitor traces."
81
+ },
82
+ "agentName": { "type": "string" },
83
+ "model": {
84
+ "type": "string",
85
+ "description": "Provider-qualified model identifier, e.g., openrouter/anthropic/claude-sonnet-4.6."
86
+ },
87
+ "cwd": { "type": "string" }
88
+ }
89
+ },
90
+ "classify_call": {
91
+ "type": "object",
92
+ "additionalProperties": false,
93
+ "required": ["type", "id", "parentId", "timestamp", "renderedPrompt", "inputText"],
94
+ "properties": {
95
+ "type": { "const": "classify_call" },
96
+ "id": { "$ref": "#/definitions/traceId" },
97
+ "parentId": {
98
+ "$ref": "#/definitions/traceId",
99
+ "description": "References the parent session_start.id."
100
+ },
101
+ "timestamp": { "$ref": "#/definitions/isoTimestamp" },
102
+ "renderedPrompt": {
103
+ "type": "string",
104
+ "description": "Post-Nunjucks-render prompt as actually sent to the model."
105
+ },
106
+ "inputText": {
107
+ "type": "string",
108
+ "description": "Primary input under classification — typically the assistant_text collector payload."
109
+ }
110
+ }
111
+ },
112
+ "classify_response": {
113
+ "type": "object",
114
+ "additionalProperties": false,
115
+ "required": ["type", "id", "parentId", "timestamp", "stopReason", "usage", "content"],
116
+ "properties": {
117
+ "type": { "const": "classify_response" },
118
+ "id": { "$ref": "#/definitions/traceId" },
119
+ "parentId": {
120
+ "$ref": "#/definitions/traceId",
121
+ "description": "References the parent classify_call.id."
122
+ },
123
+ "timestamp": { "$ref": "#/definitions/isoTimestamp" },
124
+ "stopReason": { "type": "string" },
125
+ "errorMessage": { "type": "string" },
126
+ "usage": { "$ref": "#/definitions/usage" },
127
+ "content": {
128
+ "type": "array",
129
+ "items": { "$ref": "#/definitions/contentBlock" }
130
+ }
131
+ }
132
+ },
133
+ "context_collection": {
134
+ "type": "object",
135
+ "additionalProperties": false,
136
+ "required": ["type", "id", "parentId", "timestamp", "collectorId", "collectedValue", "collectionTimeMs"],
137
+ "properties": {
138
+ "type": { "const": "context_collection" },
139
+ "id": { "$ref": "#/definitions/traceId" },
140
+ "parentId": {
141
+ "$ref": "#/definitions/traceId",
142
+ "description": "References the parent classify_call.id; one context_collection entry is fired per resolved collector."
143
+ },
144
+ "timestamp": { "$ref": "#/definitions/isoTimestamp" },
145
+ "collectorId": {
146
+ "type": "string",
147
+ "description": "Collector identifier, e.g., assistant_text, recent_files, conversation_window."
148
+ },
149
+ "collectedValue": {
150
+ "description": "Permissive — collectors return strings, arrays, or objects depending on collector kind. No constraint imposed at the trace layer; redaction occurs at TraceRedactor (T2) before this field is written."
151
+ },
152
+ "collectionTimeMs": { "type": "number" }
153
+ }
154
+ },
155
+ "verdict_decision": {
156
+ "type": "object",
157
+ "additionalProperties": false,
158
+ "required": ["type", "id", "parentId", "timestamp", "finalResult", "mappingDecisionRationale"],
159
+ "properties": {
160
+ "type": { "const": "verdict_decision" },
161
+ "id": { "$ref": "#/definitions/traceId" },
162
+ "parentId": {
163
+ "$ref": "#/definitions/traceId",
164
+ "description": "References the parent classify_response.id."
165
+ },
166
+ "timestamp": { "$ref": "#/definitions/isoTimestamp" },
167
+ "finalResult": { "$ref": "#/definitions/verdictResult" },
168
+ "mappingDecisionRationale": {
169
+ "type": "string",
170
+ "description": "Brief description of the verdict-mapping path — which tool-call argument or fallback rule produced the verdict."
171
+ }
172
+ }
173
+ },
174
+ "trace_end": {
175
+ "type": "object",
176
+ "additionalProperties": false,
177
+ "required": ["type", "id", "parentId", "timestamp", "totalDurationMs", "verdict"],
178
+ "properties": {
179
+ "type": { "const": "trace_end" },
180
+ "id": { "$ref": "#/definitions/traceId" },
181
+ "parentId": {
182
+ "$ref": "#/definitions/traceId",
183
+ "description": "References the parent session_start.id; trace_end closes the session at executeAgent exit."
184
+ },
185
+ "timestamp": { "$ref": "#/definitions/isoTimestamp" },
186
+ "totalDurationMs": { "type": "number" },
187
+ "verdict": { "$ref": "#/definitions/verdictResult" }
188
+ }
189
+ }
190
+ }
191
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Trace Config",
4
+ "description": "Per-monitor trace-redaction configuration loaded by TraceRedactor (T2) from .workflows/monitors/<name>/trace-config.json. Declares (a) regex patterns whose matches should be redacted before write, and (b) named domains that group patterns by data class. The TraceWriter (T4) consults this config before emitting each TraceEntry; collectedValue, renderedPrompt, inputText, and content fields are scanned and substituted per the patterns array. Domain entries carry data_class metadata for downstream policy enforcement and audit reporting.",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["version", "patterns", "domains"],
8
+ "properties": {
9
+ "version": {
10
+ "type": "string",
11
+ "const": "1.0",
12
+ "description": "Trace-config schema version. Currently fixed at 1.0; bumped when the patterns/domains structure changes incompatibly."
13
+ },
14
+ "patterns": {
15
+ "type": "array",
16
+ "description": "Ordered list of regex patterns evaluated against trace fields. First-match-wins is not implied at this layer — the TraceRedactor decides composition policy.",
17
+ "items": {
18
+ "type": "object",
19
+ "additionalProperties": false,
20
+ "required": ["name", "regex", "domain"],
21
+ "properties": {
22
+ "name": {
23
+ "type": "string",
24
+ "description": "Human-readable identifier for the pattern, e.g., aws_access_key, email_address."
25
+ },
26
+ "regex": {
27
+ "type": "string",
28
+ "description": "Regex source string. Compiled by TraceRedactor at config load time; invalid regex fails fast before any trace is written."
29
+ },
30
+ "domain": {
31
+ "type": "string",
32
+ "description": "Name of a domain entry under domains. The pattern's match is associated with that domain's data_class for policy and reporting."
33
+ }
34
+ }
35
+ }
36
+ },
37
+ "domains": {
38
+ "type": "object",
39
+ "description": "Map of domain name → metadata. Keys are referenced by patterns[].domain. Additional domain entries are user-extensible.",
40
+ "additionalProperties": {
41
+ "type": "object",
42
+ "additionalProperties": false,
43
+ "required": ["description", "data_class"],
44
+ "properties": {
45
+ "description": {
46
+ "type": "string",
47
+ "description": "Free-form description of what this domain represents (e.g., 'Cloud provider credentials')."
48
+ },
49
+ "data_class": {
50
+ "type": "string",
51
+ "enum": ["public", "internal", "confidential", "restricted"],
52
+ "description": "Sensitivity classification. Drives downstream policy — restricted domains may block trace persistence entirely; confidential triggers stronger redaction; internal/public are informational."
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "type": "object",
3
+ "required": ["verdict"],
4
+ "properties": {
5
+ "verdict": { "type": "string", "enum": ["CLEAN", "FLAG", "NEW"] },
6
+ "description": { "type": "string" },
7
+ "newPattern": { "type": "string" },
8
+ "severity": { "type": "string", "enum": ["info", "warning", "critical"] }
9
+ },
10
+ "allOf": [
11
+ { "if": { "properties": { "verdict": { "const": "FLAG" } } }, "then": { "required": ["verdict", "description"] } },
12
+ { "if": { "properties": { "verdict": { "const": "NEW" } } }, "then": { "required": ["verdict", "description", "newPattern"] } }
13
+ ]
14
+ }