@tyvm/knowhow 0.0.130 → 0.0.132
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/package.json +1 -1
- package/src/agents/configurable/ConfigAgent.ts +0 -1
- package/src/agents/tools/startAgentTask.ts +17 -13
- package/src/ai.ts +55 -24
- package/src/chat/CliChatService.ts +7 -1
- package/src/chat/modules/AgentModule.ts +72 -14
- package/src/chat/renderer/PlainRenderer.ts +218 -0
- package/src/chat/renderer/index.ts +1 -0
- package/src/chat/renderer/loadRenderer.ts +2 -0
- package/src/chat.ts +2 -2
- package/src/cli.ts +23 -0
- package/src/clients/anthropic.ts +9 -1
- package/src/clients/fireworks.ts +10 -1
- package/src/clients/index.ts +6 -3
- package/src/clients/meta.ts +9 -0
- package/src/clients/pricing/anthropic.ts +11 -0
- package/src/clients/pricing/fireworks.ts +12 -0
- package/src/commands/agent.ts +53 -20
- package/src/commands/agents.ts +556 -0
- package/src/commands/hash.ts +170 -0
- package/src/commands/misc.ts +157 -3
- package/src/commands/skills.ts +36 -0
- package/src/config.ts +54 -2
- package/src/generate.ts +507 -0
- package/src/index.ts +32 -216
- package/src/services/BehaviorsService.ts +32 -0
- package/src/services/SkillsService.ts +198 -0
- package/src/types.ts +36 -4
- package/ts_build/package.json +1 -1
- package/ts_build/src/agents/configurable/ConfigAgent.js.map +1 -1
- package/ts_build/src/agents/tools/startAgentTask.d.ts +2 -2
- package/ts_build/src/agents/tools/startAgentTask.js +13 -12
- package/ts_build/src/agents/tools/startAgentTask.js.map +1 -1
- package/ts_build/src/ai.d.ts +10 -4
- package/ts_build/src/ai.js +27 -25
- package/ts_build/src/ai.js.map +1 -1
- package/ts_build/src/chat/CliChatService.d.ts +1 -1
- package/ts_build/src/chat/CliChatService.js +4 -1
- package/ts_build/src/chat/CliChatService.js.map +1 -1
- package/ts_build/src/chat/modules/AgentModule.js +61 -4
- package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
- package/ts_build/src/chat/renderer/PlainRenderer.d.ts +28 -0
- package/ts_build/src/chat/renderer/PlainRenderer.js +169 -0
- package/ts_build/src/chat/renderer/PlainRenderer.js.map +1 -0
- package/ts_build/src/chat/renderer/index.d.ts +1 -0
- package/ts_build/src/chat/renderer/index.js +3 -1
- package/ts_build/src/chat/renderer/index.js.map +1 -1
- package/ts_build/src/chat/renderer/loadRenderer.js +2 -0
- package/ts_build/src/chat/renderer/loadRenderer.js.map +1 -1
- package/ts_build/src/chat.d.ts +1 -1
- package/ts_build/src/chat.js +2 -2
- package/ts_build/src/chat.js.map +1 -1
- package/ts_build/src/cli.js +16 -0
- package/ts_build/src/cli.js.map +1 -1
- package/ts_build/src/clients/anthropic.js +4 -1
- package/ts_build/src/clients/anthropic.js.map +1 -1
- package/ts_build/src/clients/fireworks.js +7 -0
- package/ts_build/src/clients/fireworks.js.map +1 -1
- package/ts_build/src/clients/index.js +5 -1
- package/ts_build/src/clients/index.js.map +1 -1
- package/ts_build/src/clients/meta.d.ts +2 -0
- package/ts_build/src/clients/meta.js +5 -0
- package/ts_build/src/clients/meta.js.map +1 -1
- package/ts_build/src/clients/pricing/anthropic.d.ts +3 -0
- package/ts_build/src/clients/pricing/anthropic.js +6 -0
- package/ts_build/src/clients/pricing/anthropic.js.map +1 -1
- package/ts_build/src/clients/pricing/fireworks.d.ts +1 -0
- package/ts_build/src/clients/pricing/fireworks.js +5 -1
- package/ts_build/src/clients/pricing/fireworks.js.map +1 -1
- package/ts_build/src/commands/agent.js +44 -17
- package/ts_build/src/commands/agent.js.map +1 -1
- package/ts_build/src/commands/agents.d.ts +2 -0
- package/ts_build/src/commands/agents.js +460 -0
- package/ts_build/src/commands/agents.js.map +1 -0
- package/ts_build/src/commands/hash.d.ts +2 -0
- package/ts_build/src/commands/hash.js +150 -0
- package/ts_build/src/commands/hash.js.map +1 -0
- package/ts_build/src/commands/misc.js +108 -2
- package/ts_build/src/commands/misc.js.map +1 -1
- package/ts_build/src/commands/skills.js +24 -0
- package/ts_build/src/commands/skills.js.map +1 -1
- package/ts_build/src/config.js +37 -1
- package/ts_build/src/config.js.map +1 -1
- package/ts_build/src/generate.d.ts +16 -0
- package/ts_build/src/generate.js +304 -0
- package/ts_build/src/generate.js.map +1 -0
- package/ts_build/src/index.d.ts +1 -3
- package/ts_build/src/index.js +9 -118
- package/ts_build/src/index.js.map +1 -1
- package/ts_build/src/services/BehaviorsService.d.ts +2 -0
- package/ts_build/src/services/BehaviorsService.js +24 -0
- package/ts_build/src/services/BehaviorsService.js.map +1 -1
- package/ts_build/src/services/SkillsService.d.ts +7 -0
- package/ts_build/src/services/SkillsService.js +163 -0
- package/ts_build/src/services/SkillsService.js.map +1 -1
- package/ts_build/src/types.d.ts +14 -4
- package/ts_build/src/types.js.map +1 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import * as crypto from "crypto";
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
|
+
import { globSync } from "glob";
|
|
6
|
+
import { getHashes, saveHashes } from "../hashes";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Compute an MD5 hash over the sorted contents of all matched files.
|
|
10
|
+
* Uses file content only (not mtime) for stability across CI clones.
|
|
11
|
+
*/
|
|
12
|
+
function hashFiles(files: string[]): string {
|
|
13
|
+
const hash = crypto.createHash("md5");
|
|
14
|
+
const sorted = [...files].sort();
|
|
15
|
+
for (const f of sorted) {
|
|
16
|
+
if (!fs.existsSync(f)) continue;
|
|
17
|
+
const content = fs.readFileSync(f);
|
|
18
|
+
hash.update(f);
|
|
19
|
+
hash.update(content);
|
|
20
|
+
}
|
|
21
|
+
return hash.digest("hex");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function addHashCommand(program: Command): void {
|
|
25
|
+
program
|
|
26
|
+
.command("hash")
|
|
27
|
+
.description(
|
|
28
|
+
"Check whether a named set of input files has changed since last saved. " +
|
|
29
|
+
"Exits 0 (unchanged) or 1 (changed / first run). " +
|
|
30
|
+
"Use with shell short-circuit: (knowhow hash ... || run-build-step)"
|
|
31
|
+
)
|
|
32
|
+
.requiredOption(
|
|
33
|
+
"--name <name>",
|
|
34
|
+
"Unique name for this hash slot (e.g. 'build', 'generate-api'). Becomes the top-level key in .hashes.json."
|
|
35
|
+
)
|
|
36
|
+
.requiredOption(
|
|
37
|
+
"--input <glob>",
|
|
38
|
+
"Glob pattern(s) of input files to hash. Separate multiple globs with commas."
|
|
39
|
+
)
|
|
40
|
+
.option(
|
|
41
|
+
"--output <paths>",
|
|
42
|
+
"Optional output file(s) — if any are missing the check always returns changed (comma-separated)."
|
|
43
|
+
)
|
|
44
|
+
.option(
|
|
45
|
+
"--save",
|
|
46
|
+
"Save the current hash after a successful build step."
|
|
47
|
+
)
|
|
48
|
+
.option(
|
|
49
|
+
"--run <command>",
|
|
50
|
+
"Self-contained mode: if inputs are unchanged, skip and exit 0. " +
|
|
51
|
+
"If changed (or first run), run this shell command and — only if it " +
|
|
52
|
+
"succeeds — save the new hash. Replaces the '(hash) || (build && hash --save)' pattern."
|
|
53
|
+
)
|
|
54
|
+
.option("--verbose", "Print what files were found and the computed hash")
|
|
55
|
+
.action(
|
|
56
|
+
async (opts: {
|
|
57
|
+
name: string;
|
|
58
|
+
input: string;
|
|
59
|
+
output?: string;
|
|
60
|
+
save?: boolean;
|
|
61
|
+
run?: string;
|
|
62
|
+
verbose?: boolean;
|
|
63
|
+
}) => {
|
|
64
|
+
const hashes = await getHashes();
|
|
65
|
+
|
|
66
|
+
const inputGlobs = opts.input.split(",").map((g) => g.trim());
|
|
67
|
+
const outputPaths = opts.output
|
|
68
|
+
? opts.output.split(",").map((p) => p.trim())
|
|
69
|
+
: [];
|
|
70
|
+
|
|
71
|
+
// Expand input globs
|
|
72
|
+
const inputFiles: string[] = [];
|
|
73
|
+
for (const pattern of inputGlobs) {
|
|
74
|
+
const matches = globSync(pattern, { nodir: true });
|
|
75
|
+
inputFiles.push(...matches);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (opts.verbose) {
|
|
79
|
+
console.error(`[knowhow hash] name=${opts.name}`);
|
|
80
|
+
console.error(
|
|
81
|
+
`[knowhow hash] input files (${inputFiles.length}): ${inputFiles.slice(0, 10).join(", ")}${inputFiles.length > 10 ? "…" : ""}`
|
|
82
|
+
);
|
|
83
|
+
if (outputPaths.length) {
|
|
84
|
+
console.error(`[knowhow hash] output files: ${outputPaths.join(", ")}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const currentHash = hashFiles(inputFiles);
|
|
89
|
+
|
|
90
|
+
// --save mode: record into .hashes.json under hashes[name][inputGlob] = hash
|
|
91
|
+
if (opts.save) {
|
|
92
|
+
if (!hashes[opts.name]) hashes[opts.name] = {};
|
|
93
|
+
hashes[opts.name][opts.input] = currentHash;
|
|
94
|
+
await saveHashes(hashes);
|
|
95
|
+
if (opts.verbose) {
|
|
96
|
+
console.error(`[knowhow hash] saved hash ${currentHash} for "${opts.name}"`);
|
|
97
|
+
}
|
|
98
|
+
process.exit(0);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Determine whether inputs (or missing outputs) indicate a rebuild is needed.
|
|
102
|
+
let changed = false;
|
|
103
|
+
|
|
104
|
+
// If any output file is missing, always report changed
|
|
105
|
+
for (const outPath of outputPaths) {
|
|
106
|
+
if (!fs.existsSync(outPath)) {
|
|
107
|
+
if (opts.verbose) {
|
|
108
|
+
console.error(`[knowhow hash] output file missing: ${outPath} → changed`);
|
|
109
|
+
}
|
|
110
|
+
changed = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const storedHash: string | undefined = hashes[opts.name]?.[opts.input];
|
|
115
|
+
|
|
116
|
+
if (opts.verbose) {
|
|
117
|
+
console.error(
|
|
118
|
+
`[knowhow hash] stored=${storedHash ?? "(none)"} current=${currentHash}`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!(storedHash && storedHash === currentHash)) {
|
|
123
|
+
changed = true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// --run mode: self-contained. Skip when unchanged; otherwise run the
|
|
127
|
+
// command and only save the new hash if it succeeds.
|
|
128
|
+
if (opts.run) {
|
|
129
|
+
if (!changed) {
|
|
130
|
+
if (opts.verbose) {
|
|
131
|
+
console.error(`[knowhow hash] ✓ unchanged — skipping "${opts.run}"`);
|
|
132
|
+
}
|
|
133
|
+
process.exit(0);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (opts.verbose) {
|
|
137
|
+
console.error(`[knowhow hash] ✗ changed — running "${opts.run}"`);
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
execSync(opts.run, { stdio: "inherit", shell: "/bin/sh" });
|
|
141
|
+
} catch (err: any) {
|
|
142
|
+
// Command failed — do NOT save the hash so it retries next time.
|
|
143
|
+
process.exit(typeof err?.status === "number" ? err.status : 1);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Command succeeded — record the hash of the inputs that produced it.
|
|
147
|
+
if (!hashes[opts.name]) hashes[opts.name] = {};
|
|
148
|
+
hashes[opts.name][opts.input] = currentHash;
|
|
149
|
+
await saveHashes(hashes);
|
|
150
|
+
if (opts.verbose) {
|
|
151
|
+
console.error(`[knowhow hash] saved hash ${currentHash} for "${opts.name}"`);
|
|
152
|
+
}
|
|
153
|
+
process.exit(0);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Legacy check mode: exit 0 (unchanged) or 1 (changed).
|
|
157
|
+
if (!changed) {
|
|
158
|
+
if (opts.verbose) {
|
|
159
|
+
console.error(`[knowhow hash] ✓ unchanged — skipping`);
|
|
160
|
+
}
|
|
161
|
+
process.exit(0);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (opts.verbose) {
|
|
165
|
+
console.error(`[knowhow hash] ✗ changed — rebuild needed`);
|
|
166
|
+
}
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
}
|
package/src/commands/misc.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { Command } from "commander";
|
|
|
2
2
|
import { execSync } from "child_process";
|
|
3
3
|
import { version } from "../../package.json";
|
|
4
4
|
import { logger } from "../logger";
|
|
5
|
-
import {
|
|
5
|
+
import { embed, upload, download, purge } from "../index";
|
|
6
|
+
import { generate, buildWaves, normalizeInputPattern, GenerateOptions } from "../generate";
|
|
6
7
|
import { init } from "../config";
|
|
7
8
|
import { login } from "../login";
|
|
8
9
|
import { KnowhowSimpleClient } from "../services/KnowhowClient";
|
|
@@ -53,13 +54,166 @@ export function addGenerateCommand(program: Command): void {
|
|
|
53
54
|
program
|
|
54
55
|
.command("generate")
|
|
55
56
|
.description("Generate documentation")
|
|
56
|
-
.
|
|
57
|
+
.option(
|
|
58
|
+
"--name <name>",
|
|
59
|
+
"Only run the generation source with this exact `name`"
|
|
60
|
+
)
|
|
61
|
+
.option(
|
|
62
|
+
"--filter <substring>",
|
|
63
|
+
"Only run generation sources whose name/input/output contains this substring"
|
|
64
|
+
)
|
|
65
|
+
.option(
|
|
66
|
+
"--sync-fs",
|
|
67
|
+
"Enable filesystem sync for agent-driven sources (creates .knowhow/processes/agents/<taskId>/ so tasks appear in `knowhow agents list`)"
|
|
68
|
+
)
|
|
69
|
+
.option(
|
|
70
|
+
"--force",
|
|
71
|
+
"Skip hash checks and regenerate all matching sources regardless of whether inputs/outputs have changed"
|
|
72
|
+
)
|
|
73
|
+
.option(
|
|
74
|
+
"--concurrency <n>",
|
|
75
|
+
"Maximum number of sources to run in parallel within a dependency wave (default: 3)",
|
|
76
|
+
(v) => parseInt(v, 10)
|
|
77
|
+
)
|
|
78
|
+
.option(
|
|
79
|
+
"--plan",
|
|
80
|
+
"Show the execution plan (dependency waves, skip/run status) without actually generating anything"
|
|
81
|
+
)
|
|
82
|
+
.action(async (options: {
|
|
83
|
+
name?: string;
|
|
84
|
+
filter?: string;
|
|
85
|
+
syncFs?: boolean;
|
|
86
|
+
force?: boolean;
|
|
87
|
+
concurrency?: number;
|
|
88
|
+
plan?: boolean;
|
|
89
|
+
}) => {
|
|
57
90
|
const { setupServices } = await import("./services");
|
|
58
91
|
await setupServices();
|
|
59
|
-
|
|
92
|
+
|
|
93
|
+
if (options.plan) {
|
|
94
|
+
await showGeneratePlan(options);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
await generate({
|
|
99
|
+
name: options.name,
|
|
100
|
+
filter: options.filter,
|
|
101
|
+
syncFs: options.syncFs,
|
|
102
|
+
force: options.force,
|
|
103
|
+
concurrency: options.concurrency,
|
|
104
|
+
});
|
|
60
105
|
});
|
|
61
106
|
}
|
|
62
107
|
|
|
108
|
+
async function showGeneratePlan(options: {
|
|
109
|
+
name?: string;
|
|
110
|
+
filter?: string;
|
|
111
|
+
force?: boolean;
|
|
112
|
+
concurrency?: number;
|
|
113
|
+
}): Promise<void> {
|
|
114
|
+
const { getConfig } = await import("../config");
|
|
115
|
+
const { getHashes, checkNoFilesChanged } = await import("../hashes");
|
|
116
|
+
const { globSync } = await import("glob");
|
|
117
|
+
const crypto = await import("crypto");
|
|
118
|
+
const { loadPrompt } = await import("../config");
|
|
119
|
+
|
|
120
|
+
const config = await getConfig();
|
|
121
|
+
const allSources = config.sources ?? [];
|
|
122
|
+
|
|
123
|
+
// Filter sources
|
|
124
|
+
const sources = allSources.filter((s) => {
|
|
125
|
+
if (options.name) return s.name === options.name;
|
|
126
|
+
if (options.filter) {
|
|
127
|
+
const needle = options.filter.toLowerCase();
|
|
128
|
+
return [s.name, s.input, s.output].filter(Boolean).some((v) => v!.toLowerCase().includes(needle));
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (sources.length === 0) {
|
|
134
|
+
console.warn("No generation sources matched the filter.");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const concurrency = options.concurrency ?? 3;
|
|
139
|
+
const waves = buildWaves(sources);
|
|
140
|
+
const hashes = await getHashes();
|
|
141
|
+
|
|
142
|
+
console.log(`\n📋 Generation Plan (concurrency: ${concurrency})\n`);
|
|
143
|
+
console.log(` Total sources : ${sources.length}`);
|
|
144
|
+
console.log(` Waves : ${waves.length}`);
|
|
145
|
+
console.log("");
|
|
146
|
+
|
|
147
|
+
for (let wi = 0; wi < waves.length; wi++) {
|
|
148
|
+
const wave = waves[wi];
|
|
149
|
+
console.log(`┌─ Wave ${wi + 1}/${waves.length} (${wave.length} source${wave.length !== 1 ? "s" : ""} in parallel)`);
|
|
150
|
+
|
|
151
|
+
for (const source of wave) {
|
|
152
|
+
// Determine skip/run status via hash check
|
|
153
|
+
let status = "▶ run ";
|
|
154
|
+
let reason = "";
|
|
155
|
+
|
|
156
|
+
if (!options.force) {
|
|
157
|
+
try {
|
|
158
|
+
const prompt = await loadPrompt(source.prompt);
|
|
159
|
+
const promptHash = crypto.createHash("md5").update(prompt || "").digest("hex");
|
|
160
|
+
let filesToCheck: string[];
|
|
161
|
+
|
|
162
|
+
if (source.output.endsWith("/")) {
|
|
163
|
+
// For multi-output we check the input files individually;
|
|
164
|
+
// just check one representative glob match to indicate staleness
|
|
165
|
+
const files = globSync(normalizeInputPattern(source.input || ""));
|
|
166
|
+
filesToCheck = files.length > 0 ? [files[0], source.output] : [source.output];
|
|
167
|
+
} else {
|
|
168
|
+
const files = globSync(normalizeInputPattern(source.input || ""));
|
|
169
|
+
filesToCheck = [source.output, ...files];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const noChanges = await checkNoFilesChanged(filesToCheck, promptHash, hashes);
|
|
173
|
+
if (noChanges) {
|
|
174
|
+
status = "⏭ skip";
|
|
175
|
+
reason = " (no changes)";
|
|
176
|
+
}
|
|
177
|
+
} catch {
|
|
178
|
+
// If hash check fails just mark as run
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
reason = " (--force)";
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const deps = source.dependsOn?.length ? ` [depends: ${source.dependsOn.join(", ")}]` : "";
|
|
185
|
+
const name = source.name ? `${source.name}` : "(unnamed)";
|
|
186
|
+
const arrow = `${source.input || "?"} → ${source.output || "?"}`;
|
|
187
|
+
console.log(`│ ${status} ${name.padEnd(30)} ${arrow}${reason}${deps}`);
|
|
188
|
+
}
|
|
189
|
+
console.log("└" + "─".repeat(60));
|
|
190
|
+
console.log("");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const runCount = (await Promise.all(
|
|
194
|
+
waves.flat().map(async (source) => {
|
|
195
|
+
if (options.force) return true;
|
|
196
|
+
try {
|
|
197
|
+
const prompt = await loadPrompt(source.prompt);
|
|
198
|
+
const promptHash = crypto.createHash("md5").update(prompt || "").digest("hex");
|
|
199
|
+
const files = globSync(normalizeInputPattern(source.input || ""));
|
|
200
|
+
const filesToCheck = source.output.endsWith("/")
|
|
201
|
+
? (files.length > 0 ? [files[0], source.output] : [source.output])
|
|
202
|
+
: [source.output, ...files];
|
|
203
|
+
const noChanges = await checkNoFilesChanged(filesToCheck, promptHash, hashes);
|
|
204
|
+
return !noChanges;
|
|
205
|
+
} catch {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
})
|
|
209
|
+
)).filter(Boolean).length;
|
|
210
|
+
|
|
211
|
+
console.log(` Would run : ${runCount} source${runCount !== 1 ? "s" : ""}`);
|
|
212
|
+
console.log(` Would skip : ${sources.length - runCount} source${sources.length - runCount !== 1 ? "s" : ""}`);
|
|
213
|
+
console.log("");
|
|
214
|
+
console.log("Run `knowhow generate` to execute, or add --force to skip hash checks.\n");
|
|
215
|
+
}
|
|
216
|
+
|
|
63
217
|
export function addEmbedCommands(program: Command): void {
|
|
64
218
|
program
|
|
65
219
|
.command("embed")
|
package/src/commands/skills.ts
CHANGED
|
@@ -68,4 +68,40 @@ export function addSkillsCommand(program: Command): void {
|
|
|
68
68
|
const svc = new SkillsService({ global: opts.global });
|
|
69
69
|
await svc.update(skillNames);
|
|
70
70
|
});
|
|
71
|
+
|
|
72
|
+
skills
|
|
73
|
+
.command("upload")
|
|
74
|
+
.description(
|
|
75
|
+
"Upload locally installed skills from .knowhow/skills/ to the backend as behaviors (isSkill: true)"
|
|
76
|
+
)
|
|
77
|
+
.option("--global", "Upload from global ~/.knowhow/skills/")
|
|
78
|
+
.option(
|
|
79
|
+
"--install-dir <dir>",
|
|
80
|
+
"Custom install directory to upload from (overrides default and --global)"
|
|
81
|
+
)
|
|
82
|
+
.action(async (opts: { global?: boolean; installDir?: string }) => {
|
|
83
|
+
const svc = new SkillsService({
|
|
84
|
+
global: opts.global,
|
|
85
|
+
installDir: opts.installDir,
|
|
86
|
+
});
|
|
87
|
+
await svc.upload();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
skills
|
|
91
|
+
.command("download")
|
|
92
|
+
.description(
|
|
93
|
+
"Download skill behaviors from the backend and write them as SKILL.md files into .knowhow/skills/<name>/SKILL.md"
|
|
94
|
+
)
|
|
95
|
+
.option("--global", "Download into global ~/.knowhow/skills/")
|
|
96
|
+
.option(
|
|
97
|
+
"--install-dir <dir>",
|
|
98
|
+
"Custom install directory (overrides default and --global)"
|
|
99
|
+
)
|
|
100
|
+
.action(async (opts: { global?: boolean; installDir?: string }) => {
|
|
101
|
+
const svc = new SkillsService({
|
|
102
|
+
global: opts.global,
|
|
103
|
+
installDir: opts.installDir,
|
|
104
|
+
});
|
|
105
|
+
await svc.download();
|
|
106
|
+
});
|
|
71
107
|
}
|
package/src/config.ts
CHANGED
|
@@ -7,6 +7,9 @@ import { promisify } from "util";
|
|
|
7
7
|
import { KNOWHOW_API_URL } from "./services/KnowhowClient";
|
|
8
8
|
import {
|
|
9
9
|
Config,
|
|
10
|
+
SourceRef,
|
|
11
|
+
GenerationSource,
|
|
12
|
+
EmbedSource,
|
|
10
13
|
Language,
|
|
11
14
|
AssistantConfig,
|
|
12
15
|
Models,
|
|
@@ -270,11 +273,58 @@ export function getConfigSync() {
|
|
|
270
273
|
}
|
|
271
274
|
|
|
272
275
|
let loggedWarning = false;
|
|
276
|
+
/**
|
|
277
|
+
* Checks whether an item in a sources/embedSources array is a SourceRef
|
|
278
|
+
* (i.e. `{ from: "..." }`) rather than a real source entry.
|
|
279
|
+
*/
|
|
280
|
+
function isSourceRef(item: unknown): item is SourceRef {
|
|
281
|
+
return (
|
|
282
|
+
typeof item === "object" &&
|
|
283
|
+
item !== null &&
|
|
284
|
+
"from" in item &&
|
|
285
|
+
typeof (item as any).from === "string"
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Resolves `{ from: "./path/to/file.json" }` entries in `sources` and
|
|
291
|
+
* `embedSources` arrays. Each referenced file must contain a JSON array of
|
|
292
|
+
* source entries. Paths are resolved relative to `.knowhow/`.
|
|
293
|
+
*/
|
|
294
|
+
function resolveSourceRefs<T>(
|
|
295
|
+
items: (T | SourceRef)[] | undefined,
|
|
296
|
+
label: string
|
|
297
|
+
): T[] {
|
|
298
|
+
if (!items) return [];
|
|
299
|
+
const resolved: T[] = [];
|
|
300
|
+
for (const item of items) {
|
|
301
|
+
if (isSourceRef(item)) {
|
|
302
|
+
const refPath = path.resolve(".knowhow", item.from);
|
|
303
|
+
try {
|
|
304
|
+
const raw = fs.readFileSync(refPath, "utf8");
|
|
305
|
+
const arr = JSON.parse(raw);
|
|
306
|
+
if (!Array.isArray(arr)) {
|
|
307
|
+
console.warn(`⚠️ ${label} ref "${item.from}" did not contain a JSON array — skipping.`);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
resolved.push(...(arr as T[]));
|
|
311
|
+
} catch (e) {
|
|
312
|
+
console.warn(`⚠️ Could not load ${label} ref "${item.from}": ${(e as Error).message}`);
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
resolved.push(item as T);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return resolved;
|
|
319
|
+
}
|
|
320
|
+
|
|
273
321
|
export async function getConfig() {
|
|
274
322
|
if (!fs.existsSync(".knowhow/knowhow.json")) {
|
|
275
323
|
if (!loggedWarning) {
|
|
276
324
|
loggedWarning = true;
|
|
277
|
-
|
|
325
|
+
const warnNeeds = process.env.KNOWHOW_WARN_NEEDS ?? "";
|
|
326
|
+
const shouldWarn = warnNeeds.split(",").includes("config");
|
|
327
|
+
if (shouldWarn && !process.argv.includes("init")) {
|
|
278
328
|
console.warn(
|
|
279
329
|
"KnowHow config file not found. Please run `knowhow init` to create it."
|
|
280
330
|
);
|
|
@@ -285,7 +335,9 @@ export async function getConfig() {
|
|
|
285
335
|
try {
|
|
286
336
|
const config = await readFile(".knowhow/knowhow.json", "utf8");
|
|
287
337
|
const parsedConfig = JSON.parse(config);
|
|
288
|
-
|
|
338
|
+
// Resolve any { from: "..." } SourceRef entries in sources / embedSources
|
|
339
|
+
parsedConfig.sources = resolveSourceRefs<GenerationSource>(parsedConfig.sources, "sources");
|
|
340
|
+
parsedConfig.embedSources = resolveSourceRefs<EmbedSource>(parsedConfig.embedSources, "embedSources");
|
|
289
341
|
return parsedConfig as Config;
|
|
290
342
|
} catch (error) {
|
|
291
343
|
console.error("Error reading .knowhow/knowhow.json:", error);
|