@jigging/agent-method 0.0.0 → 0.1.0-alpha.4

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 (52) hide show
  1. package/AGENTS.md +98 -0
  2. package/FLOW.contract.json +241 -0
  3. package/FLOW.meta.json +8 -0
  4. package/FLOW.ts +3 -0
  5. package/LICENSE +373 -0
  6. package/README.md +369 -0
  7. package/THIRD_PARTY_NOTICES +9 -0
  8. package/contracts/acp-public-updates.json +75 -0
  9. package/contracts/agent-commands.json +88 -0
  10. package/contracts/agent-replies.json +202 -0
  11. package/contracts/http-request/contract.json +37 -0
  12. package/dist/api.d.ts +11 -0
  13. package/dist/api.js +164 -0
  14. package/dist/conversation.d.ts +68 -0
  15. package/dist/conversation.js +346 -0
  16. package/dist/errors.d.ts +5 -0
  17. package/dist/errors.js +8 -0
  18. package/dist/flow.d.ts +3 -0
  19. package/dist/flow.js +2784 -0
  20. package/dist/index.d.ts +67 -0
  21. package/dist/index.js +220 -0
  22. package/dist/json.d.ts +21 -0
  23. package/dist/json.js +409 -0
  24. package/dist/schema.d.ts +7 -0
  25. package/dist/schema.js +180 -0
  26. package/dist/skills.d.ts +3 -0
  27. package/dist/skills.js +132 -0
  28. package/dist/values.d.ts +11 -0
  29. package/dist/values.js +65 -0
  30. package/justfile +32 -0
  31. package/licenses/flow.LICENSE +202 -0
  32. package/package.json +45 -5
  33. package/settings.schema.json +12 -0
  34. package/skills/answer-check/SKILL.md +5 -0
  35. package/src/api.ts +191 -0
  36. package/src/conversation.ts +387 -0
  37. package/src/errors.ts +11 -0
  38. package/src/flow.ts +66 -0
  39. package/src/index.ts +325 -0
  40. package/src/json.ts +406 -0
  41. package/src/schema.ts +230 -0
  42. package/src/skills.ts +138 -0
  43. package/src/values.ts +77 -0
  44. package/test/api.test.ts +326 -0
  45. package/test/conversation-fixture.ts +73 -0
  46. package/test/conversation.test.ts +328 -0
  47. package/test/json.test.ts +88 -0
  48. package/test/method.test.ts +308 -0
  49. package/test/pack.test.ts +81 -0
  50. package/test/result.test.ts +103 -0
  51. package/test/skills-flow.test.ts +252 -0
  52. package/tsconfig.json +17 -0
package/AGENTS.md ADDED
@@ -0,0 +1,98 @@
1
+ # Reusable Agent method
2
+
3
+ ## Purpose
4
+
5
+ Make a bounded Agent procedure independently reusable as a library and an
6
+ ordinary Flow, preserving operator ownership of Agent execution.
7
+
8
+ ## Ownership
9
+
10
+ - `src/` owns prompt preparation, structured schema checking, JSON/0 decoding,
11
+ result assembly, the optional package Skill reader, and ordinary Run/0 wiring.
12
+ - The root `FLOW.ts` invokes the bundled runtime; it performs no implicit Skill reads.
13
+ - `contracts/http-request/` mirrors the ordinary
14
+ Flow's exact delegated HTTP interface. Canonical descriptors live under
15
+ `docs/jig/spec/contracts/`.
16
+ - Package source, declarations, built runtime, licenses, tests, and build
17
+ instructions form one release artifact.
18
+ - `justfile` owns explicit builds and ordinary `bun pm pack` distribution.
19
+ Bun converts declared workspace versions to registry versions when packing;
20
+ no dependency archives or private installation convention are included.
21
+
22
+ ## Local Contracts
23
+
24
+ - Pure exports perform no provider dispatch or filesystem access. The separate
25
+ `./skills` export reads only explicitly selected package-local Skill trees.
26
+ - `./conversation` composes the public Agent Run contract through ordinary
27
+ calls and channels. It owns correlation, local endpoint disposal and an
28
+ uncancelled invocation waiter; it imports no native or private host code.
29
+ Received turn outcomes and final invocation settlement remain distinct.
30
+ Final receipt presence must match the initial session request; malformed or
31
+ unsolicited receipts fail without discarding settled turn evidence.
32
+ Callback or cleanup failures retain received turns in `AgentConversationError`.
33
+ Optional synchronous `onEvent` owns its public update channel and reports
34
+ observation loss separately from execution settlement. It never privately
35
+ echoes filtered data or requires a Log grant. Async routing uses `events`.
36
+ Resolve commands, replies and updates through the caller's declared Agent
37
+ slot; callers do not supply a separately synchronized contract directory.
38
+ - Session requests are invocation metadata, separate from rendered instructions
39
+ and transport requests. `prepareAgent` validates and snapshots them;
40
+ `finishAgent` assembles answer facts only. `checkAgentResult` validates optional
41
+ final session receipts without granting authority or reading retained state.
42
+ Unavailable receipts require one of the contract's closed retention reasons;
43
+ neither missing reasons nor arbitrary diagnostic text are accepted.
44
+ Follow-up conversation prompts cannot change session intent; the receipt belongs
45
+ to final invocation settlement, never an individual turn reply.
46
+ Optional `lifetime: 'run'` on a new retention request restricts continuation
47
+ to its owning root. Restore inherits lifetime; the host owns enforcement and
48
+ deletion, not this library or the method.
49
+ - The HTTP Flow rejects conversational mode and any session request before resource dispatch. Its
50
+ shared Agent contract does not imply support for native continuing sessions.
51
+ Its metadata declares `supports: []`; one-shot consumers need no optional
52
+ feature requirements. The shared descriptor catalog never grants a feature.
53
+ - The ordinary Flow owns one non-streaming text-only Chat Completions or
54
+ Responses exchange through its HTTP slot. Closed API/model/token settings
55
+ are checked before dispatch. `structuredOutput: 'json-schema'` explicitly
56
+ adds the API's strict schema request; prompt mode is the default. Both modes
57
+ check results locally and never fall back or retry on rejection.
58
+ Endpoint, credentials and request policy belong to the host grant. No retries,
59
+ native Agent dependency, channel projection or direct networking. Skill contents
60
+ and guidance arrive as explicit caller data, not host-authenticated provenance.
61
+ `FLOW.contract.json` offers the exact Agent Run interface; an unsupported
62
+ optional channel rejects before HTTP dispatch.
63
+ - `settings.schema.json` owns API/model/token/output-mode authoring validation.
64
+ The HTTP call requests decoded JSON/0 responses. Its 8 MiB request / 12 MiB
65
+ response ceilings do not increase the operator's smaller default grant or
66
+ JSON/0 value limits; reject oversized requests before dispatch, never truncate.
67
+ - Preserve the shared 64-group, 1,024-item, 1 MiB content and 1 MiB rendered
68
+ prompt limits. Reject duplicate selections, invalid UTF-8 and symlinks.
69
+ - Runtime dependencies are bundled; installed consumers need no build hook.
70
+ - The source workspace uses `workspace:*` for SDK development. Extracted source
71
+ uses the packed versioned development dependencies and an ordinary Bun lock.
72
+ Publish dependencies before packages that require them for source rebuilds.
73
+ - The ordinary ACP package imports this same method. `checkAgentResult` lets
74
+ consumers independently check any selected
75
+ Agent's dynamic structured result; it grants no authority or provenance.
76
+
77
+ ## Work Guidance
78
+
79
+ - Keep the bounded JSON/0 codec and schema profile local; no sibling private
80
+ imports or general provider/schema framework.
81
+ - Update source and rebuild the corresponding packed runtime when adapting the
82
+ method. Do not edit generated `dist/` files.
83
+
84
+ ## Verification
85
+
86
+ - The build clears only generated `dist/` before compiling, so removed source
87
+ cannot survive in the packed runtime or declaration files.
88
+
89
+ - `just build` compiles declarations and bundles the ordinary runtime.
90
+ - `just test` checks the method, JSON/0, bounded reader, and Flow wiring.
91
+ Session tests cover strict opaque references, immutable metadata and receipts,
92
+ unchanged model prompts, and pre-dispatch HTTP refusal.
93
+ - `just pack --destination <directory>` builds the complete archive explicitly.
94
+ - After building, `bun pm pack --ignore-scripts --destination <directory>` packs
95
+ existing output. Package tests verify source, ordinary dependency versions,
96
+ standalone runtime imports and repacking without mutating workspace manifests.
97
+
98
+ ## Child DOX Index
@@ -0,0 +1,241 @@
1
+ {
2
+ "$schema": "https://flow.jig.md/schemas/invocation-contract-0.schema.json",
3
+ "id": "https://jig.md/contracts/agent-run",
4
+ "version": "0.1.0",
5
+ "features": {
6
+ "events": "Implements the optional public-update protocol, including honest observation loss.",
7
+ "conversation": "Implements conversational commands, replies, turn results and final settlement; prompt allowances remain separately granted.",
8
+ "sessions": "Implements retain/restore requests and final receipts, including run-scoped state and honest unavailability; authority and successful retention are separate."
9
+ },
10
+ "input": {
11
+ "$ref": "#/$defs/RunInput"
12
+ },
13
+ "result": {
14
+ "oneOf": [
15
+ {
16
+ "type": "object",
17
+ "properties": {
18
+ "outcome": {
19
+ "const": "done"
20
+ },
21
+ "output": {
22
+ "$ref": "#/$defs/AgentOutput"
23
+ }
24
+ },
25
+ "required": ["outcome", "output"],
26
+ "additionalProperties": false
27
+ },
28
+ {
29
+ "type": "object",
30
+ "properties": {
31
+ "outcome": {
32
+ "const": "blocked"
33
+ },
34
+ "output": {
35
+ "$ref": "#/$defs/AgentOutput"
36
+ }
37
+ },
38
+ "required": ["outcome", "output"],
39
+ "additionalProperties": false
40
+ },
41
+ {
42
+ "type": "object",
43
+ "properties": {
44
+ "outcome": {
45
+ "const": "limit"
46
+ },
47
+ "output": {
48
+ "$ref": "#/$defs/AgentOutput"
49
+ }
50
+ },
51
+ "required": ["outcome", "output"],
52
+ "additionalProperties": false
53
+ },
54
+ {
55
+ "type": "object",
56
+ "properties": {
57
+ "outcome": {
58
+ "const": "done"
59
+ },
60
+ "output": {
61
+ "type": "object",
62
+ "properties": {
63
+ "session": {
64
+ "$ref": "#/$defs/SessionReceipt"
65
+ },
66
+ "turns": {
67
+ "type": "integer",
68
+ "minimum": 1,
69
+ "maximum": 8
70
+ }
71
+ },
72
+ "required": ["turns"],
73
+ "additionalProperties": false
74
+ }
75
+ },
76
+ "required": ["outcome", "output"],
77
+ "additionalProperties": false
78
+ }
79
+ ]
80
+ },
81
+ "outcomes": {
82
+ "blocked": "The Agent completed its bounded response but reported that the requested work is blocked.",
83
+ "limit": "The Agent completed its bounded response but reported an Agent limit; host deadline and cancellation remain operational failures."
84
+ },
85
+ "channels": {
86
+ "events": {
87
+ "direction": "send",
88
+ "required": false,
89
+ "contract": "./contracts/acp-public-updates.json"
90
+ },
91
+ "commands": {
92
+ "direction": "receive",
93
+ "required": false,
94
+ "delivery": "direct",
95
+ "contract": "./contracts/agent-commands.json"
96
+ },
97
+ "replies": {
98
+ "direction": "send",
99
+ "required": false,
100
+ "delivery": "direct",
101
+ "contract": "./contracts/agent-replies.json"
102
+ }
103
+ },
104
+ "$defs": {
105
+ "SessionRequest": {
106
+ "oneOf": [
107
+ {
108
+ "type": "object",
109
+ "properties": { "retain": { "const": true }, "lifetime": { "const": "run" } },
110
+ "required": ["retain"],
111
+ "additionalProperties": false
112
+ },
113
+ {
114
+ "type": "object",
115
+ "properties": {
116
+ "restore": { "type": "string", "minLength": 36, "maxLength": 36 }
117
+ },
118
+ "required": ["restore"],
119
+ "additionalProperties": false
120
+ }
121
+ ]
122
+ },
123
+ "SessionReceipt": {
124
+ "oneOf": [
125
+ {
126
+ "type": "object",
127
+ "properties": {
128
+ "status": { "const": "retained" },
129
+ "reference": { "type": "string", "minLength": 36, "maxLength": 36 }
130
+ },
131
+ "required": ["status", "reference"],
132
+ "additionalProperties": false
133
+ },
134
+ {
135
+ "type": "object",
136
+ "properties": {
137
+ "status": { "const": "unavailable" },
138
+ "reason": {
139
+ "enum": ["not-cleanly-closed", "missing-history", "unsupported-history", "capacity"]
140
+ }
141
+ },
142
+ "required": ["status", "reason"],
143
+ "additionalProperties": false
144
+ }
145
+ ]
146
+ },
147
+ "RunInput": {
148
+ "type": "object",
149
+ "properties": {
150
+ "instructions": {
151
+ "type": "string",
152
+ "minLength": 1,
153
+ "maxLength": 1048576
154
+ },
155
+ "skills": {
156
+ "$ref": "#/$defs/SkillContents"
157
+ },
158
+ "responseSchema": {
159
+ "type": "object"
160
+ },
161
+ "guidance": {
162
+ "type": "array",
163
+ "maxItems": 64,
164
+ "items": {
165
+ "type": "object",
166
+ "properties": {
167
+ "label": {
168
+ "type": "string",
169
+ "minLength": 1
170
+ },
171
+ "text": {
172
+ "type": "string"
173
+ }
174
+ },
175
+ "required": ["label", "text"],
176
+ "additionalProperties": false
177
+ }
178
+ },
179
+ "conversation": {
180
+ "const": true
181
+ },
182
+ "session": {
183
+ "$ref": "#/$defs/SessionRequest"
184
+ }
185
+ },
186
+ "required": ["instructions"],
187
+ "additionalProperties": false
188
+ },
189
+ "AgentOutput": {
190
+ "type": "object",
191
+ "properties": {
192
+ "text": {
193
+ "type": "string",
194
+ "maxLength": 8388608
195
+ },
196
+ "structured": true,
197
+ "session": {
198
+ "$ref": "#/$defs/SessionReceipt"
199
+ }
200
+ },
201
+ "required": ["text"],
202
+ "additionalProperties": false
203
+ },
204
+ "SkillContents": {
205
+ "type": "array",
206
+ "maxItems": 64,
207
+ "items": {
208
+ "type": "object",
209
+ "properties": {
210
+ "name": {
211
+ "type": "string",
212
+ "minLength": 1,
213
+ "maxLength": 64
214
+ },
215
+ "files": {
216
+ "type": "array",
217
+ "maxItems": 1024,
218
+ "items": {
219
+ "type": "object",
220
+ "properties": {
221
+ "path": {
222
+ "type": "string",
223
+ "minLength": 1,
224
+ "maxLength": 4096
225
+ },
226
+ "text": {
227
+ "type": "string",
228
+ "maxLength": 1048576
229
+ }
230
+ },
231
+ "required": ["path", "text"],
232
+ "additionalProperties": false
233
+ }
234
+ }
235
+ },
236
+ "required": ["name", "files"],
237
+ "additionalProperties": false
238
+ }
239
+ }
240
+ }
241
+ }
package/FLOW.meta.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "agent-method",
3
+ "supports": [],
4
+ "description": "Prepare instructions and guidance, request one text response through an HTTP slot, and check the result.",
5
+ "uses": {
6
+ "http": { "contract": "./contracts/http-request/contract.json" }
7
+ }
8
+ }
package/FLOW.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { runAgentFlow } from './dist/flow.js'
2
+
3
+ await runAgentFlow()