@lucern/sdk 0.2.0-alpha.6 → 0.2.0-alpha.7
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/.turbo/turbo-build.log +7 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CHANGELOG.md +13 -0
- package/examples/README.md +69 -0
- package/examples/contradiction.ts +94 -0
- package/examples/investigation-context.ts +118 -0
- package/examples/questions-and-tasks.ts +55 -0
- package/examples/quickstart.ts +97 -0
- package/examples/shared.ts +318 -0
- package/examples/strict-public-types.ts +143 -0
- package/examples/worktree-lifecycle.ts +79 -0
- package/package.json +16 -58
- package/src/README.md +6 -0
- package/src/adminClient.ts +789 -0
- package/{dist/lib/platform/sdk/answersClient.d.ts → src/answersClient.ts} +17 -4
- package/src/audiencesClient.ts +209 -0
- package/src/auditClient.ts +50 -0
- package/src/beliefsClient.ts +319 -0
- package/src/client.ts +2647 -0
- package/src/contextClient.ts +130 -0
- package/{dist/lib/platform/sdk/contextFacade.d.ts → src/contextFacade.ts} +6 -1
- package/src/contextPackCompiler.ts +828 -0
- package/src/contextPackSchema.ts +251 -0
- package/src/contextTypes.ts +153 -0
- package/src/contracts/api-enums.contract.ts +202 -0
- package/src/contracts/auth-session.contract.ts +109 -0
- package/src/contracts/context-pack.contract.ts +700 -0
- package/src/contracts/contextPack.ts +1 -0
- package/src/contracts/index.ts +10 -0
- package/src/contracts/lens-filter.contract.ts +183 -0
- package/src/contracts/lens-workflow.contract.ts +162 -0
- package/src/contracts/lensFilter.ts +1 -0
- package/src/contracts/lensWorkflow.ts +1 -0
- package/src/contracts/mcp-tools.contract.ts +3636 -0
- package/src/contracts/mcpTools.ts +1 -0
- package/src/contracts/prompt.contract.ts +50 -0
- package/src/contracts/prompt.ts +1 -0
- package/src/contracts/sdk-tools.contract.ts +1457 -0
- package/src/contracts/sdkTools.ts +1 -0
- package/src/contracts/workflow-runtime.contract.ts +440 -0
- package/src/contracts/workflowRuntime.ts +1 -0
- package/src/controlObjectOwnership.ts +286 -0
- package/src/coreClient.ts +570 -0
- package/src/customTools.ts +398 -0
- package/src/decisionsClient.ts +286 -0
- package/src/domainContext.ts +15 -0
- package/src/events.ts +531 -0
- package/src/eventsCore.ts +168 -0
- package/src/facade/beliefs.ts +83 -0
- package/src/facade/context.ts +110 -0
- package/src/facade/contradictions.ts +29 -0
- package/src/facade/edges.ts +30 -0
- package/src/facade/events.ts +23 -0
- package/src/facade/evidence.ts +41 -0
- package/src/facade/graph.ts +38 -0
- package/src/facade/identity.ts +16 -0
- package/src/facade/ontologies.ts +34 -0
- package/src/facade/questions.ts +59 -0
- package/src/facade/search.ts +16 -0
- package/src/facade/tasks.ts +37 -0
- package/src/facade/topics.ts +42 -0
- package/src/facade/webhooks.ts +58 -0
- package/src/facade/worktrees.ts +51 -0
- package/src/gatewayFacades.ts +1666 -0
- package/src/graphClient.ts +529 -0
- package/src/harnessClient.ts +585 -0
- package/src/identityClient.ts +278 -0
- package/src/learningClient.ts +95 -0
- package/src/mcpParityClient.ts +240 -0
- package/src/mcpParitySurface.ts +70 -0
- package/src/ontologyClient.ts +275 -0
- package/src/packRuntime.ts +3 -0
- package/src/packsClient.ts +260 -0
- package/src/policyClient.ts +572 -0
- package/src/realtime/index.ts +51 -0
- package/src/realtime/refs.ts +17 -0
- package/src/reportsClient.ts +99 -0
- package/src/schemaClient.ts +129 -0
- package/src/sdkSurface.ts +190 -0
- package/src/topicsClient.ts +243 -0
- package/src/types.ts +807 -0
- package/src/workflowClient.ts +826 -0
- package/tsconfig.json +9 -0
- package/dist/.generated +0 -2
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/lib/platform/auth/credentials.d.ts +0 -5
- package/dist/lib/platform/auth/credentials.js +0 -40
- package/dist/lib/platform/sdk/adminClient.d.ts +0 -404
- package/dist/lib/platform/sdk/adminClient.js +0 -384
- package/dist/lib/platform/sdk/answersClient.js +0 -21
- package/dist/lib/platform/sdk/audiencesClient.d.ts +0 -93
- package/dist/lib/platform/sdk/audiencesClient.js +0 -111
- package/dist/lib/platform/sdk/auditClient.d.ts +0 -24
- package/dist/lib/platform/sdk/auditClient.js +0 -21
- package/dist/lib/platform/sdk/beliefsClient.d.ts +0 -157
- package/dist/lib/platform/sdk/beliefsClient.js +0 -124
- package/dist/lib/platform/sdk/client.d.ts +0 -2369
- package/dist/lib/platform/sdk/client.js +0 -1831
- package/dist/lib/platform/sdk/contextClient.d.ts +0 -21
- package/dist/lib/platform/sdk/contextClient.js +0 -86
- package/dist/lib/platform/sdk/contextFacade.js +0 -10
- package/dist/lib/platform/sdk/contextPackCompiler.d.ts +0 -100
- package/dist/lib/platform/sdk/contextPackCompiler.js +0 -534
- package/dist/lib/platform/sdk/contextTypes.d.ts +0 -133
- package/dist/lib/platform/sdk/contextTypes.js +0 -1
- package/dist/lib/platform/sdk/controlObjectOwnership.d.ts +0 -308
- package/dist/lib/platform/sdk/controlObjectOwnership.js +0 -220
- package/dist/lib/platform/sdk/coreClient.d.ts +0 -139
- package/dist/lib/platform/sdk/coreClient.js +0 -366
- package/dist/lib/platform/sdk/customTools.d.ts +0 -83
- package/dist/lib/platform/sdk/customTools.js +0 -247
- package/dist/lib/platform/sdk/decisionsClient.d.ts +0 -106
- package/dist/lib/platform/sdk/decisionsClient.js +0 -129
- package/dist/lib/platform/sdk/domainContext.d.ts +0 -1
- package/dist/lib/platform/sdk/domainContext.js +0 -1
- package/dist/lib/platform/sdk/events.d.ts +0 -176
- package/dist/lib/platform/sdk/events.js +0 -261
- package/dist/lib/platform/sdk/eventsCore.d.ts +0 -13
- package/dist/lib/platform/sdk/eventsCore.js +0 -13
- package/dist/lib/platform/sdk/gatewayFacades.d.ts +0 -586
- package/dist/lib/platform/sdk/gatewayFacades.js +0 -845
- package/dist/lib/platform/sdk/graphClient.d.ts +0 -266
- package/dist/lib/platform/sdk/graphClient.js +0 -235
- package/dist/lib/platform/sdk/harnessClient.d.ts +0 -309
- package/dist/lib/platform/sdk/harnessClient.js +0 -219
- package/dist/lib/platform/sdk/identityClient.d.ts +0 -134
- package/dist/lib/platform/sdk/identityClient.js +0 -131
- package/dist/lib/platform/sdk/index.js +0 -49
- package/dist/lib/platform/sdk/learningClient.d.ts +0 -40
- package/dist/lib/platform/sdk/learningClient.js +0 -53
- package/dist/lib/platform/sdk/mcpParityClient.d.ts +0 -69
- package/dist/lib/platform/sdk/mcpParityClient.js +0 -196
- package/dist/lib/platform/sdk/mcpParitySurface.d.ts +0 -10
- package/dist/lib/platform/sdk/mcpParitySurface.js +0 -57
- package/dist/lib/platform/sdk/ontologyClient.d.ts +0 -131
- package/dist/lib/platform/sdk/ontologyClient.js +0 -161
- package/dist/lib/platform/sdk/packRuntime.d.ts +0 -1
- package/dist/lib/platform/sdk/packRuntime.js +0 -1
- package/dist/lib/platform/sdk/packsClient.d.ts +0 -126
- package/dist/lib/platform/sdk/packsClient.js +0 -157
- package/dist/lib/platform/sdk/policyClient.d.ts +0 -293
- package/dist/lib/platform/sdk/policyClient.js +0 -277
- package/dist/lib/platform/sdk/promptCatalog.js +0 -1
- package/dist/lib/platform/sdk/reportsClient.d.ts +0 -34
- package/dist/lib/platform/sdk/reportsClient.js +0 -64
- package/dist/lib/platform/sdk/schemaClient.d.ts +0 -59
- package/dist/lib/platform/sdk/schemaClient.js +0 -71
- package/dist/lib/platform/sdk/sdkSurface.d.ts +0 -56
- package/dist/lib/platform/sdk/sdkSurface.js +0 -140
- package/dist/lib/platform/sdk/topicsClient.d.ts +0 -78
- package/dist/lib/platform/sdk/topicsClient.js +0 -118
- package/dist/lib/platform/sdk/types.d.ts +0 -692
- package/dist/lib/platform/sdk/types.js +0 -1
- package/dist/lib/platform/sdk/version.d.ts +0 -2
- package/dist/lib/platform/sdk/workflowClient.d.ts +0 -313
- package/dist/lib/platform/sdk/workflowClient.js +0 -366
- package/dist/lucern/contracts/src/api-enums.contract.d.ts +0 -58
- package/dist/lucern/contracts/src/api-enums.contract.js +0 -147
- package/dist/lucern/contracts/src/auth-context.contract.d.ts +0 -8
- package/dist/lucern/contracts/src/auth-context.contract.js +0 -8
- package/dist/lucern/contracts/src/auth-session.contract.d.ts +0 -8
- package/dist/lucern/contracts/src/auth-session.contract.js +0 -8
- package/dist/lucern/contracts/src/auth.contract.d.ts +0 -88
- package/dist/lucern/contracts/src/auth.contract.js +0 -57
- package/dist/lucern/contracts/src/context-pack.contract.d.ts +0 -494
- package/dist/lucern/contracts/src/context-pack.contract.js +0 -169
- package/dist/lucern/contracts/src/convex-admin.contract.d.ts +0 -5
- package/dist/lucern/contracts/src/convex-admin.contract.js +0 -1
- package/dist/lucern/contracts/src/events-types.contract.d.ts +0 -8
- package/dist/lucern/contracts/src/events-types.contract.js +0 -8
- package/dist/lucern/contracts/src/events.contract.d.ts +0 -176
- package/dist/lucern/contracts/src/events.contract.js +0 -159
- package/dist/lucern/contracts/src/gateway.contract.d.ts +0 -74
- package/dist/lucern/contracts/src/gateway.contract.js +0 -19
- package/dist/lucern/contracts/src/ids.contract.d.ts +0 -7
- package/dist/lucern/contracts/src/ids.contract.js +0 -24
- package/dist/lucern/contracts/src/index.d.ts +0 -29
- package/dist/lucern/contracts/src/index.js +0 -29
- package/dist/lucern/contracts/src/lens-filter.contract.d.ts +0 -70
- package/dist/lucern/contracts/src/lens-filter.contract.js +0 -95
- package/dist/lucern/contracts/src/lens-workflow.contract.d.ts +0 -84
- package/dist/lucern/contracts/src/lens-workflow.contract.js +0 -54
- package/dist/lucern/contracts/src/mcp-tools.contract.d.ts +0 -151
- package/dist/lucern/contracts/src/mcp-tools.contract.js +0 -3281
- package/dist/lucern/contracts/src/ontology-matching.contract.d.ts +0 -8
- package/dist/lucern/contracts/src/ontology-matching.contract.js +0 -8
- package/dist/lucern/contracts/src/prompt.contract.d.ts +0 -24
- package/dist/lucern/contracts/src/prompt.contract.js +0 -24
- package/dist/lucern/contracts/src/sdk-methods.contract.d.ts +0 -358
- package/dist/lucern/contracts/src/sdk-methods.contract.js +0 -19
- package/dist/lucern/contracts/src/sdk-tools.contract.d.ts +0 -92
- package/dist/lucern/contracts/src/sdk-tools.contract.js +0 -1398
- package/dist/lucern/contracts/src/text-matching.contract.d.ts +0 -53
- package/dist/lucern/contracts/src/text-matching.contract.js +0 -277
- package/dist/lucern/contracts/src/topic-scope.contract.d.ts +0 -8
- package/dist/lucern/contracts/src/topic-scope.contract.js +0 -8
- package/dist/lucern/contracts/src/workflow-runtime.contract.d.ts +0 -161
- package/dist/lucern/contracts/src/workflow-runtime.contract.js +0 -257
- package/dist/realtime-refs.d.ts +0 -1
- package/dist/realtime-refs.js +0 -1
- package/dist/realtime.d.ts +0 -1
- package/dist/realtime.js +0 -1
- /package/{dist/lib/platform/sdk/index.d.ts → src/index.ts} +0 -0
- /package/{dist/lib/platform/sdk/promptCatalog.d.ts → src/promptCatalog.ts} +0 -0
- /package/{dist/lib/platform/sdk/version.js → src/version.ts} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
> @lucern/sdk@0.2.0-alpha.5 build /Users/petercasella/lucern-repo/packages/sdk
|
|
3
|
+
> bash -lc 'cd ../../.. && npx tsx scripts/build-sdk-package.ts'
|
|
4
|
+
|
|
5
|
+
npm warn Unknown env config "_lucern-registry". This will stop working in the next major version of npm.
|
|
6
|
+
npm error A complete log of this run can be found in: /Users/petercasella/.npm/_logs/2026-04-19T23_24_01_220Z-debug-0.log
|
|
7
|
+
ELIFECYCLE Command failed with exit code 1.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@lucern/sdk` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
- No unreleased changes yet.
|
|
7
|
+
|
|
8
|
+
## [0.2.0-alpha.5] - 2026-04-18
|
|
9
|
+
- Refresh publish from current stackos source under EK-16 T4.
|
|
10
|
+
- Version-numbering note: 0.2.0-alpha.2 through 0.2.0-alpha.5 were published from earlier stackos source on 2026-04-12 by pete_c. This release (alpha.5) is the first to ship the current April 18 source — 56 commits of accumulated changes from the code-separation track.
|
|
11
|
+
|
|
12
|
+
## [0.2.0-alpha.1] - 2026-03-17
|
|
13
|
+
- Current private registry release baseline for the typed SDK client.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# SDK Examples
|
|
2
|
+
|
|
3
|
+
Runnable examples for `@lucern/sdk` that exercise the belief lifecycle against a live deployment.
|
|
4
|
+
|
|
5
|
+
Inside this repo, the examples import `../src/index.js` so they stay aligned with the current public surface during development. When the package is published, the same imports translate directly to `@lucern/sdk`. Each run creates a fresh child topic under the topic you provide, so the example state stays isolated from the parent scope.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
Export the deployment origin, API key, and a writable parent topic:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
export LUCERN_BASE_URL="https://your-deployment.example.com"
|
|
13
|
+
export LUCERN_API_KEY="luc_..."
|
|
14
|
+
export LUCERN_TOPIC_ID="topic_you_can_write_into"
|
|
15
|
+
export LUCERN_ENVIRONMENT="sandbox"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`LUCERN_BASE_URL` may also be provided as `LUCERN_API_BASE_URL`. `LUCERN_TOPIC_ID` may also be provided as `LUCERN_PROJECT_ID`.
|
|
19
|
+
|
|
20
|
+
## Run
|
|
21
|
+
|
|
22
|
+
Use `tsx` from the repo root:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npx tsx lucern/packages/sdk/examples/quickstart.ts
|
|
26
|
+
npx tsx lucern/packages/sdk/examples/questions-and-tasks.ts
|
|
27
|
+
npx tsx lucern/packages/sdk/examples/worktree-lifecycle.ts
|
|
28
|
+
npx tsx lucern/packages/sdk/examples/investigation-context.ts
|
|
29
|
+
npx tsx lucern/packages/sdk/examples/contradiction.ts
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Every script prints a JSON payload with `status`, IDs, and the visible output of the operations it executed.
|
|
33
|
+
|
|
34
|
+
## Example Map
|
|
35
|
+
|
|
36
|
+
| File | Covers |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| `quickstart.ts` | Create topic, create belief with the `text` alias, add evidence, modulate confidence, fork belief, search beliefs |
|
|
39
|
+
| `questions-and-tasks.ts` | Create a question linked to a belief, then create a task linked to that question and belief |
|
|
40
|
+
| `worktree-lifecycle.ts` | Create branch, create worktree, activate it through the public SDK, then list the created worktree |
|
|
41
|
+
| `investigation-context.ts` | Attempt hosted-MCP `compile_context`, with a public-SDK composed fallback when that tool is unavailable on the deployment |
|
|
42
|
+
| `contradiction.ts` | Create two beliefs, flag a contradiction, and list the visible contradiction state |
|
|
43
|
+
| `strict-public-types.ts` | Compile-time guard that public SDK types stay strict and do not regress to unknown-string index signatures |
|
|
44
|
+
|
|
45
|
+
## Expected Output
|
|
46
|
+
|
|
47
|
+
The quickstart returns a compact JSON summary:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"example": "quickstart",
|
|
52
|
+
"status": "ok",
|
|
53
|
+
"topic": {
|
|
54
|
+
"topicId": "topic_..."
|
|
55
|
+
},
|
|
56
|
+
"quickstart": {
|
|
57
|
+
"beliefId": "belief_...",
|
|
58
|
+
"forkId": "belief_...",
|
|
59
|
+
"resultCount": 1
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The hosted-MCP-based examples stay runnable even when the deployment does not yet expose those tools. In that case they return a `mode` such as `hosted-mcp-preview` or `composed-fallback` instead of failing silently.
|
|
65
|
+
|
|
66
|
+
## Notes
|
|
67
|
+
|
|
68
|
+
- These scripts create fresh topics, beliefs, tasks, and worktrees. Use a sandbox topic and API key.
|
|
69
|
+
- `investigation-context.ts` and `contradiction.ts` still make the remaining public-surface gaps explicit instead of patching the SDK source in-place.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
callHostedMcpTool,
|
|
3
|
+
createExampleTopic,
|
|
4
|
+
requireStringField,
|
|
5
|
+
runExample,
|
|
6
|
+
} from "./shared.js";
|
|
7
|
+
|
|
8
|
+
runExample("contradiction", async (context) => {
|
|
9
|
+
const topic = await createExampleTopic(context, "contradiction");
|
|
10
|
+
|
|
11
|
+
const beliefA = await context.lucern.beliefs.create({
|
|
12
|
+
text: "Developers adopt the SDK faster when quickstarts stay linear and minimal.",
|
|
13
|
+
topicId: topic.topicId,
|
|
14
|
+
});
|
|
15
|
+
const beliefB = await context.lucern.beliefs.create({
|
|
16
|
+
text: "Developers adopt the SDK faster when examples enumerate every lifecycle branch on day one.",
|
|
17
|
+
topicId: topic.topicId,
|
|
18
|
+
});
|
|
19
|
+
const beliefAId = requireStringField(
|
|
20
|
+
beliefA.data,
|
|
21
|
+
["nodeId", "globalId"],
|
|
22
|
+
"beliefAId"
|
|
23
|
+
);
|
|
24
|
+
const beliefBId = requireStringField(
|
|
25
|
+
beliefB.data,
|
|
26
|
+
["nodeId", "globalId"],
|
|
27
|
+
"beliefBId"
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const contradiction = await callHostedMcpTool(context, "flag_contradiction", {
|
|
31
|
+
beliefA: beliefAId,
|
|
32
|
+
beliefB: beliefBId,
|
|
33
|
+
defeatType: "rebuts",
|
|
34
|
+
description:
|
|
35
|
+
"The onboarding flow cannot be both minimal-first and exhaustive-first at the same time.",
|
|
36
|
+
topicId: topic.topicId,
|
|
37
|
+
severity: "high",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
let contradictionId: string | null = null;
|
|
41
|
+
if (contradiction.ok) {
|
|
42
|
+
contradictionId =
|
|
43
|
+
typeof (contradiction.payload as { contradictionId?: unknown })
|
|
44
|
+
?.contradictionId === "string"
|
|
45
|
+
? String(
|
|
46
|
+
(contradiction.payload as { contradictionId: string })
|
|
47
|
+
.contradictionId
|
|
48
|
+
)
|
|
49
|
+
: null;
|
|
50
|
+
} else {
|
|
51
|
+
const fallback = await context.lucern.raw.graph.createNode({
|
|
52
|
+
metadata: {
|
|
53
|
+
beliefA: beliefAId,
|
|
54
|
+
beliefB: beliefBId,
|
|
55
|
+
defeatType: "rebuts",
|
|
56
|
+
severity: "high",
|
|
57
|
+
status: "unresolved",
|
|
58
|
+
},
|
|
59
|
+
nodeType: "contradiction",
|
|
60
|
+
text: "The onboarding flow cannot be both minimal-first and exhaustive-first at the same time.",
|
|
61
|
+
topicId: topic.topicId,
|
|
62
|
+
});
|
|
63
|
+
contradictionId = requireStringField(
|
|
64
|
+
fallback.data,
|
|
65
|
+
["nodeId", "globalId"],
|
|
66
|
+
"contradictionId"
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const contradictions = await context.lucern.graph.findContradictions({
|
|
71
|
+
topicId: topic.topicId,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
contradiction: contradiction.ok
|
|
76
|
+
? {
|
|
77
|
+
contradictionId,
|
|
78
|
+
mode: "hosted-mcp",
|
|
79
|
+
payload: contradiction.payload,
|
|
80
|
+
}
|
|
81
|
+
: {
|
|
82
|
+
contradictionId,
|
|
83
|
+
mode: "raw-graph-fallback",
|
|
84
|
+
note: "Hosted MCP contradiction tooling was unavailable, so the example created the contradiction node through the raw graph client.",
|
|
85
|
+
payload: contradiction.payload,
|
|
86
|
+
},
|
|
87
|
+
beliefs: {
|
|
88
|
+
beliefAId,
|
|
89
|
+
beliefBId,
|
|
90
|
+
},
|
|
91
|
+
topic,
|
|
92
|
+
visibleContradictions: contradictions.contradictions,
|
|
93
|
+
};
|
|
94
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
callHostedMcpTool,
|
|
3
|
+
createExampleTopic,
|
|
4
|
+
listItems,
|
|
5
|
+
requireStringField,
|
|
6
|
+
runExample,
|
|
7
|
+
slugify,
|
|
8
|
+
} from "./shared.js";
|
|
9
|
+
|
|
10
|
+
runExample("investigation-context", async (context) => {
|
|
11
|
+
const topic = await createExampleTopic(context, "investigation-context");
|
|
12
|
+
const query = "SDK example context pack";
|
|
13
|
+
|
|
14
|
+
const belief = await context.lucern.beliefs.create({
|
|
15
|
+
text: "A focused context pack helps developers understand the next graph action without reading the whole ontology.",
|
|
16
|
+
topicId: topic.topicId,
|
|
17
|
+
});
|
|
18
|
+
const beliefId = requireStringField(
|
|
19
|
+
belief.data,
|
|
20
|
+
["nodeId", "globalId"],
|
|
21
|
+
"beliefId"
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
await context.lucern.evidence.add({
|
|
25
|
+
sourceUrl: "https://example.invalid/sdk-example-context",
|
|
26
|
+
supports: {
|
|
27
|
+
nodeId: beliefId,
|
|
28
|
+
reasoning:
|
|
29
|
+
"The example seeds one belief and one evidence item for retrieval.",
|
|
30
|
+
weight: 0.74,
|
|
31
|
+
},
|
|
32
|
+
text: "Context-pack example seeded a concrete signal about first-run developer comprehension.",
|
|
33
|
+
topicId: topic.topicId,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
await context.lucern.questions.create({
|
|
37
|
+
linkedBeliefId: beliefId,
|
|
38
|
+
priority: "high",
|
|
39
|
+
text: "Which belief, question, and worktree signals should show up first in a minimal onboarding context pack?",
|
|
40
|
+
topicId: topic.topicId,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const branch = await context.lucern.worktrees.createBranch({
|
|
44
|
+
description: "Branch for the investigation-context example.",
|
|
45
|
+
name: `sdk-context-${slugify(topic.name)}`,
|
|
46
|
+
topicId: topic.topicId,
|
|
47
|
+
});
|
|
48
|
+
const branchId = requireStringField(
|
|
49
|
+
branch.data,
|
|
50
|
+
["branchId", "nodeId"],
|
|
51
|
+
"branchId"
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
await context.lucern.worktrees.create({
|
|
55
|
+
beliefIds: [beliefId],
|
|
56
|
+
branchId,
|
|
57
|
+
hypothesis:
|
|
58
|
+
"A compact context bundle gives enough orientation to take the next reasoning action.",
|
|
59
|
+
title: "SDK Example Investigation Context",
|
|
60
|
+
topicId: topic.topicId,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const compiledContext = await callHostedMcpTool(context, "compile_context", {
|
|
64
|
+
budget: 1200,
|
|
65
|
+
limit: 5,
|
|
66
|
+
query,
|
|
67
|
+
topicId: topic.topicId,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (compiledContext.ok) {
|
|
71
|
+
return {
|
|
72
|
+
mode: "hosted-mcp",
|
|
73
|
+
topic,
|
|
74
|
+
contextPack: compiledContext.payload,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const beliefs = await context.lucern.graph.listBeliefs({
|
|
79
|
+
topicId: topic.topicId,
|
|
80
|
+
});
|
|
81
|
+
const questions = await context.lucern.questions.getHighPriority({
|
|
82
|
+
limit: 5,
|
|
83
|
+
topicId: topic.topicId,
|
|
84
|
+
});
|
|
85
|
+
const evidence = await context.lucern.evidence.search({
|
|
86
|
+
limit: 5,
|
|
87
|
+
query: "context-pack example",
|
|
88
|
+
topicId: topic.topicId,
|
|
89
|
+
});
|
|
90
|
+
const worktrees = await context.lucern.worktrees.list({
|
|
91
|
+
topicId: topic.topicId,
|
|
92
|
+
});
|
|
93
|
+
const recentEvidence = listItems<Record<string, unknown>>(evidence, "results");
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
mode: "composed-fallback",
|
|
97
|
+
note: "The hosted MCP deployment did not expose compile_context in this environment, so this example composes an equivalent bundle from the public SDK reads.",
|
|
98
|
+
mcp: {
|
|
99
|
+
contextPack: compiledContext.payload,
|
|
100
|
+
},
|
|
101
|
+
topic,
|
|
102
|
+
contextPack: {
|
|
103
|
+
beliefs: beliefs.slice(0, 5),
|
|
104
|
+
openQuestions: questions.questions,
|
|
105
|
+
recentEvidence,
|
|
106
|
+
summary: {
|
|
107
|
+
beliefCount: beliefs.length,
|
|
108
|
+
evidenceCount: recentEvidence.length,
|
|
109
|
+
questionCount: questions.questions.length,
|
|
110
|
+
worktreeCount: listItems(worktrees.data, "worktrees").length,
|
|
111
|
+
},
|
|
112
|
+
worktrees: listItems<Record<string, unknown>>(
|
|
113
|
+
worktrees.data,
|
|
114
|
+
"worktrees"
|
|
115
|
+
),
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createExampleTopic,
|
|
3
|
+
requireStringField,
|
|
4
|
+
runExample,
|
|
5
|
+
} from "./shared.js";
|
|
6
|
+
|
|
7
|
+
runExample("questions-and-tasks", async (context) => {
|
|
8
|
+
const topic = await createExampleTopic(context, "questions-and-tasks");
|
|
9
|
+
|
|
10
|
+
const belief = await context.lucern.beliefs.create({
|
|
11
|
+
metadata: {
|
|
12
|
+
example: "questions-and-tasks",
|
|
13
|
+
},
|
|
14
|
+
text: "SDK onboarding friction drops when runnable examples answer concrete first-run questions.",
|
|
15
|
+
topicId: topic.topicId,
|
|
16
|
+
});
|
|
17
|
+
const beliefId = requireStringField(
|
|
18
|
+
belief.data,
|
|
19
|
+
["nodeId", "globalId"],
|
|
20
|
+
"beliefId"
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const question = await context.lucern.questions.create({
|
|
24
|
+
linkedBeliefId: beliefId,
|
|
25
|
+
priority: "high",
|
|
26
|
+
text: "Which setup step still blocks a developer before the first successful belief write?",
|
|
27
|
+
topicId: topic.topicId,
|
|
28
|
+
});
|
|
29
|
+
const questionId = requireStringField(
|
|
30
|
+
question.data,
|
|
31
|
+
["nodeId", "globalId"],
|
|
32
|
+
"questionId"
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const task = await context.lucern.tasks.create({
|
|
36
|
+
description:
|
|
37
|
+
"Validate the setup sequence from API key + base URL to a successful belief.create() call.",
|
|
38
|
+
linkedBeliefId: beliefId,
|
|
39
|
+
linkedQuestionId: questionId,
|
|
40
|
+
priority: "high",
|
|
41
|
+
taskType: "analysis",
|
|
42
|
+
title: "Audit the first-belief onboarding sequence",
|
|
43
|
+
topicId: topic.topicId,
|
|
44
|
+
});
|
|
45
|
+
const taskId = requireStringField(task.data, ["taskId", "id"], "taskId");
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
topic,
|
|
49
|
+
workflow: {
|
|
50
|
+
beliefId,
|
|
51
|
+
questionId,
|
|
52
|
+
taskId,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createExampleTopic,
|
|
3
|
+
printJson,
|
|
4
|
+
requireStringField,
|
|
5
|
+
runExample,
|
|
6
|
+
} from "./shared.js";
|
|
7
|
+
|
|
8
|
+
if (process.argv.includes("--dry-run")) {
|
|
9
|
+
printJson({
|
|
10
|
+
example: "quickstart",
|
|
11
|
+
mode: "dry-run",
|
|
12
|
+
steps: [
|
|
13
|
+
"create topic",
|
|
14
|
+
"create belief with text alias",
|
|
15
|
+
"add evidence",
|
|
16
|
+
"modulate confidence",
|
|
17
|
+
"fork belief",
|
|
18
|
+
"search beliefs",
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
process.exit(0);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
runExample("quickstart", async (context) => {
|
|
25
|
+
const topic = await createExampleTopic(context, "quickstart");
|
|
26
|
+
|
|
27
|
+
const belief = await context.lucern.beliefs.create({
|
|
28
|
+
metadata: {
|
|
29
|
+
example: "quickstart",
|
|
30
|
+
source: "lucern/packages/sdk/examples/quickstart.ts",
|
|
31
|
+
},
|
|
32
|
+
text: "Time-to-first-belief drops when the SDK ships a concrete quickstart that exercises the core lifecycle end to end.",
|
|
33
|
+
topicId: topic.topicId,
|
|
34
|
+
});
|
|
35
|
+
const beliefId = requireStringField(
|
|
36
|
+
belief.data,
|
|
37
|
+
["nodeId", "globalId"],
|
|
38
|
+
"beliefId"
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const evidence = await context.lucern.evidence.add({
|
|
42
|
+
sourceUrl: "https://example.invalid/sdk-quickstart-signal",
|
|
43
|
+
supports: {
|
|
44
|
+
nodeId: beliefId,
|
|
45
|
+
reasoning:
|
|
46
|
+
"Example-driven onboarding reduces the amount of guesswork before a first successful write.",
|
|
47
|
+
weight: 0.81,
|
|
48
|
+
},
|
|
49
|
+
text: "A runnable example moved the first successful belief write into the first five minutes for a new developer.",
|
|
50
|
+
topicId: topic.topicId,
|
|
51
|
+
});
|
|
52
|
+
const evidenceId = requireStringField(
|
|
53
|
+
evidence,
|
|
54
|
+
["nodeId", "globalId"],
|
|
55
|
+
"evidenceId"
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
await context.lucern.beliefs.modulateConfidence(beliefId, {
|
|
59
|
+
confidence: 0.79,
|
|
60
|
+
rationale:
|
|
61
|
+
"The quickstart now demonstrates a complete create → evidence → confidence → fork path.",
|
|
62
|
+
trigger: "evidence_added",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const fork = await context.lucern.beliefs.fork(beliefId, {
|
|
66
|
+
forkReason: "refinement",
|
|
67
|
+
newFormulation:
|
|
68
|
+
"Time-to-first-belief drops below five minutes when the SDK ships a concrete quickstart that exercises the core lifecycle end to end.",
|
|
69
|
+
rationale: "Narrow the claim to the under-five-minute onboarding target.",
|
|
70
|
+
});
|
|
71
|
+
const forkId = requireStringField(
|
|
72
|
+
fork.data,
|
|
73
|
+
["nodeId", "forkedNodeId", "globalId"],
|
|
74
|
+
"forkId"
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const search = await context.lucern.beliefs.search({
|
|
78
|
+
limit: 5,
|
|
79
|
+
query: "time-to-first-belief",
|
|
80
|
+
topicId: topic.topicId,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
quickstart: {
|
|
85
|
+
beliefId,
|
|
86
|
+
evidenceId,
|
|
87
|
+
forkId,
|
|
88
|
+
resultCount: search.results.length,
|
|
89
|
+
searchResults: search.results.map((result) => ({
|
|
90
|
+
canonicalText: result.canonicalText,
|
|
91
|
+
confidence: result.confidence,
|
|
92
|
+
nodeId: result.nodeId,
|
|
93
|
+
})),
|
|
94
|
+
},
|
|
95
|
+
topic,
|
|
96
|
+
};
|
|
97
|
+
});
|