trucontext 0.3.1 → 0.4.1
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 +2 -0
- package/bin/cli.js +11 -1
- package/package.json +1 -1
- package/src/client.js +15 -0
- package/src/commands/docs.js +113 -0
package/README.md
CHANGED
|
@@ -168,6 +168,8 @@ Observe → Capture → Sleep → Wake → Query → Observe → ...
|
|
|
168
168
|
| `relationship-types` | List all relationship types |
|
|
169
169
|
| `schema show` | Show current app schema |
|
|
170
170
|
| `schema generate` | AI-generate a schema from description |
|
|
171
|
+
| `docs` | List all API documentation sections |
|
|
172
|
+
| `docs show <slug>` | View a specific doc section (no auth required) |
|
|
171
173
|
|
|
172
174
|
## API
|
|
173
175
|
|
package/bin/cli.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
3
4
|
import { program } from 'commander';
|
|
4
5
|
import { loginCommand } from '../src/commands/login.js';
|
|
6
|
+
|
|
7
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
5
8
|
import { logoutCommand } from '../src/commands/logout.js';
|
|
6
9
|
import { whoamiCommand } from '../src/commands/whoami.js';
|
|
7
10
|
import { appsCommand, useCommand } from '../src/commands/apps.js';
|
|
@@ -14,11 +17,12 @@ import { schemaShowCommand, schemaGenerateCommand, schemaSetAuthorshipCommand }
|
|
|
14
17
|
import { entitiesListCommand, entitiesGetCommand, entitiesCreateCommand, entitiesUpdateCommand, entitiesDeleteCommand, entitiesEdgesCommand } from '../src/commands/entities.js';
|
|
15
18
|
import { recipesListCommand, recipesGetCommand, recipesCreateCommand, recipesDeleteCommand } from '../src/commands/recipes.js';
|
|
16
19
|
import { relationshipTypesListCommand } from '../src/commands/relationship-types.js';
|
|
20
|
+
import { docsListCommand, docsShowCommand } from '../src/commands/docs.js';
|
|
17
21
|
|
|
18
22
|
program
|
|
19
23
|
.name('trucontext')
|
|
20
24
|
.description('TruContext CLI — contextual memory for AI applications')
|
|
21
|
-
.version(
|
|
25
|
+
.version(pkg.version);
|
|
22
26
|
|
|
23
27
|
// Auth
|
|
24
28
|
program.command('login')
|
|
@@ -101,6 +105,7 @@ entities.command('create')
|
|
|
101
105
|
.requiredOption('--type <Type>', 'Entity type (PascalCase)')
|
|
102
106
|
.option('--properties <json>', 'JSON properties object')
|
|
103
107
|
.option('--recipe <recipeId>', 'Recipe ID')
|
|
108
|
+
.option('--heartbeat', 'Enable heartbeat')
|
|
104
109
|
.option('--no-heartbeat', 'Disable heartbeat')
|
|
105
110
|
.option('--confidence <n>', 'Confidence level (0.0-1.0)')
|
|
106
111
|
.option('--temporal', 'Content can decay over time (default)')
|
|
@@ -164,4 +169,9 @@ schema.command('set-authorship <model>')
|
|
|
164
169
|
.description('Set authorship model (single_author, multi_author, anonymous)')
|
|
165
170
|
.action(schemaSetAuthorshipCommand);
|
|
166
171
|
|
|
172
|
+
// Docs (public — no auth required)
|
|
173
|
+
const docs = program.command('docs').description('Browse API documentation').action(docsListCommand);
|
|
174
|
+
docs.command('list').description('List all doc sections').action(docsListCommand);
|
|
175
|
+
docs.command('show <slug>').description('Show a specific doc section').action(docsShowCommand);
|
|
176
|
+
|
|
167
177
|
program.parse();
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -75,3 +75,18 @@ export function dataPlane(method, path, body) {
|
|
|
75
75
|
export function controlPlane(method, path, body) {
|
|
76
76
|
return request(CONTROL_PLANE_URL, method, path, body);
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
export async function publicApi(method, path) {
|
|
80
|
+
const ac = new AbortController();
|
|
81
|
+
const timeout = setTimeout(() => ac.abort(), 15000);
|
|
82
|
+
try {
|
|
83
|
+
const res = await fetch(`${CONTROL_PLANE_URL}${path}`, {
|
|
84
|
+
method,
|
|
85
|
+
headers: { 'Content-Type': 'application/json' },
|
|
86
|
+
signal: ac.signal,
|
|
87
|
+
});
|
|
88
|
+
return handleResponse(res);
|
|
89
|
+
} finally {
|
|
90
|
+
clearTimeout(timeout);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { publicApi } from '../client.js';
|
|
3
|
+
|
|
4
|
+
export async function docsListCommand() {
|
|
5
|
+
try {
|
|
6
|
+
const res = await publicApi('GET', '/public/docs');
|
|
7
|
+
const sections = res.data?.sections || res.sections || [];
|
|
8
|
+
|
|
9
|
+
if (sections.length === 0) {
|
|
10
|
+
console.log(chalk.yellow('No documentation available.'));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
console.log(chalk.bold('TruContext Documentation\n'));
|
|
15
|
+
for (const section of sections) {
|
|
16
|
+
const slug = section.sectionId || section.layerId || section.slug || section.id;
|
|
17
|
+
console.log(` ${chalk.cyan(slug.padEnd(28))} ${chalk.bold(section.title)}`);
|
|
18
|
+
}
|
|
19
|
+
console.log();
|
|
20
|
+
console.log(chalk.dim(`${sections.length} sections. Use: trucontext docs show <slug>`));
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.error(chalk.red(`Failed: ${err.message}`));
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function docsShowCommand(slug) {
|
|
28
|
+
try {
|
|
29
|
+
const res = await publicApi('GET', `/public/docs/${slug}`);
|
|
30
|
+
const doc = res.data || res;
|
|
31
|
+
|
|
32
|
+
if (!doc || !doc.title) {
|
|
33
|
+
console.error(chalk.red(`No doc found for slug: ${slug}`));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Title
|
|
38
|
+
console.log(chalk.bold.underline(`\n${doc.title}\n`));
|
|
39
|
+
|
|
40
|
+
// Main content
|
|
41
|
+
if (doc.content) {
|
|
42
|
+
console.log(renderMarkdown(doc.content));
|
|
43
|
+
console.log();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Callouts
|
|
47
|
+
for (const callout of (doc.callouts || [])) {
|
|
48
|
+
const icon = callout.variant === 'warning' ? '!' : 'i';
|
|
49
|
+
console.log(chalk.yellow(` [${icon}] ${chalk.bold(callout.title)}`));
|
|
50
|
+
console.log(` ${chalk.dim(callout.content.replace(/\n/g, '\n '))}`);
|
|
51
|
+
console.log();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Subsections
|
|
55
|
+
for (const sub of (doc.subsections || [])) {
|
|
56
|
+
if (sub.title) {
|
|
57
|
+
console.log(chalk.cyan.bold(`## ${sub.title}`));
|
|
58
|
+
}
|
|
59
|
+
if (sub.content) {
|
|
60
|
+
console.log(renderMarkdown(sub.content));
|
|
61
|
+
console.log();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Steps
|
|
65
|
+
for (const step of (sub.steps || [])) {
|
|
66
|
+
console.log(` ${chalk.green(step.number + '.')} ${renderMarkdown(step.content)}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Endpoints
|
|
70
|
+
for (const ep of (sub.endpoints || [])) {
|
|
71
|
+
console.log(` ${chalk.green(ep.method)} ${chalk.bold(ep.path)}`);
|
|
72
|
+
if (ep.description) console.log(` ${chalk.dim(ep.description)}`);
|
|
73
|
+
if (ep.auth) console.log(` ${chalk.dim(`Auth: ${ep.auth}`)}`);
|
|
74
|
+
if (ep.body) {
|
|
75
|
+
console.log(` ${chalk.dim('Body:')} ${JSON.stringify(ep.body, null, 2).split('\n').join('\n ')}`);
|
|
76
|
+
}
|
|
77
|
+
if (ep.response) {
|
|
78
|
+
console.log(` ${chalk.dim('Response:')} ${JSON.stringify(ep.response, null, 2).split('\n').join('\n ')}`);
|
|
79
|
+
}
|
|
80
|
+
console.log();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Code blocks
|
|
84
|
+
for (const block of (sub.codeBlocks || [])) {
|
|
85
|
+
if (block.title) console.log(` ${chalk.dim(block.title)}`);
|
|
86
|
+
console.log(chalk.green(` ${block.code}`));
|
|
87
|
+
console.log();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Items (relationship types, node types, etc.)
|
|
91
|
+
for (const item of (sub.items || [])) {
|
|
92
|
+
const label = item.type || item.name || item.recipeId || '';
|
|
93
|
+
const desc = item.description || '';
|
|
94
|
+
if (label) {
|
|
95
|
+
console.log(` ${chalk.yellow(label.padEnd(24))} ${desc}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (sub.steps?.length || sub.items?.length) console.log();
|
|
100
|
+
}
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.error(chalk.red(`Failed: ${err.message}`));
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Simple markdown-to-terminal renderer
|
|
108
|
+
function renderMarkdown(text) {
|
|
109
|
+
return text
|
|
110
|
+
.replace(/\*\*(.+?)\*\*/g, (_, m) => chalk.bold(m))
|
|
111
|
+
.replace(/`(.+?)`/g, (_, m) => chalk.green(m))
|
|
112
|
+
.replace(/\[(.+?)\]\(.+?\)/g, (_, m) => chalk.underline(m));
|
|
113
|
+
}
|