tally-sdk 0.1.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.
@@ -0,0 +1,111 @@
1
+ ---
2
+ name: openspec-propose
3
+ description: Propose a new change with all artifacts generated in one step. Use when the user wants to quickly describe what they want to build and get a complete proposal with design, specs, and tasks ready for implementation.
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
+ Propose a new change - create the change and generate all artifacts in one step.
13
+
14
+ I'll create a change with artifacts:
15
+ - proposal.md (what & why)
16
+ - design.md (how)
17
+ - tasks.md (implementation steps)
18
+
19
+ When ready to implement, run /opsx-apply
20
+
21
+ ---
22
+
23
+ **Input**: The user's request should include a change name (kebab-case) OR a description of what they want to build.
24
+
25
+ **Steps**
26
+
27
+ 1. **If no clear input provided, ask what they want to build**
28
+
29
+ Use the **AskUserQuestion tool** (open-ended, no preset options) to ask:
30
+ > "What change do you want to work on? Describe what you want to build or fix."
31
+
32
+ From their description, derive a kebab-case name (e.g., "add user authentication" → `add-user-auth`).
33
+
34
+ **IMPORTANT**: Do NOT proceed without understanding what the user wants to build.
35
+
36
+ 2. **Create the change directory**
37
+ ```bash
38
+ openspec new change "<name>"
39
+ ```
40
+ This creates a scaffolded change in the planning home resolved by the CLI with `.openspec.yaml`.
41
+
42
+ 3. **Get the artifact build order**
43
+ ```bash
44
+ openspec status --change "<name>" --json
45
+ ```
46
+ Parse the JSON to get:
47
+ - `applyRequires`: array of artifact IDs needed before implementation (e.g., `["tasks"]`)
48
+ - `artifacts`: list of all artifacts with their status and dependencies
49
+ - `planningHome`, `changeRoot`, `artifactPaths`, and `actionContext`: path and scope context. Use these instead of assuming repo-local paths.
50
+
51
+ 4. **Create artifacts in sequence until apply-ready**
52
+
53
+ Use the **TodoWrite tool** to track progress through the artifacts.
54
+
55
+ Loop through artifacts in dependency order (artifacts with no pending dependencies first):
56
+
57
+ a. **For each artifact that is `ready` (dependencies satisfied)**:
58
+ - Get instructions:
59
+ ```bash
60
+ openspec instructions <artifact-id> --change "<name>" --json
61
+ ```
62
+ - The instructions JSON includes:
63
+ - `context`: Project background (constraints for you - do NOT include in output)
64
+ - `rules`: Artifact-specific rules (constraints for you - do NOT include in output)
65
+ - `template`: The structure to use for your output file
66
+ - `instruction`: Schema-specific guidance for this artifact type
67
+ - `resolvedOutputPath`: Resolved path or pattern to write the artifact
68
+ - `dependencies`: Completed artifacts to read for context
69
+ - Read any completed dependency files for context
70
+ - Create the artifact file using `template` as the structure and write it to `resolvedOutputPath`
71
+ - Apply `context` and `rules` as constraints - but do NOT copy them into the file
72
+ - Show brief progress: "Created <artifact-id>"
73
+
74
+ b. **Continue until all `applyRequires` artifacts are complete**
75
+ - After creating each artifact, re-run `openspec status --change "<name>" --json`
76
+ - Check if every artifact ID in `applyRequires` has `status: "done"` in the artifacts array
77
+ - Stop when all `applyRequires` artifacts are done
78
+
79
+ c. **If an artifact requires user input** (unclear context):
80
+ - Use **AskUserQuestion tool** to clarify
81
+ - Then continue with creation
82
+
83
+ 5. **Show final status**
84
+ ```bash
85
+ openspec status --change "<name>"
86
+ ```
87
+
88
+ **Output**
89
+
90
+ After completing all artifacts, summarize:
91
+ - Change name and location
92
+ - List of artifacts created with brief descriptions
93
+ - What's ready: "All artifacts created! Ready for implementation."
94
+ - Prompt: "Run `/opsx-apply` or ask me to implement to start working on the tasks."
95
+
96
+ **Artifact Creation Guidelines**
97
+
98
+ - Follow the `instruction` field from `openspec instructions` for each artifact type
99
+ - The schema defines what each artifact should contain - follow it
100
+ - Read dependency artifacts for context before creating new ones
101
+ - Use `template` as the structure for your output file - fill in its sections
102
+ - **IMPORTANT**: `context` and `rules` are constraints for YOU, not content for the file
103
+ - Do NOT copy `<context>`, `<rules>`, `<project_context>` blocks into the artifact
104
+ - These guide what you write, but should never appear in the output
105
+
106
+ **Guardrails**
107
+ - Create ALL artifacts needed for implementation (as defined by schema's `apply.requires`)
108
+ - Always read dependency artifacts before creating a new one
109
+ - If context is critically unclear, ask the user - but prefer making reasonable decisions to keep momentum
110
+ - If a change with that name already exists, ask if user wants to continue it or create a new one
111
+ - Verify each artifact file exists after writing before proceeding to next
@@ -0,0 +1,147 @@
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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tally 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 all
13
+ 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 THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # tally-sdk
2
+
3
+ Accounting, tax, and compliance layer for the agent economy.
4
+
5
+ Tally is an open-source SDK middleware that captures x402 payment metadata at the HTTP layer, persists it to a local SQLite store, and exports structured records to QuickBooks, Xero, and ERP systems.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install tally-sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { createTally } from "tally-sdk";
17
+
18
+ const tally = createTally({ facilitator: "dexter" });
19
+
20
+ // Option 1: Use the wrapped fetch directly
21
+ const response = await tally.fetch("https://api.example.com/paid-endpoint");
22
+
23
+ // Option 2: Monkey-patch global fetch
24
+ tally.wrap();
25
+ const response = await fetch("https://api.example.com/paid-endpoint");
26
+
27
+ // Restore original fetch
28
+ tally.unwrap();
29
+
30
+ // Query stored payments
31
+ const payments = await tally.store.list({ facilitator: "dexter" });
32
+
33
+ // Clean up
34
+ await tally.close();
35
+ ```
36
+
37
+ ## API
38
+
39
+ ### `createTally(config: TallyConfig): TallyClient`
40
+
41
+ Creates a Tally client that observes x402 payment responses and persists metadata.
42
+
43
+ ```typescript
44
+ interface TallyConfig {
45
+ facilitator: string; // e.g., "dexter", "coinbase-cdp"
46
+ store?: Store; // defaults to SQLite at ./tally.db
47
+ }
48
+
49
+ interface TallyClient {
50
+ fetch(input, init): Promise<Response>; // wrapped fetch
51
+ wrap(): void; // monkey-patches globalThis.fetch
52
+ unwrap(): void; // restores original globalThis.fetch
53
+ store: Store; // direct access to the store
54
+ close(): Promise<void>;
55
+ }
56
+ ```
57
+
58
+ ### `Store` Interface
59
+
60
+ ```typescript
61
+ interface Store {
62
+ insert(payload: PaymentPayload): Promise<void>;
63
+ list(opts?: { facilitator?: string; limit?: number; offset?: number }): Promise<PaymentPayload[]>;
64
+ get(id: string): Promise<PaymentPayload | null>;
65
+ close(): Promise<void>;
66
+ }
67
+ ```
68
+
69
+ ### `PaymentPayload`
70
+
71
+ ```typescript
72
+ interface PaymentPayload {
73
+ id: string;
74
+ facilitator: string;
75
+ requestId: string;
76
+ fromAddress: string;
77
+ toAddress: string;
78
+ amount: string; // decimal string
79
+ asset: string; // e.g., "USDC"
80
+ chainId: string; // CAIP-2 format: "eip155:1", "solana:5eykt..."
81
+ txHash: string;
82
+ timestamp: number; // unix ms
83
+ memo?: string;
84
+ metadata?: Record<string, unknown>;
85
+ }
86
+ ```
87
+
88
+ ## How It Works
89
+
90
+ 1. Agent makes an HTTP request via the wrapped `fetch()`
91
+ 2. If the response contains x402 payment headers (`x-facilitator`, `x-request-id`), Tally extracts the payment metadata
92
+ 3. The `PaymentPayload` is persisted to the local SQLite store
93
+ 4. Export commands (coming soon) generate CSV/QuickBooks/Xero files
94
+
95
+ ## Architecture
96
+
97
+ ```
98
+ Agent Code → wrapped fetch() → x402 payment → PaymentPayload → SQLite Store
99
+ ```
100
+
101
+ Tally is a transparent observer — it never modifies requests or responses. If extraction fails, the agent request proceeds normally.
102
+
103
+ ## License
104
+
105
+ MIT
@@ -0,0 +1,122 @@
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