@treeseed/sdk 0.1.1 → 0.3.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.
- package/README.md +97 -494
- package/dist/{src/cli-tools.d.ts → cli-tools.d.ts} +1 -1
- package/dist/cli-tools.js +5 -3
- package/dist/{src/content-store.d.ts → content-store.d.ts} +3 -2
- package/dist/content-store.js +52 -20
- package/dist/{src/d1-store.d.ts → d1-store.d.ts} +62 -1
- package/dist/d1-store.js +625 -65
- package/dist/field-aliases.d.ts +11 -0
- package/dist/field-aliases.js +41 -0
- package/dist/graph/build.d.ts +19 -0
- package/dist/graph/build.js +949 -0
- package/dist/graph/dsl.d.ts +2 -0
- package/dist/graph/dsl.js +243 -0
- package/dist/graph/query.d.ts +47 -0
- package/dist/graph/query.js +447 -0
- package/dist/graph/ranking.d.ts +3 -0
- package/dist/graph/ranking.js +483 -0
- package/dist/graph/schema.d.ts +142 -0
- package/dist/graph/schema.js +133 -0
- package/dist/graph.d.ts +52 -0
- package/dist/graph.js +133 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +90 -2
- package/dist/model-registry.d.ts +8 -0
- package/dist/model-registry.js +351 -25
- package/dist/operations/providers/default.d.ts +10 -0
- package/dist/operations/providers/default.js +514 -0
- package/dist/operations/runtime.d.ts +7 -0
- package/dist/operations/runtime.js +60 -0
- package/dist/operations/services/config-runtime.d.ts +269 -0
- package/dist/operations/services/config-runtime.js +1397 -0
- package/dist/operations/services/d1-migration.d.ts +6 -0
- package/dist/operations/services/d1-migration.js +89 -0
- package/dist/operations/services/deploy.d.ts +371 -0
- package/dist/operations/services/deploy.js +981 -0
- package/dist/operations/services/git-workflow.d.ts +49 -0
- package/dist/operations/services/git-workflow.js +218 -0
- package/dist/operations/services/github-automation.d.ts +156 -0
- package/dist/operations/services/github-automation.js +256 -0
- package/dist/operations/services/local-dev.d.ts +9 -0
- package/dist/operations/services/local-dev.js +106 -0
- package/dist/operations/services/mailpit-runtime.d.ts +4 -0
- package/dist/operations/services/mailpit-runtime.js +59 -0
- package/dist/operations/services/railway-deploy.d.ts +53 -0
- package/dist/operations/services/railway-deploy.js +123 -0
- package/dist/operations/services/runtime-paths.d.ts +19 -0
- package/dist/operations/services/runtime-paths.js +54 -0
- package/dist/operations/services/runtime-tools.d.ts +117 -0
- package/dist/operations/services/runtime-tools.js +358 -0
- package/dist/operations/services/save-deploy-preflight.d.ts +34 -0
- package/dist/operations/services/save-deploy-preflight.js +76 -0
- package/dist/operations/services/template-registry.d.ts +88 -0
- package/dist/operations/services/template-registry.js +407 -0
- package/dist/operations/services/watch-dev.d.ts +21 -0
- package/dist/operations/services/watch-dev.js +284 -0
- package/dist/operations/services/workspace-preflight.d.ts +40 -0
- package/dist/operations/services/workspace-preflight.js +165 -0
- package/dist/operations/services/workspace-save.d.ts +42 -0
- package/dist/operations/services/workspace-save.js +235 -0
- package/dist/operations/services/workspace-tools.d.ts +16 -0
- package/dist/operations/services/workspace-tools.js +270 -0
- package/dist/operations-registry.d.ts +5 -0
- package/dist/operations-registry.js +68 -0
- package/dist/operations-types.d.ts +71 -0
- package/dist/operations-types.js +17 -0
- package/dist/operations.d.ts +6 -0
- package/dist/operations.js +16 -0
- package/dist/platform/books-data.d.ts +1 -0
- package/dist/platform/books-data.js +1 -0
- package/dist/platform/contracts.d.ts +158 -0
- package/dist/platform/contracts.js +0 -0
- package/dist/platform/deploy/config.d.ts +4 -0
- package/dist/platform/deploy/config.js +222 -0
- package/dist/platform/deploy-config.d.ts +1 -0
- package/dist/platform/deploy-config.js +1 -0
- package/dist/platform/env.yaml +394 -0
- package/dist/platform/environment.d.ts +130 -0
- package/dist/platform/environment.js +331 -0
- package/dist/platform/plugin.d.ts +2 -0
- package/dist/platform/plugin.js +4 -0
- package/dist/platform/plugins/constants.d.ts +22 -0
- package/dist/platform/plugins/constants.js +29 -0
- package/dist/platform/plugins/plugin.d.ts +51 -0
- package/dist/platform/plugins/plugin.js +6 -0
- package/dist/platform/plugins/runtime.d.ts +35 -0
- package/dist/platform/plugins/runtime.js +142 -0
- package/dist/platform/plugins.d.ts +5 -0
- package/dist/platform/plugins.js +16 -0
- package/dist/platform/site-config-schema.js +1 -0
- package/dist/platform/tenant/config.d.ts +9 -0
- package/dist/platform/tenant/config.js +154 -0
- package/dist/platform/tenant/runtime-config.d.ts +4 -0
- package/dist/platform/tenant/runtime-config.js +20 -0
- package/dist/platform/tenant-config.d.ts +1 -0
- package/dist/platform/tenant-config.js +1 -0
- package/dist/platform/utils/books-data.d.ts +29 -0
- package/dist/platform/utils/books-data.js +82 -0
- package/dist/platform/utils/site-config-schema.js +321 -0
- package/dist/remote.d.ts +175 -0
- package/dist/remote.js +202 -0
- package/dist/runtime.js +50 -3
- package/dist/scripts/aggregate-book.js +121 -0
- package/dist/scripts/build-dist.js +57 -13
- package/dist/scripts/build-tenant-worker.js +36 -0
- package/dist/scripts/cleanup-markdown.js +373 -0
- package/dist/scripts/cli-test-fixtures.js +48 -0
- package/dist/scripts/config-treeseed.js +95 -0
- package/dist/scripts/ensure-mailpit.js +29 -0
- package/dist/scripts/local-dev.js +129 -0
- package/dist/scripts/logs-mailpit.js +2 -0
- package/dist/scripts/patch-starlight-content-path.js +172 -0
- package/dist/scripts/release-verify.js +34 -5
- package/dist/scripts/run-fixture-astro-command.js +18 -0
- package/dist/scripts/scaffold-site.js +65 -0
- package/dist/scripts/stop-mailpit.js +5 -0
- package/dist/scripts/sync-dev-vars.js +6 -0
- package/dist/scripts/sync-template.js +20 -0
- package/dist/scripts/template-catalog.test.js +100 -0
- package/dist/scripts/template-command.js +31 -0
- package/dist/scripts/tenant-astro-command.js +3 -0
- package/dist/scripts/tenant-build.js +16 -0
- package/dist/scripts/tenant-check.js +7 -0
- package/dist/scripts/tenant-d1-migrate-local.js +11 -0
- package/dist/scripts/tenant-deploy.js +180 -0
- package/dist/scripts/tenant-destroy.js +104 -0
- package/dist/scripts/tenant-dev.js +171 -0
- package/dist/scripts/tenant-lint.js +4 -0
- package/dist/scripts/tenant-test.js +4 -0
- package/dist/scripts/test-cloudflare-local.js +212 -0
- package/dist/scripts/test-scaffold.js +314 -0
- package/dist/scripts/test-smoke.js +71 -13
- package/dist/scripts/treeseed-assert-release-tag-version.js +21 -0
- package/dist/scripts/treeseed-build-dist.js +134 -0
- package/dist/scripts/treeseed-publish-package.js +19 -0
- package/dist/scripts/treeseed-release-verify.js +131 -0
- package/dist/scripts/treeseed-run-ts.js +45 -0
- package/dist/scripts/validate-templates.js +6 -0
- package/dist/scripts/verify-driver.js +29 -0
- package/dist/scripts/workflow-commands.test.js +39 -0
- package/dist/scripts/workspace-close.js +24 -0
- package/dist/scripts/workspace-command-e2e.js +718 -0
- package/dist/scripts/workspace-lint.js +9 -0
- package/dist/scripts/workspace-preflight.js +22 -0
- package/dist/scripts/workspace-publish-changed-packages.js +16 -0
- package/dist/scripts/workspace-release-verify.js +81 -0
- package/dist/scripts/workspace-release.js +42 -0
- package/dist/scripts/workspace-save.js +124 -0
- package/dist/scripts/workspace-start-warning.js +3 -0
- package/dist/scripts/workspace-start.js +71 -0
- package/dist/scripts/workspace-test-unit.js +4 -0
- package/dist/scripts/workspace-test.js +11 -0
- package/dist/sdk-fields.d.ts +11 -0
- package/dist/sdk-fields.js +169 -0
- package/dist/sdk-filters.d.ts +4 -0
- package/dist/sdk-filters.js +12 -15
- package/dist/sdk-types.d.ts +796 -0
- package/dist/sdk-types.js +7 -1
- package/dist/sdk-version.d.ts +2 -0
- package/dist/sdk-version.js +42 -0
- package/dist/sdk.d.ts +215 -0
- package/dist/sdk.js +235 -11
- package/dist/stores/cursor-store.js +9 -3
- package/dist/stores/lease-store.js +8 -2
- package/dist/{src/stores → stores}/message-store.d.ts +1 -1
- package/dist/stores/message-store.js +27 -3
- package/dist/stores/operational-store.d.ts +24 -0
- package/dist/stores/operational-store.js +279 -0
- package/dist/stores/run-store.js +8 -1
- package/dist/stores/subscription-store.js +7 -5
- package/dist/template-catalog.d.ts +13 -0
- package/dist/template-catalog.js +141 -0
- package/dist/treeseed/services/compose.yml +7 -0
- package/dist/treeseed/template-catalog/catalog.fixture.json +55 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/astro.config.d.ts +2 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/astro.config.ts +3 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/package.json +32 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/config.yaml +40 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/empty/.gitkeep +1 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/knowledge/handbook/index.mdx +11 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/pages/welcome.mdx +11 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content.config.d.ts +1 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content.config.ts +3 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/env.yaml +1 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/manifest.yaml +19 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/treeseed.site.yaml +26 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/tsconfig.json +9 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template.config.json +90 -0
- package/dist/verification.d.ts +20 -0
- package/dist/verification.js +98 -0
- package/dist/workflow/operations.d.ts +396 -0
- package/dist/workflow/operations.js +841 -0
- package/dist/workflow-state.d.ts +56 -0
- package/dist/workflow-state.js +195 -0
- package/dist/workflow-support.d.ts +9 -0
- package/dist/workflow-support.js +176 -0
- package/dist/workflow.d.ts +111 -0
- package/dist/workflow.js +97 -0
- package/package.json +97 -5
- package/scripts/verify-driver.mjs +29 -0
- package/dist/scripts/.ts-run-1775616845195-odh4xzphk3l.js +0 -22
- package/dist/scripts/.ts-run-1775616848931-9386s6kwrl.js +0 -126
- package/dist/scripts/assert-release-tag-version.d.ts +0 -1
- package/dist/scripts/build-dist.d.ts +0 -1
- package/dist/scripts/package-tools.d.ts +0 -15
- package/dist/scripts/publish-package.d.ts +0 -1
- package/dist/scripts/release-verify.d.ts +0 -1
- package/dist/scripts/test-smoke.d.ts +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/model-registry.d.ts +0 -4
- package/dist/src/sdk-filters.d.ts +0 -4
- package/dist/src/sdk-types.d.ts +0 -285
- package/dist/src/sdk.d.ts +0 -109
- package/dist/test/test-fixture.d.ts +0 -1
- package/dist/test/utils/envelopes.test.d.ts +0 -1
- package/dist/test/utils/sdk.test.d.ts +0 -1
- package/dist/vitest.config.d.ts +0 -2
- /package/dist/{src/frontmatter.d.ts → frontmatter.d.ts} +0 -0
- /package/dist/{src/git-runtime.d.ts → git-runtime.d.ts} +0 -0
- /package/dist/{src/runtime.d.ts → runtime.d.ts} +0 -0
- /package/dist/{src/stores → stores}/cursor-store.d.ts +0 -0
- /package/dist/{src/stores → stores}/envelopes.d.ts +0 -0
- /package/dist/{src/stores → stores}/helpers.d.ts +0 -0
- /package/dist/{src/stores → stores}/lease-store.d.ts +0 -0
- /package/dist/{src/stores → stores}/run-store.d.ts +0 -0
- /package/dist/{src/stores → stores}/subscription-store.d.ts +0 -0
- /package/dist/{src/types → types}/agents.d.ts +0 -0
- /package/dist/{src/types → types}/cloudflare.d.ts +0 -0
- /package/dist/{src/wrangler-d1.d.ts → wrangler-d1.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,565 +1,168 @@
|
|
|
1
1
|
# `@treeseed/sdk`
|
|
2
2
|
|
|
3
|
-
`@treeseed/sdk` is the
|
|
3
|
+
`@treeseed/sdk` is the main programmatic interface for Treeseed content, control-plane state, and graph-first AI context retrieval.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
For most consumers, the right entrypoint is `AgentSdk`.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- D1-backed access for subscriptions, messages, agent runs, cursors, and content leases
|
|
9
|
-
- stable query and mutation APIs for `get`, `read`, `search`, `follow`, `pick`, `create`, and `update`
|
|
7
|
+
## Which Surface Should I Use?
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
Treeseed exposes three public SDK surfaces, but they are not peers:
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
Install:
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install @treeseed/sdk
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Example:
|
|
11
|
+
| Surface | Role | Use It For |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| `AgentSdk` | Primary | application code, workers, scripts, API handlers, graph-first context retrieval |
|
|
14
|
+
| `ScopedAgentSdk` | Operational | agent-runtime code that must enforce model permissions and inject actor identity |
|
|
15
|
+
| `ContentGraphRuntime` | Advanced | low-level graph-only integrations that want the graph engine without the rest of the SDK |
|
|
25
16
|
|
|
26
|
-
|
|
27
|
-
import { AgentSdk } from '@treeseed/sdk';
|
|
17
|
+
If you are unsure, use `AgentSdk`.
|
|
28
18
|
|
|
29
|
-
|
|
30
|
-
```
|
|
19
|
+
## Major Capability Groups
|
|
31
20
|
|
|
32
|
-
|
|
21
|
+
`AgentSdk` covers five main areas:
|
|
33
22
|
|
|
34
|
-
|
|
23
|
+
- generic model reads and mutations across content-backed and D1-backed models
|
|
24
|
+
- operational runtime state such as messages, runs, cursors, and leases
|
|
25
|
+
- control-plane orchestration for work days, tasks, task events, graph runs, and reports
|
|
26
|
+
- graph-first context retrieval through `parseGraphDsl()`, `resolveSeeds()`, `queryGraph()`, and `buildContextPack()`
|
|
27
|
+
- agent scoping through `scopeForAgent()`
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
- `model`
|
|
38
|
-
- `operation`
|
|
39
|
-
- `payload`
|
|
40
|
-
- optional `meta`
|
|
29
|
+
## Install
|
|
41
30
|
|
|
42
|
-
|
|
31
|
+
```bash
|
|
32
|
+
npm install @treeseed/sdk
|
|
33
|
+
```
|
|
43
34
|
|
|
44
|
-
|
|
45
|
-
2. call `get`, `read`, `search`, `follow`, `pick`, `create`, or `update`
|
|
46
|
-
3. read the typed `payload` from the returned envelope
|
|
35
|
+
Consumer contract:
|
|
47
36
|
|
|
48
|
-
|
|
37
|
+
- Node `>=22`
|
|
38
|
+
- ESM package
|
|
39
|
+
- import from the package root or documented subpath exports
|
|
49
40
|
|
|
50
|
-
|
|
41
|
+
## Quickstart
|
|
51
42
|
|
|
52
43
|
```ts
|
|
53
44
|
import { AgentSdk } from '@treeseed/sdk';
|
|
54
45
|
|
|
55
46
|
const sdk = new AgentSdk({
|
|
56
|
-
|
|
47
|
+
repoRoot: '/absolute/path/to/your-site',
|
|
57
48
|
});
|
|
58
49
|
```
|
|
59
50
|
|
|
60
|
-
Use `createLocal()` when you want a local Wrangler-backed D1 database:
|
|
51
|
+
Use `AgentSdk.createLocal()` when you want a local Wrangler-backed D1 database:
|
|
61
52
|
|
|
62
53
|
```ts
|
|
63
54
|
import { AgentSdk } from '@treeseed/sdk';
|
|
64
55
|
|
|
65
56
|
const sdk = AgentSdk.createLocal({
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
Use `MemoryAgentDatabase` explicitly in tests or scripts when you want a fully in-memory setup:
|
|
73
|
-
|
|
74
|
-
```ts
|
|
75
|
-
import { AgentSdk } from '@treeseed/sdk';
|
|
76
|
-
import { MemoryAgentDatabase } from '@treeseed/sdk/d1-store';
|
|
77
|
-
|
|
78
|
-
const sdk = new AgentSdk({
|
|
79
|
-
repoRoot: '/absolute/path/to/your-site',
|
|
80
|
-
database: new MemoryAgentDatabase(),
|
|
81
|
-
});
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Read A Single Record
|
|
85
|
-
|
|
86
|
-
Use `get()` when you want one record by `id`, `slug`, or `key`.
|
|
87
|
-
|
|
88
|
-
```ts
|
|
89
|
-
const response = await sdk.get({
|
|
90
|
-
model: 'knowledge',
|
|
91
|
-
slug: 'guides/getting-started/1-introduction',
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
if (response.payload) {
|
|
95
|
-
console.log(response.payload.title);
|
|
96
|
-
console.log(response.payload.body);
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Use `read()` when you want the same lookup behavior but want the returned envelope to say `operation: 'read'`.
|
|
101
|
-
|
|
102
|
-
```ts
|
|
103
|
-
const response = await sdk.read({
|
|
104
|
-
model: 'page',
|
|
105
|
-
slug: 'getting-started',
|
|
106
|
-
});
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Search Across A Model
|
|
110
|
-
|
|
111
|
-
Use `search()` to list and filter records from a model.
|
|
112
|
-
|
|
113
|
-
```ts
|
|
114
|
-
const response = await sdk.search({
|
|
115
|
-
model: 'knowledge',
|
|
116
|
-
filters: [
|
|
117
|
-
{ field: 'title', op: 'contains', value: 'TreeSeed' },
|
|
118
|
-
{ field: 'tags', op: 'contains', value: 'onboarding' },
|
|
119
|
-
],
|
|
120
|
-
sort: [{ field: 'updated', direction: 'desc' }],
|
|
121
|
-
limit: 10,
|
|
57
|
+
repoRoot: '/absolute/path/to/your-site',
|
|
58
|
+
databaseName: 'treeseed-local',
|
|
59
|
+
persistTo: '.wrangler/state/v3/d1',
|
|
122
60
|
});
|
|
123
|
-
|
|
124
|
-
console.log(response.meta?.count);
|
|
125
|
-
console.log(response.payload.map((item) => item.slug));
|
|
126
61
|
```
|
|
127
62
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
- listing recent notes
|
|
131
|
-
- finding objectives by status
|
|
132
|
-
- finding people by role or affiliation
|
|
133
|
-
- finding queued D1 messages by type or status
|
|
63
|
+
## Preferred Graph Workflow
|
|
134
64
|
|
|
135
|
-
|
|
65
|
+
The preferred graph API for new integrations is:
|
|
136
66
|
|
|
137
|
-
|
|
67
|
+
1. `parseGraphDsl()`
|
|
68
|
+
2. `queryGraph()`
|
|
69
|
+
3. `buildContextPack()`
|
|
138
70
|
|
|
139
|
-
|
|
140
|
-
const response = await sdk.follow({
|
|
141
|
-
model: 'knowledge',
|
|
142
|
-
since: '2026-04-07T00:00:00.000Z',
|
|
143
|
-
filters: [{ field: 'tags', op: 'contains', value: 'treeseed' }],
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
for (const item of response.payload.items) {
|
|
147
|
-
console.log(item.slug);
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
The payload shape is:
|
|
71
|
+
Example:
|
|
152
72
|
|
|
153
73
|
```ts
|
|
154
|
-
{
|
|
155
|
-
items: [...],
|
|
156
|
-
since: '...'
|
|
157
|
-
}
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### Pick Work Items
|
|
161
|
-
|
|
162
|
-
Use `pick()` when you want the SDK to choose one item from a model for a worker.
|
|
163
|
-
|
|
164
|
-
For content-backed models, `pick()` tries to claim a content lease and returns both the selected item and a `leaseToken` when a claim succeeds.
|
|
74
|
+
import { AgentSdk } from '@treeseed/sdk';
|
|
165
75
|
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
leaseSeconds: 300,
|
|
171
|
-
filters: [{ field: 'status', op: 'eq', value: 'in progress' }],
|
|
172
|
-
});
|
|
76
|
+
const sdk = new AgentSdk();
|
|
77
|
+
const parsed = await sdk.parseGraphDsl(
|
|
78
|
+
'ctx "queue api" for implement in /knowledge via implements,references depth 1 budget 4000 as full',
|
|
79
|
+
);
|
|
173
80
|
|
|
174
|
-
if (
|
|
175
|
-
|
|
176
|
-
console.log(response.payload.leaseToken);
|
|
81
|
+
if (!parsed.ok || !parsed.query) {
|
|
82
|
+
throw new Error(parsed.errors.join('; '));
|
|
177
83
|
}
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
For `message`, `pick()` routes to queue claiming behavior in the D1 layer.
|
|
181
|
-
|
|
182
|
-
### Create Content Or D1 Records
|
|
183
|
-
|
|
184
|
-
Use `create()` for models that support creation.
|
|
185
|
-
|
|
186
|
-
For content-backed models, pass frontmatter-like fields in `data`. The SDK writes the document and returns the created item plus git metadata.
|
|
187
|
-
|
|
188
|
-
```ts
|
|
189
|
-
const response = await sdk.create({
|
|
190
|
-
model: 'note',
|
|
191
|
-
actor: 'app-server',
|
|
192
|
-
data: {
|
|
193
|
-
slug: 'operating-a-small-treeseed',
|
|
194
|
-
title: 'Operating a Small TreeSeed',
|
|
195
|
-
status: 'live',
|
|
196
|
-
author: 'TreeSeed Team',
|
|
197
|
-
tags: ['operations', 'treeseed'],
|
|
198
|
-
body: 'Keep the content model simple and the workflows visible.',
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
console.log(response.payload.item.slug);
|
|
203
|
-
console.log(response.payload.git);
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
For D1-backed models, `create()` delegates to the relevant store and returns the created entity.
|
|
207
|
-
|
|
208
|
-
### Update Existing Records
|
|
209
|
-
|
|
210
|
-
Use `update()` when you want to modify an existing content-backed or D1-backed record.
|
|
211
|
-
|
|
212
|
-
```ts
|
|
213
|
-
const response = await sdk.update({
|
|
214
|
-
model: 'objective',
|
|
215
|
-
slug: 'make-the-sample-site-easy-to-operate',
|
|
216
|
-
actor: 'app-server',
|
|
217
|
-
data: {
|
|
218
|
-
status: 'live',
|
|
219
|
-
body: 'The objective is now complete and documented.',
|
|
220
|
-
},
|
|
221
|
-
});
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
For content-backed models, `update()` returns the updated item and git metadata. For D1-backed models, it returns the updated row or `null` when no matching record exists.
|
|
225
|
-
|
|
226
|
-
### Work With Messages
|
|
227
|
-
|
|
228
|
-
The SDK exposes dedicated queue helpers in addition to generic model access.
|
|
229
|
-
|
|
230
|
-
Create a message:
|
|
231
|
-
|
|
232
|
-
```ts
|
|
233
|
-
const created = await sdk.createMessage({
|
|
234
|
-
type: 'guidance_ready',
|
|
235
|
-
actor: 'guide-agent',
|
|
236
|
-
payload: {
|
|
237
|
-
slug: 'guides/getting-started/1-introduction',
|
|
238
|
-
},
|
|
239
|
-
relatedModel: 'knowledge',
|
|
240
|
-
relatedId: 'guides/getting-started/1-introduction',
|
|
241
|
-
priority: 5,
|
|
242
|
-
maxAttempts: 3,
|
|
243
|
-
});
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
Claim a message:
|
|
247
|
-
|
|
248
|
-
```ts
|
|
249
|
-
const claimed = await sdk.claimMessage({
|
|
250
|
-
workerId: 'worker-1',
|
|
251
|
-
messageTypes: ['guidance_ready'],
|
|
252
|
-
leaseSeconds: 300,
|
|
253
|
-
});
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
Acknowledge a message:
|
|
257
|
-
|
|
258
|
-
```ts
|
|
259
|
-
await sdk.ackMessage({
|
|
260
|
-
id: 1,
|
|
261
|
-
status: 'completed',
|
|
262
|
-
});
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
### Record Agent Runs, Cursors, And Leases
|
|
266
|
-
|
|
267
|
-
Record a run:
|
|
268
|
-
|
|
269
|
-
```ts
|
|
270
|
-
await sdk.recordRun({
|
|
271
|
-
run: {
|
|
272
|
-
runId: 'run-123',
|
|
273
|
-
agentSlug: 'guide-agent',
|
|
274
|
-
status: 'completed',
|
|
275
|
-
triggerSource: 'message',
|
|
276
|
-
startedAt: '2026-04-07T00:00:00.000Z',
|
|
277
|
-
finishedAt: '2026-04-07T00:05:00.000Z',
|
|
278
|
-
},
|
|
279
|
-
});
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
Read and update a cursor:
|
|
283
|
-
|
|
284
|
-
```ts
|
|
285
|
-
const cursor = await sdk.getCursor({
|
|
286
|
-
agentSlug: 'guide-agent',
|
|
287
|
-
cursorKey: 'knowledge-sync',
|
|
288
|
-
});
|
|
289
84
|
|
|
290
|
-
await sdk.
|
|
291
|
-
|
|
292
|
-
cursorKey: 'knowledge-sync',
|
|
293
|
-
cursorValue: '2026-04-07T00:00:00.000Z',
|
|
294
|
-
});
|
|
85
|
+
const graph = await sdk.queryGraph(parsed.query);
|
|
86
|
+
const pack = await sdk.buildContextPack(parsed.query);
|
|
295
87
|
```
|
|
296
88
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
```ts
|
|
300
|
-
await sdk.releaseLease({
|
|
301
|
-
model: 'objective',
|
|
302
|
-
itemKey: 'make-the-sample-site-easy-to-operate',
|
|
303
|
-
leaseToken: 'lease-token',
|
|
304
|
-
});
|
|
89
|
+
The public `ctx` syntax is:
|
|
305
90
|
|
|
306
|
-
|
|
91
|
+
```text
|
|
92
|
+
ctx <target>
|
|
93
|
+
[for <stage>]
|
|
94
|
+
[in <scope>]
|
|
95
|
+
[via <relation[,relation...]>]
|
|
96
|
+
[depth <0-3>]
|
|
97
|
+
[where <filter-expression>]
|
|
98
|
+
[limit <n>]
|
|
99
|
+
[budget <tokens>]
|
|
100
|
+
[as <list|brief|full|map>]
|
|
307
101
|
```
|
|
308
102
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
These three concepts are the operational state layer for TreeSeed's agent runtime. They are not general content models like `page` or `knowledge`. Instead, they let TreeSeed coordinate ongoing agent work safely and make that work inspectable after the fact.
|
|
312
|
-
|
|
313
|
-
#### Agent Runs
|
|
314
|
-
|
|
315
|
-
An `agent_run` is the execution trace for one agent invocation.
|
|
316
|
-
|
|
317
|
-
TreeSeed records a run when the agent kernel starts an agent, and records it again when the run finishes or fails. In practice, that means a run captures:
|
|
318
|
-
|
|
319
|
-
- which agent ran
|
|
320
|
-
- what triggered it
|
|
321
|
-
- the current status such as `running`, `completed`, `failed`, or `waiting`
|
|
322
|
-
- which message or item was selected
|
|
323
|
-
- summary or error output
|
|
324
|
-
- optional branch, commit, PR, and changed-path metadata
|
|
325
|
-
- start and finish timestamps
|
|
326
|
-
|
|
327
|
-
In the TreeSeed agent runtime, [`agent/src/agents/kernel/agent-kernel.ts`](/home/adrian/Projects/treeseed/agent/src/agents/kernel/agent-kernel.ts) calls `sdk.recordRun()` at the beginning of execution and again after the handler returns. That gives TreeSeed a durable per-run audit trail for:
|
|
328
|
-
|
|
329
|
-
- debugging agent behavior
|
|
330
|
-
- understanding why an agent did or did not run
|
|
331
|
-
- inspecting outputs from planner, reviewer, notifier, and similar handlers
|
|
332
|
-
- connecting downstream events back to the run that produced them
|
|
103
|
+
The old `key=value` graph DSL is no longer supported.
|
|
333
104
|
|
|
334
|
-
|
|
105
|
+
## Advanced Graph Methods
|
|
335
106
|
|
|
336
|
-
|
|
107
|
+
The SDK also exposes lower-level graph primitives such as:
|
|
337
108
|
|
|
338
|
-
|
|
109
|
+
- `searchFiles()`
|
|
110
|
+
- `searchSections()`
|
|
111
|
+
- `searchEntities()`
|
|
112
|
+
- `getGraphNode()`
|
|
113
|
+
- `getNeighbors()`
|
|
114
|
+
- `followReferences()`
|
|
115
|
+
- `getBacklinks()`
|
|
116
|
+
- `getRelated()`
|
|
117
|
+
- `getSubgraph()`
|
|
118
|
+
- `refreshGraph()`
|
|
339
119
|
|
|
340
|
-
-
|
|
341
|
-
- `cursorKey`
|
|
342
|
-
- `cursorValue`
|
|
120
|
+
These remain public, but they are considered advanced tools. Prefer the graph-first context workflow above unless you specifically need raw lexical search or raw traversal primitives.
|
|
343
121
|
|
|
344
|
-
|
|
122
|
+
## `ScopedAgentSdk`
|
|
345
123
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
- the agent kernel writes `last_run_at` after a successful run
|
|
349
|
-
- follow triggers read a cursor like `follow:model-a,model-b` to know which timestamp to compare against
|
|
350
|
-
- the sample planner agent writes `last_priority_run_at`
|
|
351
|
-
- the sample notifier agent reads and updates `last_notified_at` so it only announces new activity
|
|
352
|
-
|
|
353
|
-
You can see that usage in:
|
|
354
|
-
|
|
355
|
-
- [`agent/src/agents/kernel/agent-kernel.ts`](/home/adrian/Projects/treeseed/agent/src/agents/kernel/agent-kernel.ts)
|
|
356
|
-
- [`agent/src/agents/kernel/trigger-resolver.ts`](/home/adrian/Projects/treeseed/agent/src/agents/kernel/trigger-resolver.ts)
|
|
357
|
-
- [`core/fixture/src/agents/planner.ts`](/home/adrian/Projects/treeseed/core/fixture/src/agents/planner.ts)
|
|
358
|
-
- [`core/fixture/src/agents/notifier.ts`](/home/adrian/Projects/treeseed/core/fixture/src/agents/notifier.ts)
|
|
359
|
-
|
|
360
|
-
Conceptually, `agent_cursor` is the answer to: "Where should this agent continue from next time?"
|
|
361
|
-
|
|
362
|
-
#### Content Leases
|
|
363
|
-
|
|
364
|
-
A `content_lease` is a short-lived claim on one content item. TreeSeed uses leases to avoid two workers picking and mutating the same item at the same time.
|
|
365
|
-
|
|
366
|
-
When `pick()` runs against a content-backed model, the SDK does not just choose the "best" item. It also tries to claim a lease in the database. If another worker already holds a live lease for that item, the claim fails and the picker moves on.
|
|
367
|
-
|
|
368
|
-
Each lease stores:
|
|
369
|
-
|
|
370
|
-
- the model
|
|
371
|
-
- the item key
|
|
372
|
-
- who claimed it
|
|
373
|
-
- when it was claimed
|
|
374
|
-
- when the lease expires
|
|
375
|
-
- a lease token
|
|
376
|
-
|
|
377
|
-
This is how TreeSeed prevents duplicate work during autonomous or parallel agent execution, especially for content-backed tasks like selecting the next note, question, or objective to act on.
|
|
378
|
-
|
|
379
|
-
In the SDK, the lease flow is wired through:
|
|
380
|
-
|
|
381
|
-
- content selection in [`sdk/src/content-store.ts`](/home/adrian/Projects/treeseed/sdk/src/content-store.ts)
|
|
382
|
-
- D1 lease persistence in [`sdk/src/stores/lease-store.ts`](/home/adrian/Projects/treeseed/sdk/src/stores/lease-store.ts)
|
|
383
|
-
- runtime cleanup through `releaseLease()` and `releaseAllLeases()`
|
|
384
|
-
|
|
385
|
-
The agent kernel exposes that cleanup path as `releaseLeases()` so TreeSeed operators can clear stale claims when needed.
|
|
386
|
-
|
|
387
|
-
Conceptually, `content_lease` is the answer to: "Who currently owns this piece of work, and when does that claim expire?"
|
|
388
|
-
|
|
389
|
-
#### How They Work Together
|
|
390
|
-
|
|
391
|
-
In TreeSeed, these records solve different parts of the same runtime problem:
|
|
392
|
-
|
|
393
|
-
- `agent_run` records what happened
|
|
394
|
-
- `agent_cursor` records where to resume
|
|
395
|
-
- `content_lease` records who currently owns a piece of work
|
|
396
|
-
|
|
397
|
-
Together, they make the agent system:
|
|
398
|
-
|
|
399
|
-
- inspectable, because each run leaves a trace
|
|
400
|
-
- incremental, because agents can continue from saved cursors
|
|
401
|
-
- concurrency-safe, because content picking is guarded by leases
|
|
402
|
-
|
|
403
|
-
That combination is what lets TreeSeed move from one-off scripts toward a manageable long-running agent runtime.
|
|
404
|
-
|
|
405
|
-
### Discover Agent Specs
|
|
406
|
-
|
|
407
|
-
When your application stores agent definitions in content, use `listRawAgentSpecs()` or `listAgentSpecs()`.
|
|
408
|
-
|
|
409
|
-
```ts
|
|
410
|
-
const specs = await sdk.listAgentSpecs({ enabled: true });
|
|
411
|
-
|
|
412
|
-
for (const spec of specs) {
|
|
413
|
-
console.log(spec.slug, spec.handler);
|
|
414
|
-
}
|
|
415
|
-
```
|
|
416
|
-
|
|
417
|
-
Use `listRawAgentSpecs()` when you want the underlying content entries. Use `listAgentSpecs()` when you want normalized runtime specs.
|
|
418
|
-
|
|
419
|
-
### Restrict Access With `ScopedAgentSdk`
|
|
420
|
-
|
|
421
|
-
Use `scopeForAgent()` when you want application code to enforce an agent’s declared permissions before executing SDK operations.
|
|
124
|
+
Use `scopeForAgent()` when code must enforce an agent’s declared permissions:
|
|
422
125
|
|
|
423
126
|
```ts
|
|
424
127
|
const scoped = sdk.scopeForAgent({
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
128
|
+
slug: 'guide-agent',
|
|
129
|
+
permissions: [
|
|
130
|
+
{ model: 'knowledge', operations: ['get', 'read', 'search'] },
|
|
131
|
+
{ model: 'message', operations: ['create'] },
|
|
132
|
+
],
|
|
430
133
|
});
|
|
431
|
-
|
|
432
|
-
await scoped.search({
|
|
433
|
-
model: 'knowledge',
|
|
434
|
-
filters: [{ field: 'tags', op: 'contains', value: 'treeseed' }],
|
|
435
|
-
});
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
`ScopedAgentSdk` automatically injects the agent slug as `actor` for `create()`, `update()`, and `createMessage()`, and throws when the requested operation is not allowed.
|
|
439
|
-
|
|
440
|
-
### Model And Filter Notes
|
|
441
|
-
|
|
442
|
-
The SDK resolves model aliases for you. For example, `docs` maps to `knowledge` and `people` maps to `person`.
|
|
443
|
-
|
|
444
|
-
Common request fields:
|
|
445
|
-
|
|
446
|
-
- `model`: the canonical model or an accepted alias
|
|
447
|
-
- `filters`: array of `{ field, op, value }`
|
|
448
|
-
- `sort`: array of `{ field, direction }`
|
|
449
|
-
- `limit`: max number of returned items
|
|
450
|
-
|
|
451
|
-
Common filter operators include:
|
|
452
|
-
|
|
453
|
-
- `eq`
|
|
454
|
-
- `in`
|
|
455
|
-
- `contains`
|
|
456
|
-
- `prefix`
|
|
457
|
-
- `gt`
|
|
458
|
-
- `gte`
|
|
459
|
-
- `lt`
|
|
460
|
-
- `lte`
|
|
461
|
-
- `updated_since`
|
|
462
|
-
- `related_to`
|
|
463
|
-
|
|
464
|
-
### Envelope Pattern
|
|
465
|
-
|
|
466
|
-
Every top-level SDK call returns a consistent envelope:
|
|
467
|
-
|
|
468
|
-
```ts
|
|
469
|
-
const response = await sdk.search({ model: 'person', limit: 1 });
|
|
470
|
-
|
|
471
|
-
response.ok; // true
|
|
472
|
-
response.model; // 'person'
|
|
473
|
-
response.operation; // 'search'
|
|
474
|
-
response.payload; // typed result
|
|
475
|
-
response.meta; // optional metadata
|
|
476
134
|
```
|
|
477
135
|
|
|
478
|
-
|
|
136
|
+
`ScopedAgentSdk` is intended for manager/worker and agent-runtime code. It is not the default application entrypoint.
|
|
479
137
|
|
|
480
|
-
##
|
|
138
|
+
## `ContentGraphRuntime`
|
|
481
139
|
|
|
482
|
-
|
|
140
|
+
`ContentGraphRuntime` is still exported, but it is an advanced graph runtime:
|
|
483
141
|
|
|
484
|
-
|
|
142
|
+
- it powers the graph subsystem behind `AgentSdk`
|
|
143
|
+
- it is useful when you want only graph behavior
|
|
144
|
+
- it is not the recommended starting point for most applications
|
|
485
145
|
|
|
486
|
-
|
|
487
|
-
- `@treeseed/sdk/content-store`
|
|
488
|
-
- `@treeseed/sdk/d1-store`
|
|
489
|
-
- `@treeseed/sdk/frontmatter`
|
|
490
|
-
- `@treeseed/sdk/git-runtime`
|
|
491
|
-
- `@treeseed/sdk/models`
|
|
492
|
-
- `@treeseed/sdk/sdk-filters`
|
|
493
|
-
- `@treeseed/sdk/cli-tools`
|
|
494
|
-
- `@treeseed/sdk/types`
|
|
495
|
-
- `@treeseed/sdk/types/agents`
|
|
496
|
-
- `@treeseed/sdk/types/cloudflare`
|
|
497
|
-
- `@treeseed/sdk/wrangler-d1`
|
|
498
|
-
- `@treeseed/sdk/stores/*`
|
|
146
|
+
## Reference Docs
|
|
499
147
|
|
|
500
|
-
|
|
148
|
+
- [SDK Interface Reference](/home/adrian/Projects/treeseed/market/src/content/knowledge/sdk/interface-reference.mdx)
|
|
149
|
+
- [Graph API Guide](/home/adrian/Projects/treeseed/market/src/content/knowledge/sdk/graph-api-guide.mdx)
|
|
150
|
+
- [ctx Query Language](/home/adrian/Projects/treeseed/market/src/content/knowledge/sdk/ctx-query-language.mdx)
|
|
151
|
+
- [How ctx Works](/home/adrian/Projects/treeseed/market/src/content/knowledge/sdk/ctx-query-engine.mdx)
|
|
501
152
|
|
|
502
|
-
|
|
153
|
+
## Other Public Capabilities
|
|
503
154
|
|
|
504
|
-
|
|
155
|
+
The package also exports:
|
|
505
156
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
157
|
+
- workflow helpers such as `TreeseedWorkflowSdk`
|
|
158
|
+
- gateway and queue clients such as `TreeseedGatewayClient` and `CloudflareQueuePullClient`
|
|
159
|
+
- model registry, field, and filter utilities
|
|
160
|
+
- plugin/runtime types and helpers
|
|
510
161
|
|
|
511
|
-
For package
|
|
512
|
-
|
|
513
|
-
Example with an explicit root:
|
|
514
|
-
|
|
515
|
-
```ts
|
|
516
|
-
import { AgentSdk } from '@treeseed/sdk';
|
|
517
|
-
|
|
518
|
-
const sdk = new AgentSdk({
|
|
519
|
-
repoRoot: '/absolute/path/to/site-or-fixture-root',
|
|
520
|
-
});
|
|
521
|
-
```
|
|
522
|
-
|
|
523
|
-
## Local Development
|
|
162
|
+
For package work:
|
|
524
163
|
|
|
525
164
|
```bash
|
|
526
|
-
npm
|
|
165
|
+
npm install
|
|
527
166
|
npm run build
|
|
528
167
|
npm test
|
|
529
|
-
npm run test:smoke
|
|
530
|
-
npm run verify
|
|
531
168
|
```
|
|
532
|
-
|
|
533
|
-
What each command does:
|
|
534
|
-
|
|
535
|
-
- `npm run build`: builds `dist/`
|
|
536
|
-
- `npm test`: runs unit tests
|
|
537
|
-
- `npm run test:smoke`: packs the SDK tarball and verifies a clean import from the packed install
|
|
538
|
-
- `npm run verify`: runs the release verification path used by CI
|
|
539
|
-
|
|
540
|
-
## Sample Fixture Site
|
|
541
|
-
|
|
542
|
-
The canonical SDK sample fixture lives at `../fixtures/fixture-sdk-sample-site/template` in the TreeSeed workspace.
|
|
543
|
-
|
|
544
|
-
The SDK package also keeps a mirrored local fixture at `sdk/fixture` so the standalone SDK repository can run its own tests and CI without depending on the larger workspace layout.
|
|
545
|
-
|
|
546
|
-
It serves three purposes at once:
|
|
547
|
-
|
|
548
|
-
- a small documentation surface about working with TreeSeed
|
|
549
|
-
- the default local test ground for content-backed SDK behavior
|
|
550
|
-
- a concrete example of a valid `repoRoot` for `AgentSdk`
|
|
551
|
-
|
|
552
|
-
You can point the SDK at it directly:
|
|
553
|
-
|
|
554
|
-
```ts
|
|
555
|
-
import path from 'node:path';
|
|
556
|
-
import { AgentSdk } from '@treeseed/sdk';
|
|
557
|
-
|
|
558
|
-
const sdk = new AgentSdk({
|
|
559
|
-
repoRoot: path.resolve('../fixtures/fixture-sdk-sample-site/template'),
|
|
560
|
-
});
|
|
561
|
-
```
|
|
562
|
-
|
|
563
|
-
The fixture includes representative entries for pages, notes, questions, objectives, books, knowledge, people, and agents so local queries behave like a small real site instead of a synthetic stub.
|
|
564
|
-
|
|
565
|
-
In the full TreeSeed workspace, tests prefer the workspace fixture under `fixtures/`. In the standalone SDK repository, tests fall back to `sdk/fixture`.
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AgentCliOptions } from './types/agents.ts';
|
|
2
2
|
export declare function normalizeAgentCliOptions(input: unknown): AgentCliOptions;
|
|
3
3
|
export declare function buildCopilotAllowToolArgs(allowTools?: AgentCliOptions['allowTools']): string[];
|
package/dist/cli-tools.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const AGENT_CLI_ALLOW_TOOLS = [
|
|
2
|
+
"shell(git)",
|
|
3
|
+
"shell(npm)",
|
|
4
|
+
"web"
|
|
5
|
+
];
|
|
4
6
|
const ALLOWED_TOOL_SET = new Set(AGENT_CLI_ALLOW_TOOLS);
|
|
5
7
|
function normalizeStringArray(value, field) {
|
|
6
8
|
if (value === void 0 || value === null) {
|