@best-agent/cli 0.0.2-beta.8 → 0.0.2-beta.9
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/LICENSE +21 -0
- package/README.md +44 -181
- package/dist/launcher.js +32 -0
- package/package.json +15 -27
- package/dist/best-agent-native-bridge.d.ts +0 -389
- package/dist/best-agent-native-bridge.js +0 -4645
- package/dist/cli-storage.d.ts +0 -5
- package/dist/cli-storage.js +0 -7
- package/dist/dimsdk/ask-user.d.ts +0 -21
- package/dist/dimsdk/ask-user.js +0 -131
- package/dist/dimsdk/cli/version.d.ts +0 -6
- package/dist/dimsdk/cli/version.js +0 -36
- package/dist/dimsdk/compat/archships/dim-agent/runtime-host.d.ts +0 -49
- package/dist/dimsdk/compat/archships/dim-agent/runtime-host.js +0 -215
- package/dist/dimsdk/compat/runtime-host.d.ts +0 -2
- package/dist/dimsdk/compat/runtime-host.js +0 -2
- package/dist/dimsdk/core/debug-log.d.ts +0 -8
- package/dist/dimsdk/core/debug-log.js +0 -100
- package/dist/dimsdk/core/env.d.ts +0 -26
- package/dist/dimsdk/core/env.js +0 -130
- package/dist/dimsdk/core/markdown/sanitize.d.ts +0 -2
- package/dist/dimsdk/core/markdown/sanitize.js +0 -43
- package/dist/dimsdk/core/markdown/wrap.d.ts +0 -9
- package/dist/dimsdk/core/markdown/wrap.js +0 -139
- package/dist/dimsdk/core/markdown.d.ts +0 -18
- package/dist/dimsdk/core/markdown.js +0 -62
- package/dist/dimsdk/core/model.d.ts +0 -273
- package/dist/dimsdk/core/model.js +0 -16
- package/dist/dimsdk/core/observability/perf-log.d.ts +0 -18
- package/dist/dimsdk/core/observability/perf-log.js +0 -236
- package/dist/dimsdk/core/store/agent-event-mappers.d.ts +0 -26
- package/dist/dimsdk/core/store/agent-event-mappers.js +0 -109
- package/dist/dimsdk/core/store/message-mutations.d.ts +0 -105
- package/dist/dimsdk/core/store/message-mutations.js +0 -1528
- package/dist/dimsdk/core/store/semantic-readers.d.ts +0 -2
- package/dist/dimsdk/core/store/semantic-readers.js +0 -4
- package/dist/dimsdk/core/store/transcript-projector.d.ts +0 -164
- package/dist/dimsdk/core/store/transcript-projector.js +0 -580
- package/dist/dimsdk/core/tool-metadata.d.ts +0 -12
- package/dist/dimsdk/core/tool-metadata.js +0 -70
- package/dist/dimsdk/core/transcript-part-id.d.ts +0 -6
- package/dist/dimsdk/core/transcript-part-id.js +0 -22
- package/dist/dimsdk/i18n/index.d.ts +0 -18
- package/dist/dimsdk/i18n/index.js +0 -141
- package/dist/dimsdk/i18n/locales/en.d.ts +0 -988
- package/dist/dimsdk/i18n/locales/en.js +0 -987
- package/dist/dimsdk/i18n/locales/index.d.ts +0 -1976
- package/dist/dimsdk/i18n/locales/index.js +0 -8
- package/dist/dimsdk/i18n/locales/zh-CN.d.ts +0 -988
- package/dist/dimsdk/i18n/locales/zh-CN.js +0 -987
- package/dist/dimsdk/i18n/types.d.ts +0 -13
- package/dist/dimsdk/i18n/types.js +0 -2
- package/dist/dimsdk/shared/value-normalizers.d.ts +0 -7
- package/dist/dimsdk/shared/value-normalizers.js +0 -48
- package/dist/dimsdk-tui.bundle-size.json +0 -169
- package/dist/dimsdk-tui.bundle.js +0 -330756
- package/dist/goatchain-adapter.d.ts +0 -41
- package/dist/goatchain-adapter.js +0 -499
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -1405
- package/dist/native-runtime-bridge.d.ts +0 -387
- package/dist/native-runtime-bridge.js +0 -4624
- package/dist/provider-config-env.d.ts +0 -7
- package/dist/provider-config-env.js +0 -286
- package/dist/provider-model-limit-index.generated.d.ts +0 -3
- package/dist/provider-model-limit-index.generated.js +0 -7818
- package/dist/provider-model-limits.d.ts +0 -8
- package/dist/provider-model-limits.js +0 -43
- package/dist/runtime.d.ts +0 -47
- package/dist/runtime.js +0 -516
package/dist/cli-storage.d.ts
DELETED
package/dist/cli-storage.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { resolveWorkspaceStorageRoot } from "@best-agent/foundation";
|
|
2
|
-
export function resolveCliStorageRoot(options) {
|
|
3
|
-
return (options.storageRoot ??
|
|
4
|
-
process.env.BEST_AGENT_STORAGE_ROOT ??
|
|
5
|
-
resolveWorkspaceStorageRoot(options.cwd ?? process.cwd()));
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=cli-storage.js.map
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export type NormalizedAskUserOption = Readonly<{
|
|
2
|
-
label: string;
|
|
3
|
-
description?: string;
|
|
4
|
-
}>;
|
|
5
|
-
export type NormalizedAskUserQuestion = Readonly<{
|
|
6
|
-
allowCustom: boolean;
|
|
7
|
-
id: string;
|
|
8
|
-
header: string;
|
|
9
|
-
kind: 'choice' | 'input';
|
|
10
|
-
multiline: boolean;
|
|
11
|
-
placeholder: string;
|
|
12
|
-
question: string;
|
|
13
|
-
options: readonly NormalizedAskUserOption[];
|
|
14
|
-
multiSelect: boolean;
|
|
15
|
-
}>;
|
|
16
|
-
export declare function getAskUserQuestionId(question: Readonly<{
|
|
17
|
-
id?: unknown;
|
|
18
|
-
}> | undefined, index: number): string;
|
|
19
|
-
export declare function normalizeAskUserQuestions(raw: unknown): NormalizedAskUserQuestion[];
|
|
20
|
-
export declare function mergeAskUserQuestions(currentRaw: unknown, fallbackRaw: unknown): NormalizedAskUserQuestion[];
|
|
21
|
-
//# sourceMappingURL=ask-user.d.ts.map
|
package/dist/dimsdk/ask-user.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
function asRecord(value) {
|
|
2
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
3
|
-
return null;
|
|
4
|
-
return value;
|
|
5
|
-
}
|
|
6
|
-
function normalizeAskUserText(value) {
|
|
7
|
-
return typeof value === 'string' ? value.trim() : '';
|
|
8
|
-
}
|
|
9
|
-
function fallbackAskUserQuestionId(index) {
|
|
10
|
-
return index === 0 ? 'answer' : `answer_${index + 1}`;
|
|
11
|
-
}
|
|
12
|
-
function normalizeAskUserQuestionCandidates(raw) {
|
|
13
|
-
if (Array.isArray(raw))
|
|
14
|
-
return raw;
|
|
15
|
-
if (typeof raw === 'string')
|
|
16
|
-
return [{ question: raw }];
|
|
17
|
-
const record = asRecord(raw);
|
|
18
|
-
if (!record)
|
|
19
|
-
return [];
|
|
20
|
-
return Array.isArray(record.questions) ? record.questions : [record];
|
|
21
|
-
}
|
|
22
|
-
function normalizeAskUserKind(value, hasOptions) {
|
|
23
|
-
const kind = normalizeAskUserText(value);
|
|
24
|
-
if (kind === 'choice')
|
|
25
|
-
return 'choice';
|
|
26
|
-
if (kind === 'input')
|
|
27
|
-
return 'input';
|
|
28
|
-
return hasOptions ? 'choice' : 'input';
|
|
29
|
-
}
|
|
30
|
-
function normalizeAskUserOption(value) {
|
|
31
|
-
if (typeof value === 'string') {
|
|
32
|
-
const label = normalizeAskUserText(value);
|
|
33
|
-
return label ? { label } : null;
|
|
34
|
-
}
|
|
35
|
-
const record = asRecord(value);
|
|
36
|
-
if (!record)
|
|
37
|
-
return null;
|
|
38
|
-
const label = normalizeAskUserText(record.label);
|
|
39
|
-
if (!label)
|
|
40
|
-
return null;
|
|
41
|
-
const description = normalizeAskUserText(record.description);
|
|
42
|
-
return description ? { label, description } : { label };
|
|
43
|
-
}
|
|
44
|
-
export function getAskUserQuestionId(question, index) {
|
|
45
|
-
return normalizeAskUserText(question?.id) || fallbackAskUserQuestionId(index);
|
|
46
|
-
}
|
|
47
|
-
export function normalizeAskUserQuestions(raw) {
|
|
48
|
-
const candidates = normalizeAskUserQuestionCandidates(raw);
|
|
49
|
-
const questions = [];
|
|
50
|
-
for (const [index, item] of candidates.entries()) {
|
|
51
|
-
const questionRecord = asRecord(item);
|
|
52
|
-
if (!questionRecord)
|
|
53
|
-
continue;
|
|
54
|
-
const optionsRaw = Array.isArray(questionRecord.options)
|
|
55
|
-
? questionRecord.options
|
|
56
|
-
: [];
|
|
57
|
-
const normalizedOptions = [];
|
|
58
|
-
for (const rawOption of optionsRaw) {
|
|
59
|
-
const option = normalizeAskUserOption(rawOption);
|
|
60
|
-
if (option)
|
|
61
|
-
normalizedOptions.push(option);
|
|
62
|
-
}
|
|
63
|
-
const kind = normalizeAskUserKind(questionRecord.kind, optionsRaw.length > 0);
|
|
64
|
-
questions.push({
|
|
65
|
-
allowCustom: questionRecord.allowCustom !== false,
|
|
66
|
-
id: getAskUserQuestionId(questionRecord, index),
|
|
67
|
-
header: normalizeAskUserText(questionRecord.header),
|
|
68
|
-
kind,
|
|
69
|
-
multiline: questionRecord.multiline === true,
|
|
70
|
-
placeholder: normalizeAskUserText(questionRecord.placeholder),
|
|
71
|
-
question: normalizeAskUserText(questionRecord.question),
|
|
72
|
-
options: normalizedOptions,
|
|
73
|
-
multiSelect: questionRecord.multiSelect === true,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return questions;
|
|
77
|
-
}
|
|
78
|
-
export function mergeAskUserQuestions(currentRaw, fallbackRaw) {
|
|
79
|
-
const current = normalizeAskUserQuestions(currentRaw);
|
|
80
|
-
const fallback = normalizeAskUserQuestions(fallbackRaw);
|
|
81
|
-
if (fallback.length === 0)
|
|
82
|
-
return current;
|
|
83
|
-
if (current.length === 0)
|
|
84
|
-
return fallback;
|
|
85
|
-
const merged = [];
|
|
86
|
-
for (let index = 0; index < Math.max(current.length, fallback.length); index += 1) {
|
|
87
|
-
const currentQuestion = current[index];
|
|
88
|
-
const fallbackQuestion = fallback[index];
|
|
89
|
-
if (!currentQuestion) {
|
|
90
|
-
if (fallbackQuestion)
|
|
91
|
-
merged.push(fallbackQuestion);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (!fallbackQuestion) {
|
|
95
|
-
merged.push(currentQuestion);
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const syntheticId = fallbackAskUserQuestionId(index);
|
|
99
|
-
const mergedId = currentQuestion.id === syntheticId
|
|
100
|
-
&& fallbackQuestion.id !== syntheticId
|
|
101
|
-
? fallbackQuestion.id
|
|
102
|
-
: currentQuestion.id || fallbackQuestion.id;
|
|
103
|
-
const shouldBackfillChoice = currentQuestion.kind === 'input'
|
|
104
|
-
&& currentQuestion.options.length === 0
|
|
105
|
-
&& fallbackQuestion.options.length > 0;
|
|
106
|
-
if (shouldBackfillChoice) {
|
|
107
|
-
merged.push({
|
|
108
|
-
...fallbackQuestion,
|
|
109
|
-
id: mergedId,
|
|
110
|
-
header: currentQuestion.header || fallbackQuestion.header,
|
|
111
|
-
question: currentQuestion.question || fallbackQuestion.question,
|
|
112
|
-
});
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
merged.push({
|
|
116
|
-
allowCustom: currentQuestion.allowCustom ?? fallbackQuestion.allowCustom,
|
|
117
|
-
id: mergedId,
|
|
118
|
-
header: currentQuestion.header || fallbackQuestion.header,
|
|
119
|
-
kind: currentQuestion.kind || fallbackQuestion.kind,
|
|
120
|
-
multiline: currentQuestion.multiline || fallbackQuestion.multiline,
|
|
121
|
-
placeholder: currentQuestion.placeholder || fallbackQuestion.placeholder,
|
|
122
|
-
question: currentQuestion.question || fallbackQuestion.question,
|
|
123
|
-
options: currentQuestion.options.length >= fallbackQuestion.options.length
|
|
124
|
-
? currentQuestion.options
|
|
125
|
-
: fallbackQuestion.options,
|
|
126
|
-
multiSelect: currentQuestion.multiSelect || fallbackQuestion.multiSelect,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
return merged;
|
|
130
|
-
}
|
|
131
|
-
//# sourceMappingURL=ask-user.js.map
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
export function resolveCliVersion() {
|
|
5
|
-
const injected = typeof __CLI_VERSION__ === 'string' ? __CLI_VERSION__.trim() : '';
|
|
6
|
-
if (injected)
|
|
7
|
-
return { version: injected, source: 'injected' };
|
|
8
|
-
const pkgVersion = readNearestPackageVersion();
|
|
9
|
-
if (pkgVersion)
|
|
10
|
-
return { version: pkgVersion, source: 'package' };
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
function readNearestPackageVersion() {
|
|
14
|
-
try {
|
|
15
|
-
let dir = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
-
for (let i = 0; i < 6; i++) {
|
|
17
|
-
const candidate = path.join(dir, 'package.json');
|
|
18
|
-
if (existsSync(candidate)) {
|
|
19
|
-
const raw = readFileSync(candidate, 'utf8');
|
|
20
|
-
const pkg = JSON.parse(raw);
|
|
21
|
-
const version = typeof pkg?.version === 'string' ? pkg.version.trim() : '';
|
|
22
|
-
if (version)
|
|
23
|
-
return version;
|
|
24
|
-
}
|
|
25
|
-
const parent = path.dirname(dir);
|
|
26
|
-
if (parent === dir)
|
|
27
|
-
break;
|
|
28
|
-
dir = parent;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
// ignore
|
|
33
|
-
}
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=version.js.map
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export declare const RUNTIME_SNAPSHOT_DIR = "runtime-snapshots";
|
|
2
|
-
export declare function sanitizeStructuredCloneValue<T>(value: T): T;
|
|
3
|
-
export type StructuredCloneSanitized = unknown;
|
|
4
|
-
type MessageLike = Readonly<{
|
|
5
|
-
role?: unknown;
|
|
6
|
-
content?: unknown;
|
|
7
|
-
}>;
|
|
8
|
-
type CanonicalizedSystemMessages<T extends MessageLike> = Readonly<{
|
|
9
|
-
systemPrompt: string;
|
|
10
|
-
messages: T[];
|
|
11
|
-
systemMessages: T[];
|
|
12
|
-
}>;
|
|
13
|
-
export declare function extractSystemMessageText(content: unknown): string;
|
|
14
|
-
export declare function canonicalizeSystemMessages<T extends MessageLike>(input: Readonly<{
|
|
15
|
-
systemPrompt?: unknown;
|
|
16
|
-
messages: readonly T[];
|
|
17
|
-
}>): CanonicalizedSystemMessages<T>;
|
|
18
|
-
export declare function applyCcMockSystemPrompt(input: unknown, _env?: Record<string, string | undefined>): string;
|
|
19
|
-
export declare function isDelegationRecordedFinalMessage(_value?: unknown): boolean;
|
|
20
|
-
export declare function normalizeRuntimeToolName(value: unknown): string;
|
|
21
|
-
export declare function normalizeAskUserQuestions<T>(questions: readonly T[]): T[];
|
|
22
|
-
export type PersistedSubagentChildSummary = {
|
|
23
|
-
sessionId: string;
|
|
24
|
-
state?: string;
|
|
25
|
-
summary?: string;
|
|
26
|
-
taskId?: string;
|
|
27
|
-
taskName?: string;
|
|
28
|
-
};
|
|
29
|
-
export declare function normalizePersistedSubagentChildSummary(value: unknown): PersistedSubagentChildSummary | null;
|
|
30
|
-
export declare function readPersistedSubagentChildSummaries(metadata: unknown): Array<{
|
|
31
|
-
sessionId: string;
|
|
32
|
-
summary?: string;
|
|
33
|
-
taskId?: string;
|
|
34
|
-
taskName?: string;
|
|
35
|
-
}>;
|
|
36
|
-
export declare function runtimeSnapshotPath(stateDir: string, sessionId: string): string;
|
|
37
|
-
export declare function readJsonFile<T>(filePath: string): Promise<T>;
|
|
38
|
-
export declare function writeJsonFile(filePath: string, value: unknown): Promise<void>;
|
|
39
|
-
export declare function safeLoadRuntimeSnapshot<T>(input: {
|
|
40
|
-
directory: string;
|
|
41
|
-
sessionId: string;
|
|
42
|
-
}): Promise<T | null>;
|
|
43
|
-
export declare function getSkillsCatalogRoots(cwd: string): string[];
|
|
44
|
-
export declare function scanMultipleSkillsDirectories(roots: readonly string[]): Promise<Array<{
|
|
45
|
-
name: string;
|
|
46
|
-
description: string;
|
|
47
|
-
}>>;
|
|
48
|
-
export {};
|
|
49
|
-
//# sourceMappingURL=runtime-host.d.ts.map
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import { dirname, join, resolve } from "node:path";
|
|
3
|
-
import { canonicalToolName } from "../../../core/tool-metadata.js";
|
|
4
|
-
export const RUNTIME_SNAPSHOT_DIR = "runtime-snapshots";
|
|
5
|
-
export function sanitizeStructuredCloneValue(value) {
|
|
6
|
-
return JSON.parse(JSON.stringify(value ?? null));
|
|
7
|
-
}
|
|
8
|
-
function appendContentText(content, parts) {
|
|
9
|
-
if (typeof content === "string") {
|
|
10
|
-
parts.push(content);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (Array.isArray(content)) {
|
|
14
|
-
for (const item of content) {
|
|
15
|
-
appendContentText(item, parts);
|
|
16
|
-
}
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (!content || typeof content !== "object") {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const record = content;
|
|
23
|
-
const type = typeof record.type === "string" ? record.type : "";
|
|
24
|
-
if (type === "text" || type === "input_text" || type === "output_text") {
|
|
25
|
-
if (typeof record.text === "string") {
|
|
26
|
-
parts.push(record.text);
|
|
27
|
-
}
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (typeof record.text === "string") {
|
|
31
|
-
parts.push(record.text);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if ("content" in record) {
|
|
35
|
-
appendContentText(record.content, parts);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export function extractSystemMessageText(content) {
|
|
39
|
-
const parts = [];
|
|
40
|
-
appendContentText(content, parts);
|
|
41
|
-
return parts.join("");
|
|
42
|
-
}
|
|
43
|
-
function normalizeSegment(content) {
|
|
44
|
-
if (typeof content !== "string") {
|
|
45
|
-
return "";
|
|
46
|
-
}
|
|
47
|
-
return content.trim();
|
|
48
|
-
}
|
|
49
|
-
function stripLeadingSystemPrompt(content, systemPrompt) {
|
|
50
|
-
const normalizedContent = normalizeSegment(content);
|
|
51
|
-
const normalizedSystemPrompt = normalizeSegment(systemPrompt);
|
|
52
|
-
if (!normalizedContent || !normalizedSystemPrompt) {
|
|
53
|
-
return normalizedContent;
|
|
54
|
-
}
|
|
55
|
-
if (normalizedContent === normalizedSystemPrompt) {
|
|
56
|
-
return "";
|
|
57
|
-
}
|
|
58
|
-
if (!normalizedContent.startsWith(normalizedSystemPrompt)) {
|
|
59
|
-
return normalizedContent;
|
|
60
|
-
}
|
|
61
|
-
const rest = normalizedContent.slice(normalizedSystemPrompt.length);
|
|
62
|
-
if (!rest) {
|
|
63
|
-
return "";
|
|
64
|
-
}
|
|
65
|
-
if (!/^\s*\n/.test(rest)) {
|
|
66
|
-
return normalizedContent;
|
|
67
|
-
}
|
|
68
|
-
return rest.replace(/^\s*\n\s*/, "").trim();
|
|
69
|
-
}
|
|
70
|
-
function pushUniqueSegment(segments, seen, content, systemPrompt) {
|
|
71
|
-
const normalized = stripLeadingSystemPrompt(normalizeSegment(content), systemPrompt);
|
|
72
|
-
if (!normalized || seen.has(normalized)) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
seen.add(normalized);
|
|
76
|
-
segments.push(normalized);
|
|
77
|
-
}
|
|
78
|
-
export function canonicalizeSystemMessages(input) {
|
|
79
|
-
const segments = [];
|
|
80
|
-
const seen = new Set();
|
|
81
|
-
const systemMessages = [];
|
|
82
|
-
const messages = [];
|
|
83
|
-
pushUniqueSegment(segments, seen, input.systemPrompt);
|
|
84
|
-
for (const message of input.messages) {
|
|
85
|
-
if (String(message?.role ?? "") === "system") {
|
|
86
|
-
systemMessages.push(message);
|
|
87
|
-
pushUniqueSegment(segments, seen, extractSystemMessageText(message?.content), input.systemPrompt);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
messages.push(message);
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
systemPrompt: segments.join("\n\n"),
|
|
94
|
-
messages,
|
|
95
|
-
systemMessages,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
export function applyCcMockSystemPrompt(input, _env) {
|
|
99
|
-
return String(input ?? "");
|
|
100
|
-
}
|
|
101
|
-
export function isDelegationRecordedFinalMessage(_value) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
export function normalizeRuntimeToolName(value) {
|
|
105
|
-
return canonicalToolName(value);
|
|
106
|
-
}
|
|
107
|
-
export function normalizeAskUserQuestions(questions) {
|
|
108
|
-
return [...questions];
|
|
109
|
-
}
|
|
110
|
-
export function normalizePersistedSubagentChildSummary(value) {
|
|
111
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
const record = value;
|
|
115
|
-
const sessionId = String(record.sessionId ?? record.childSessionId ?? "").trim();
|
|
116
|
-
if (!sessionId) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
const summary = String(record.summary ?? "").trim() || undefined;
|
|
120
|
-
const taskId = String(record.taskId ?? record.id ?? "").trim() || undefined;
|
|
121
|
-
const taskName = String(record.taskName ?? record.name ?? "").trim() || undefined;
|
|
122
|
-
return {
|
|
123
|
-
sessionId,
|
|
124
|
-
summary,
|
|
125
|
-
taskId,
|
|
126
|
-
taskName,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
export function readPersistedSubagentChildSummaries(metadata) {
|
|
130
|
-
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
|
|
131
|
-
return [];
|
|
132
|
-
}
|
|
133
|
-
const record = metadata;
|
|
134
|
-
const candidates = [record.subagentChildren, record.subagents, record.childSessions];
|
|
135
|
-
for (const candidate of candidates) {
|
|
136
|
-
if (!Array.isArray(candidate)) {
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
return candidate
|
|
140
|
-
.map((entry) => normalizePersistedSubagentChildSummary(entry))
|
|
141
|
-
.filter((entry) => Boolean(entry));
|
|
142
|
-
}
|
|
143
|
-
return [];
|
|
144
|
-
}
|
|
145
|
-
export function runtimeSnapshotPath(stateDir, sessionId) {
|
|
146
|
-
return join(resolve(stateDir), RUNTIME_SNAPSHOT_DIR, `${sessionId}.json`);
|
|
147
|
-
}
|
|
148
|
-
export async function readJsonFile(filePath) {
|
|
149
|
-
return JSON.parse(await readFile(filePath, "utf8"));
|
|
150
|
-
}
|
|
151
|
-
export async function writeJsonFile(filePath, value) {
|
|
152
|
-
await mkdir(dirname(filePath), { recursive: true });
|
|
153
|
-
await writeFile(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
|
|
154
|
-
}
|
|
155
|
-
export async function safeLoadRuntimeSnapshot(input) {
|
|
156
|
-
const filePath = join(input.directory, `${input.sessionId}.json`);
|
|
157
|
-
try {
|
|
158
|
-
return await readJsonFile(filePath);
|
|
159
|
-
}
|
|
160
|
-
catch {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
export function getSkillsCatalogRoots(cwd) {
|
|
165
|
-
const home = String(process.env.HOME ?? "").trim();
|
|
166
|
-
const codeHome = String(process.env.CODEX_HOME ?? "").trim();
|
|
167
|
-
const roots = [
|
|
168
|
-
join(cwd, ".codex", "skills"),
|
|
169
|
-
join(cwd, ".agents", "skills"),
|
|
170
|
-
codeHome ? join(codeHome, "skills") : "",
|
|
171
|
-
home ? join(home, ".codex", "skills") : "",
|
|
172
|
-
home ? join(home, ".agents", "skills") : "",
|
|
173
|
-
].filter(Boolean);
|
|
174
|
-
return Array.from(new Set(roots));
|
|
175
|
-
}
|
|
176
|
-
export async function scanMultipleSkillsDirectories(roots) {
|
|
177
|
-
const { readdir, stat } = await import("node:fs/promises");
|
|
178
|
-
const skills = new Map();
|
|
179
|
-
async function scan(root) {
|
|
180
|
-
let entries;
|
|
181
|
-
try {
|
|
182
|
-
entries = await readdir(root, { withFileTypes: true });
|
|
183
|
-
}
|
|
184
|
-
catch {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
for (const entry of entries) {
|
|
188
|
-
if (!entry.isDirectory()) {
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
const skillDir = join(root, entry.name);
|
|
192
|
-
const skillFile = join(skillDir, "SKILL.md");
|
|
193
|
-
try {
|
|
194
|
-
const info = await stat(skillFile);
|
|
195
|
-
if (!info.isFile()) {
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
const content = await readFile(skillFile, "utf8");
|
|
199
|
-
const description = content
|
|
200
|
-
.split("\n")
|
|
201
|
-
.map((line) => line.trim())
|
|
202
|
-
.find((line) => line.length > 0 && !line.startsWith("#")) ?? entry.name;
|
|
203
|
-
skills.set(entry.name, { description, name: entry.name });
|
|
204
|
-
}
|
|
205
|
-
catch {
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
for (const root of roots) {
|
|
211
|
-
await scan(root);
|
|
212
|
-
}
|
|
213
|
-
return [...skills.values()].sort((left, right) => left.name.localeCompare(right.name));
|
|
214
|
-
}
|
|
215
|
-
//# sourceMappingURL=runtime-host.js.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare function debugLog(eventName: string, payload?: unknown): void;
|
|
2
|
-
/**
|
|
3
|
-
* Write a debug line into a per-session log file.
|
|
4
|
-
* The file is always **appended** — it is never cleared within a session.
|
|
5
|
-
* Files live under `logsDir()/<sessionId>.log`.
|
|
6
|
-
*/
|
|
7
|
-
export declare function debugLogSession(sessionId: string, eventName: string, payload?: unknown): void;
|
|
8
|
-
//# sourceMappingURL=debug-log.d.ts.map
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { appendFileSync, mkdirSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { readPrefixedEnv, readPrefixedEnvFlag } from './env.js';
|
|
4
|
-
function runtimeGlobals() {
|
|
5
|
-
return globalThis;
|
|
6
|
-
}
|
|
7
|
-
function isNodeLike() {
|
|
8
|
-
const p = runtimeGlobals().process;
|
|
9
|
-
return Boolean(p && typeof p?.versions?.node === 'string');
|
|
10
|
-
}
|
|
11
|
-
function isDebugEnabled() {
|
|
12
|
-
if (!isNodeLike())
|
|
13
|
-
return false;
|
|
14
|
-
const v = readPrefixedEnvFlag(undefined, 'DEBUG');
|
|
15
|
-
return v === '1' || v === 'true' || v === 'yes' || v === 'on';
|
|
16
|
-
}
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
// Directory helpers
|
|
19
|
-
// ---------------------------------------------------------------------------
|
|
20
|
-
const ensuredDirs = new Set();
|
|
21
|
-
function ensureDir(dir) {
|
|
22
|
-
if (ensuredDirs.has(dir))
|
|
23
|
-
return;
|
|
24
|
-
try {
|
|
25
|
-
mkdirSync(dir, { recursive: true });
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
// ignore
|
|
29
|
-
}
|
|
30
|
-
ensuredDirs.add(dir);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* All debug logs live under a single `logs/` directory.
|
|
34
|
-
* When `DIMCODE_DEBUG_LOG` is set the parent of that path is used instead.
|
|
35
|
-
*/
|
|
36
|
-
function logsDir() {
|
|
37
|
-
const raw = readPrefixedEnv(undefined, 'DEBUG_LOG');
|
|
38
|
-
if (raw)
|
|
39
|
-
return path.dirname(raw);
|
|
40
|
-
return './logs';
|
|
41
|
-
}
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
// Formatting / writing
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
function formatLine(eventName, payload) {
|
|
46
|
-
const name = String(eventName ?? '').trim() || 'event';
|
|
47
|
-
const timestamp = new Date().toISOString();
|
|
48
|
-
let line = `[${timestamp}] ${name}`;
|
|
49
|
-
if (payload !== undefined) {
|
|
50
|
-
try {
|
|
51
|
-
line += ` ${JSON.stringify(payload)}`;
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
// ignore
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return `${line}\n`;
|
|
58
|
-
}
|
|
59
|
-
function writeLine(filePath, line) {
|
|
60
|
-
try {
|
|
61
|
-
appendFileSync(filePath, line);
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// ignore
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// ---------------------------------------------------------------------------
|
|
68
|
-
// Global debug log
|
|
69
|
-
// ---------------------------------------------------------------------------
|
|
70
|
-
function debugLogPath() {
|
|
71
|
-
const raw = readPrefixedEnv(undefined, 'DEBUG_LOG');
|
|
72
|
-
if (raw)
|
|
73
|
-
return raw;
|
|
74
|
-
const dir = logsDir();
|
|
75
|
-
ensureDir(dir);
|
|
76
|
-
return path.join(dir, 'dimcode-debug.log');
|
|
77
|
-
}
|
|
78
|
-
export function debugLog(eventName, payload) {
|
|
79
|
-
if (!isDebugEnabled())
|
|
80
|
-
return;
|
|
81
|
-
writeLine(debugLogPath(), formatLine(eventName, payload));
|
|
82
|
-
}
|
|
83
|
-
// ---------------------------------------------------------------------------
|
|
84
|
-
// Per-session debug log (logs/<sessionId>.log)
|
|
85
|
-
// ---------------------------------------------------------------------------
|
|
86
|
-
/**
|
|
87
|
-
* Write a debug line into a per-session log file.
|
|
88
|
-
* The file is always **appended** — it is never cleared within a session.
|
|
89
|
-
* Files live under `logsDir()/<sessionId>.log`.
|
|
90
|
-
*/
|
|
91
|
-
export function debugLogSession(sessionId, eventName, payload) {
|
|
92
|
-
if (!isDebugEnabled())
|
|
93
|
-
return;
|
|
94
|
-
const dir = logsDir();
|
|
95
|
-
ensureDir(dir);
|
|
96
|
-
const sanitized = sessionId.replace(/[^\w-]/g, '_');
|
|
97
|
-
const filePath = path.join(dir, `${sanitized}.log`);
|
|
98
|
-
writeLine(filePath, formatLine(eventName, payload));
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=debug-log.js.map
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export type EnvRecord = Readonly<Record<string, string | undefined>>;
|
|
2
|
-
export declare const DIMCODE_ENV_PREFIX = "DIMCODE_";
|
|
3
|
-
export type EnvReader = Readonly<{
|
|
4
|
-
env: EnvRecord;
|
|
5
|
-
str: (key: string, ...aliases: string[]) => string;
|
|
6
|
-
strAny: (keys: readonly string[]) => string;
|
|
7
|
-
bool: (key: string, ...aliases: string[]) => boolean | undefined;
|
|
8
|
-
boolAny: (keys: readonly string[]) => boolean | undefined;
|
|
9
|
-
int: (key: string, ...aliases: string[]) => number | undefined;
|
|
10
|
-
intAny: (keys: readonly string[]) => number | undefined;
|
|
11
|
-
float: (key: string, ...aliases: string[]) => number | undefined;
|
|
12
|
-
floatAny: (keys: readonly string[]) => number | undefined;
|
|
13
|
-
prefixedStr: (name: string, ...aliases: string[]) => string;
|
|
14
|
-
prefixedBool: (name: string, ...aliases: string[]) => boolean | undefined;
|
|
15
|
-
prefixedInt: (name: string, ...aliases: string[]) => number | undefined;
|
|
16
|
-
prefixedFloat: (name: string, ...aliases: string[]) => number | undefined;
|
|
17
|
-
}>;
|
|
18
|
-
export declare function readProcessEnv(): EnvRecord;
|
|
19
|
-
export declare function resolveEnv(primary?: EnvRecord, fallback?: EnvRecord): EnvRecord;
|
|
20
|
-
export declare function prefixedEnvKeys(name: string): readonly [string];
|
|
21
|
-
export declare function createEnvReader(env?: EnvRecord, fallback?: EnvRecord): EnvReader;
|
|
22
|
-
export declare function readPrefixedEnv(env: EnvRecord | undefined, name: string): string;
|
|
23
|
-
export declare function readPrefixedEnvFlag(env: EnvRecord | undefined, name: string): string;
|
|
24
|
-
export declare function setPrefixedEnvValue(env: Record<string, string | undefined>, name: string, value: string | undefined): void;
|
|
25
|
-
export declare function ensurePrefixedEnvValue(env: Record<string, string | undefined>, name: string, fallback: string): string;
|
|
26
|
-
//# sourceMappingURL=env.d.ts.map
|