tally-sdk 0.1.0 → 0.2.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 (45) hide show
  1. package/dist/src/hook.d.ts +6 -0
  2. package/dist/src/hook.d.ts.map +1 -0
  3. package/dist/src/hook.js +37 -0
  4. package/dist/src/hook.js.map +1 -0
  5. package/dist/src/index.d.ts +6 -0
  6. package/dist/src/index.d.ts.map +1 -0
  7. package/dist/src/index.js +22 -0
  8. package/dist/src/index.js.map +1 -0
  9. package/dist/src/middleware/core.d.ts +15 -0
  10. package/dist/src/middleware/core.d.ts.map +1 -0
  11. package/dist/src/middleware/core.js +20 -0
  12. package/dist/src/middleware/core.js.map +1 -0
  13. package/dist/src/middleware/express.d.ts +4 -0
  14. package/dist/src/middleware/express.d.ts.map +1 -0
  15. package/dist/src/middleware/express.js +26 -0
  16. package/dist/src/middleware/express.js.map +1 -0
  17. package/dist/src/store.d.ts +14 -0
  18. package/dist/src/store.d.ts.map +1 -0
  19. package/dist/src/store.js +84 -0
  20. package/dist/src/store.js.map +1 -0
  21. package/dist/src/types.d.ts +36 -0
  22. package/dist/src/types.d.ts.map +1 -0
  23. package/dist/src/types.js +2 -0
  24. package/dist/src/types.js.map +1 -0
  25. package/package.json +11 -5
  26. package/src/index.ts +2 -0
  27. package/src/middleware/core.ts +38 -0
  28. package/src/middleware/express.ts +32 -0
  29. package/.opencode/commands/opsx-apply.md +0 -152
  30. package/.opencode/commands/opsx-archive.md +0 -157
  31. package/.opencode/commands/opsx-explore.md +0 -169
  32. package/.opencode/commands/opsx-propose.md +0 -104
  33. package/.opencode/commands/opsx-sync.md +0 -140
  34. package/.opencode/skills/openspec-apply-change/SKILL.md +0 -159
  35. package/.opencode/skills/openspec-archive-change/SKILL.md +0 -117
  36. package/.opencode/skills/openspec-explore/SKILL.md +0 -287
  37. package/.opencode/skills/openspec-propose/SKILL.md +0 -111
  38. package/.opencode/skills/openspec-sync-specs/SKILL.md +0 -147
  39. package/docs/design-hook-store.md +0 -122
  40. package/docs/plan-hook-store.md +0 -752
  41. package/test/hook.test.ts +0 -87
  42. package/test/index.test.ts +0 -36
  43. package/test/integration.test.ts +0 -44
  44. package/test/store.test.ts +0 -88
  45. package/test/types.test.ts +0 -30
@@ -1,147 +0,0 @@
1
- ---
2
- name: openspec-sync-specs
3
- description: Sync delta specs from a change to main specs. Use when the user wants to update main specs with changes from a delta spec, without archiving the change.
4
- license: MIT
5
- compatibility: Requires openspec CLI.
6
- metadata:
7
- author: openspec
8
- version: "1.0"
9
- generatedBy: "1.4.1"
10
- ---
11
-
12
- Sync delta specs from a change to main specs.
13
-
14
- This is an **agent-driven** operation - you will read delta specs and directly edit main specs to apply the changes. This allows intelligent merging (e.g., adding a scenario without copying the entire requirement).
15
-
16
- **Input**: Optionally specify a change name. If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes.
17
-
18
- **Steps**
19
-
20
- 1. **If no change name provided, prompt for selection**
21
-
22
- Run `openspec list --json` to get available changes. Use the **AskUserQuestion tool** to let the user select.
23
-
24
- Show changes that have delta specs (under `specs/` directory).
25
-
26
- **IMPORTANT**: Do NOT guess or auto-select a change. Always let the user choose.
27
-
28
- 2. **Resolve change context**
29
-
30
- Run:
31
- ```bash
32
- openspec status --change "<name>" --json
33
- ```
34
-
35
- If status reports `actionContext.mode: "workspace-planning"`, explain that workspace spec sync is not supported in this slice and STOP. Do not fall back to repo-local paths or edit linked repos.
36
-
37
- 3. **Find delta specs**
38
-
39
- Use `artifactPaths.specs.existingOutputPaths` from the status JSON as the list of delta spec files.
40
-
41
- Each delta spec file contains sections like:
42
- - `## ADDED Requirements` - New requirements to add
43
- - `## MODIFIED Requirements` - Changes to existing requirements
44
- - `## REMOVED Requirements` - Requirements to remove
45
- - `## RENAMED Requirements` - Requirements to rename (FROM:/TO: format)
46
-
47
- If no delta specs found, inform user and stop.
48
-
49
- 4. **For each delta spec, apply changes to main specs**
50
-
51
- For each repo-local capability delta spec path returned by the CLI:
52
-
53
- a. **Read the delta spec** to understand the intended changes
54
-
55
- b. **Read the main spec** at `openspec/specs/<capability>/spec.md` (may not exist yet)
56
-
57
- c. **Apply changes intelligently**:
58
-
59
- **ADDED Requirements:**
60
- - If requirement doesn't exist in main spec → add it
61
- - If requirement already exists → update it to match (treat as implicit MODIFIED)
62
-
63
- **MODIFIED Requirements:**
64
- - Find the requirement in main spec
65
- - Apply the changes - this can be:
66
- - Adding new scenarios (don't need to copy existing ones)
67
- - Modifying existing scenarios
68
- - Changing the requirement description
69
- - Preserve scenarios/content not mentioned in the delta
70
-
71
- **REMOVED Requirements:**
72
- - Remove the entire requirement block from main spec
73
-
74
- **RENAMED Requirements:**
75
- - Find the FROM requirement, rename to TO
76
-
77
- d. **Create new main spec** if capability doesn't exist yet:
78
- - Create `openspec/specs/<capability>/spec.md`
79
- - Add Purpose section (can be brief, mark as TBD)
80
- - Add Requirements section with the ADDED requirements
81
-
82
- 5. **Show summary**
83
-
84
- After applying all changes, summarize:
85
- - Which capabilities were updated
86
- - What changes were made (requirements added/modified/removed/renamed)
87
-
88
- **Delta Spec Format Reference**
89
-
90
- ```markdown
91
- ## ADDED Requirements
92
-
93
- ### Requirement: New Feature
94
- The system SHALL do something new.
95
-
96
- #### Scenario: Basic case
97
- - **WHEN** user does X
98
- - **THEN** system does Y
99
-
100
- ## MODIFIED Requirements
101
-
102
- ### Requirement: Existing Feature
103
- #### Scenario: New scenario to add
104
- - **WHEN** user does A
105
- - **THEN** system does B
106
-
107
- ## REMOVED Requirements
108
-
109
- ### Requirement: Deprecated Feature
110
-
111
- ## RENAMED Requirements
112
-
113
- - FROM: `### Requirement: Old Name`
114
- - TO: `### Requirement: New Name`
115
- ```
116
-
117
- **Key Principle: Intelligent Merging**
118
-
119
- Unlike programmatic merging, you can apply **partial updates**:
120
- - To add a scenario, just include that scenario under MODIFIED - don't copy existing scenarios
121
- - The delta represents *intent*, not a wholesale replacement
122
- - Use your judgment to merge changes sensibly
123
-
124
- **Output On Success**
125
-
126
- ```
127
- ## Specs Synced: <change-name>
128
-
129
- Updated main specs:
130
-
131
- **<capability-1>**:
132
- - Added requirement: "New Feature"
133
- - Modified requirement: "Existing Feature" (added 1 scenario)
134
-
135
- **<capability-2>**:
136
- - Created new spec file
137
- - Added requirement: "Another Feature"
138
-
139
- Main specs are now updated. The change remains active - archive when implementation is complete.
140
- ```
141
-
142
- **Guardrails**
143
- - Read both delta and main specs before making changes
144
- - Preserve existing content not mentioned in delta
145
- - If something is unclear, ask for clarification
146
- - Show what you're changing as you go
147
- - The operation should be idempotent - running twice should give same result
@@ -1,122 +0,0 @@
1
- # Tally: x402 Hook + SQLite Store — Design
2
-
3
- ## Package Structure
4
-
5
- ```
6
- tally/
7
- ├── package.json # tally-sdk
8
- ├── tsconfig.json # strict TS, Node 20
9
- ├── src/
10
- │ ├── index.ts # createTally(), TallyClient — public API
11
- │ ├── types.ts # PaymentPayload, Store, TallyConfig
12
- │ ├── hook.ts # x402 V2 fetch wrapper
13
- │ ├── store.ts # SQLite store (implements Store)
14
- │ └── cli.ts # tally export entry (future)
15
- └── test/
16
- ├── hook.test.ts
17
- └── store.test.ts
18
- ```
19
-
20
- ## Core Data Model
21
-
22
- ### PaymentPayload
23
-
24
- The central type that every subsystem produces, consumes, or persists.
25
-
26
- - `id: string` — uuid
27
- - `facilitator: string` — e.g. "dexter", "coinbase-cdp"
28
- - `requestId: string` — x402 request identifier
29
- - `fromAddress: string` — sender wallet
30
- - `toAddress: string` — receiver wallet
31
- - `amount: string` — decimal string (avoids float precision issues)
32
- - `asset: string` — e.g. "USDC"
33
- - `chainId: string` — CAIP-2 format: "eip155:1", "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
34
- - `txHash: string` — on-chain transaction hash
35
- - `timestamp: number` — unix ms
36
- - `memo?: string` — Solana extra.memo for reconciliation
37
- - `metadata?: Record<string, unknown>` — facilitator-specific extras
38
-
39
- ### Store Interface
40
-
41
- ```typescript
42
- interface Store {
43
- insert(payload: PaymentPayload): Promise<void>
44
- list(opts?: { facilitator?: string; limit?: number; offset?: number }): Promise<PaymentPayload[]>
45
- get(id: string): Promise<PaymentPayload | null>
46
- close(): Promise<void>
47
- }
48
- ```
49
-
50
- ## Public API
51
-
52
- ```typescript
53
- // Entry point — creates a Tally client
54
- function createTally(config: TallyConfig): TallyClient
55
-
56
- interface TallyConfig {
57
- facilitator: string
58
- store?: Store // defaults to SQLite store at ./tally.db
59
- }
60
-
61
- interface TallyClient {
62
- fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>
63
- wrap(): void // monkey-patches globalThis.fetch
64
- store: Store // exposed for direct queries
65
- close(): Promise<void>
66
- }
67
- ```
68
-
69
- ## x402 Hook
70
-
71
- ### Wrapping strategy
72
-
73
- Two approaches, both exported:
74
-
75
- 1. **`wrapFetch()`** — monkey-patches `globalThis.fetch`. Zero agent code changes.
76
- 2. **`createFetch()`** — returns a wrapped fetch function. Explicit, composable.
77
-
78
- Lifecycle: agent calls fetch → hook adds x402 headers → response returns → hook extracts PaymentPayload from response body + headers → calls `store.insert()` → returns original response.
79
-
80
- ## SQLite Store
81
-
82
- ### Schema
83
-
84
- ```sql
85
- CREATE TABLE IF NOT EXISTS payments (
86
- id TEXT PRIMARY KEY,
87
- facilitator TEXT NOT NULL,
88
- request_id TEXT NOT NULL,
89
- from_addr TEXT NOT NULL,
90
- to_addr TEXT NOT NULL,
91
- amount TEXT NOT NULL,
92
- asset TEXT NOT NULL DEFAULT 'USDC',
93
- chain_id TEXT NOT NULL,
94
- tx_hash TEXT NOT NULL,
95
- memo TEXT,
96
- metadata TEXT,
97
- created_at INTEGER NOT NULL
98
- );
99
-
100
- CREATE INDEX idx_payments_facilitator ON payments(facilitator);
101
- CREATE INDEX idx_payments_created_at ON payments(created_at);
102
- ```
103
-
104
- `metadata` is JSON-stringified. `better-sqlite3` for synchronous, zero-config operation.
105
-
106
- ### Methods
107
-
108
- - `insert(payload)` — INSERT OR IGNORE on id collision
109
- - `list({ facilitator, limit, offset })` — filtered, paginated query
110
- - `get(id)` — single row lookup
111
- - `close()` — close database connection
112
-
113
- ## Tests
114
-
115
- - `test/hook.test.ts` — mock `globalThis.fetch`, verify payload extraction and store insertion
116
- - `test/store.test.ts` — `:memory:` SQLite, test insert/list/get
117
-
118
- ## Package Config
119
-
120
- - `package.json`: `name: "tally-sdk"`, `type: "module"`, `exports` map
121
- - `tsconfig.json`: `strict: true`, `target: "ES2022"`, `module: "NodeNext"`
122
- - No bundler for V1 — ship TypeScript source