indusagi-coding-agent 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2249 -0
- package/README.md +546 -0
- package/dist/cli/args.js +282 -0
- package/dist/cli/config-selector.js +30 -0
- package/dist/cli/file-processor.js +78 -0
- package/dist/cli/list-models.js +91 -0
- package/dist/cli/session-picker.js +31 -0
- package/dist/cli.js +10 -0
- package/dist/config.js +158 -0
- package/dist/core/agent-session.js +2097 -0
- package/dist/core/auth-storage.js +278 -0
- package/dist/core/bash-executor.js +211 -0
- package/dist/core/compaction/branch-summarization.js +241 -0
- package/dist/core/compaction/compaction.js +606 -0
- package/dist/core/compaction/index.js +6 -0
- package/dist/core/compaction/utils.js +137 -0
- package/dist/core/diagnostics.js +1 -0
- package/dist/core/event-bus.js +24 -0
- package/dist/core/exec.js +70 -0
- package/dist/core/export-html/ansi-to-html.js +248 -0
- package/dist/core/export-html/index.js +221 -0
- package/dist/core/export-html/template.css +905 -0
- package/dist/core/export-html/template.html +54 -0
- package/dist/core/export-html/template.js +1549 -0
- package/dist/core/export-html/tool-renderer.js +56 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +6 -0
- package/dist/core/extensions/index.js +8 -0
- package/dist/core/extensions/loader.js +395 -0
- package/dist/core/extensions/runner.js +499 -0
- package/dist/core/extensions/types.js +31 -0
- package/dist/core/extensions/wrapper.js +101 -0
- package/dist/core/footer-data-provider.js +133 -0
- package/dist/core/index.js +8 -0
- package/dist/core/keybindings.js +140 -0
- package/dist/core/messages.js +122 -0
- package/dist/core/model-registry.js +454 -0
- package/dist/core/model-resolver.js +309 -0
- package/dist/core/package-manager.js +1142 -0
- package/dist/core/prompt-templates.js +250 -0
- package/dist/core/resource-loader.js +569 -0
- package/dist/core/sdk.js +225 -0
- package/dist/core/session-manager.js +1078 -0
- package/dist/core/settings-manager.js +430 -0
- package/dist/core/skills.js +339 -0
- package/dist/core/system-prompt.js +136 -0
- package/dist/core/timings.js +24 -0
- package/dist/core/tools/bash.js +226 -0
- package/dist/core/tools/edit-diff.js +242 -0
- package/dist/core/tools/edit.js +145 -0
- package/dist/core/tools/find.js +205 -0
- package/dist/core/tools/grep.js +238 -0
- package/dist/core/tools/index.js +60 -0
- package/dist/core/tools/ls.js +117 -0
- package/dist/core/tools/path-utils.js +52 -0
- package/dist/core/tools/read.js +165 -0
- package/dist/core/tools/truncate.js +204 -0
- package/dist/core/tools/write.js +77 -0
- package/dist/index.js +41 -0
- package/dist/main.js +565 -0
- package/dist/migrations.js +260 -0
- package/dist/modes/index.js +7 -0
- package/dist/modes/interactive/components/armin.js +328 -0
- package/dist/modes/interactive/components/assistant-message.js +86 -0
- package/dist/modes/interactive/components/bash-execution.js +155 -0
- package/dist/modes/interactive/components/bordered-loader.js +47 -0
- package/dist/modes/interactive/components/branch-summary-message.js +41 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +42 -0
- package/dist/modes/interactive/components/config-selector.js +458 -0
- package/dist/modes/interactive/components/countdown-timer.js +27 -0
- package/dist/modes/interactive/components/custom-editor.js +61 -0
- package/dist/modes/interactive/components/custom-message.js +80 -0
- package/dist/modes/interactive/components/diff.js +132 -0
- package/dist/modes/interactive/components/dynamic-border.js +19 -0
- package/dist/modes/interactive/components/extension-editor.js +96 -0
- package/dist/modes/interactive/components/extension-input.js +54 -0
- package/dist/modes/interactive/components/extension-selector.js +70 -0
- package/dist/modes/interactive/components/footer.js +213 -0
- package/dist/modes/interactive/components/index.js +31 -0
- package/dist/modes/interactive/components/keybinding-hints.js +60 -0
- package/dist/modes/interactive/components/login-dialog.js +138 -0
- package/dist/modes/interactive/components/model-selector.js +253 -0
- package/dist/modes/interactive/components/oauth-selector.js +91 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +262 -0
- package/dist/modes/interactive/components/session-selector-search.js +145 -0
- package/dist/modes/interactive/components/session-selector.js +698 -0
- package/dist/modes/interactive/components/settings-selector.js +250 -0
- package/dist/modes/interactive/components/show-images-selector.js +33 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +44 -0
- package/dist/modes/interactive/components/theme-selector.js +43 -0
- package/dist/modes/interactive/components/thinking-selector.js +45 -0
- package/dist/modes/interactive/components/tool-execution.js +608 -0
- package/dist/modes/interactive/components/tree-selector.js +892 -0
- package/dist/modes/interactive/components/user-message-selector.js +109 -0
- package/dist/modes/interactive/components/user-message.js +15 -0
- package/dist/modes/interactive/components/visual-truncate.js +32 -0
- package/dist/modes/interactive/interactive-mode.js +3576 -0
- package/dist/modes/interactive/theme/dark.json +85 -0
- package/dist/modes/interactive/theme/light.json +84 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.js +938 -0
- package/dist/modes/print-mode.js +96 -0
- package/dist/modes/rpc/rpc-client.js +390 -0
- package/dist/modes/rpc/rpc-mode.js +448 -0
- package/dist/modes/rpc/rpc-types.js +7 -0
- package/dist/utils/changelog.js +86 -0
- package/dist/utils/clipboard-image.js +116 -0
- package/dist/utils/clipboard.js +58 -0
- package/dist/utils/frontmatter.js +25 -0
- package/dist/utils/git.js +5 -0
- package/dist/utils/image-convert.js +34 -0
- package/dist/utils/image-resize.js +180 -0
- package/dist/utils/mime.js +25 -0
- package/dist/utils/photon.js +120 -0
- package/dist/utils/shell.js +164 -0
- package/dist/utils/sleep.js +16 -0
- package/dist/utils/tools-manager.js +186 -0
- package/docs/compaction.md +390 -0
- package/docs/custom-provider.md +538 -0
- package/docs/development.md +69 -0
- package/docs/extensions.md +1733 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/json.md +79 -0
- package/docs/keybindings.md +162 -0
- package/docs/models.md +193 -0
- package/docs/packages.md +163 -0
- package/docs/prompt-templates.md +67 -0
- package/docs/providers.md +147 -0
- package/docs/rpc.md +1048 -0
- package/docs/sdk.md +957 -0
- package/docs/session.md +412 -0
- package/docs/settings.md +216 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +226 -0
- package/docs/terminal-setup.md +65 -0
- package/docs/themes.md +295 -0
- package/docs/tree.md +219 -0
- package/docs/tui.md +887 -0
- package/docs/windows.md +17 -0
- package/examples/README.md +25 -0
- package/examples/extensions/README.md +192 -0
- package/examples/extensions/antigravity-image-gen.ts +414 -0
- package/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +115 -0
- package/examples/extensions/custom-footer.ts +65 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +605 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +350 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +83 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +133 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +105 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/handoff.ts +151 -0
- package/examples/extensions/hello.ts +25 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +60 -0
- package/examples/extensions/modal-editor.ts +86 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +25 -0
- package/examples/extensions/overlay-qa-tests.ts +882 -0
- package/examples/extensions/overlay-test.ts +151 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +65 -0
- package/examples/extensions/plan-mode/index.ts +341 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +399 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/qna.ts +120 -0
- package/examples/extensions/question.ts +265 -0
- package/examples/extensions/questionnaire.ts +428 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/sandbox/index.ts +318 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +344 -0
- package/examples/extensions/space-invaders.ts +561 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +40 -0
- package/examples/extensions/subagent/README.md +172 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +127 -0
- package/examples/extensions/subagent/index.ts +964 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +196 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/todo.ts +300 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +147 -0
- package/examples/extensions/trigger-compact.ts +40 -0
- package/examples/extensions/truncated-tool.ts +193 -0
- package/examples/extensions/widget-placement.ts +17 -0
- package/examples/extensions/with-deps/index.ts +36 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/sdk/01-minimal.ts +22 -0
- package/examples/sdk/02-custom-model.ts +50 -0
- package/examples/sdk/03-custom-prompt.ts +55 -0
- package/examples/sdk/04-skills.ts +46 -0
- package/examples/sdk/05-tools.ts +56 -0
- package/examples/sdk/06-extensions.ts +88 -0
- package/examples/sdk/07-context-files.ts +40 -0
- package/examples/sdk/08-prompt-templates.ts +47 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
- package/examples/sdk/10-settings.ts +38 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +82 -0
- package/examples/sdk/13-codex-oauth.ts +37 -0
- package/examples/sdk/README.md +144 -0
- package/package.json +85 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "fs";
|
|
2
|
+
import { homedir } from "os";
|
|
3
|
+
import { basename, dirname, isAbsolute, join, resolve, sep } from "path";
|
|
4
|
+
import { CONFIG_DIR_NAME, getAgentDir } from "../config.js";
|
|
5
|
+
import { parseFrontmatter } from "../utils/frontmatter.js";
|
|
6
|
+
/**
|
|
7
|
+
* Standard frontmatter fields per Agent Skills spec.
|
|
8
|
+
* See: https://agentskills.io/specification#frontmatter-required
|
|
9
|
+
*/
|
|
10
|
+
const ALLOWED_FRONTMATTER_FIELDS = new Set([
|
|
11
|
+
"name",
|
|
12
|
+
"description",
|
|
13
|
+
"license",
|
|
14
|
+
"compatibility",
|
|
15
|
+
"metadata",
|
|
16
|
+
"allowed-tools",
|
|
17
|
+
"disable-model-invocation",
|
|
18
|
+
]);
|
|
19
|
+
/** Max name length per spec */
|
|
20
|
+
const MAX_NAME_LENGTH = 64;
|
|
21
|
+
/** Max description length per spec */
|
|
22
|
+
const MAX_DESCRIPTION_LENGTH = 1024;
|
|
23
|
+
/**
|
|
24
|
+
* Validate skill name per Agent Skills spec.
|
|
25
|
+
* Returns array of validation error messages (empty if valid).
|
|
26
|
+
*/
|
|
27
|
+
function validateName(name, parentDirName) {
|
|
28
|
+
const errors = [];
|
|
29
|
+
if (name !== parentDirName) {
|
|
30
|
+
errors.push(`name "${name}" does not match parent directory "${parentDirName}"`);
|
|
31
|
+
}
|
|
32
|
+
if (name.length > MAX_NAME_LENGTH) {
|
|
33
|
+
errors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);
|
|
34
|
+
}
|
|
35
|
+
if (!/^[a-z0-9-]+$/.test(name)) {
|
|
36
|
+
errors.push(`name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)`);
|
|
37
|
+
}
|
|
38
|
+
if (name.startsWith("-") || name.endsWith("-")) {
|
|
39
|
+
errors.push(`name must not start or end with a hyphen`);
|
|
40
|
+
}
|
|
41
|
+
if (name.includes("--")) {
|
|
42
|
+
errors.push(`name must not contain consecutive hyphens`);
|
|
43
|
+
}
|
|
44
|
+
return errors;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validate description per Agent Skills spec.
|
|
48
|
+
*/
|
|
49
|
+
function validateDescription(description) {
|
|
50
|
+
const errors = [];
|
|
51
|
+
if (!description || description.trim() === "") {
|
|
52
|
+
errors.push("description is required");
|
|
53
|
+
}
|
|
54
|
+
else if (description.length > MAX_DESCRIPTION_LENGTH) {
|
|
55
|
+
errors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);
|
|
56
|
+
}
|
|
57
|
+
return errors;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check for unknown frontmatter fields.
|
|
61
|
+
*/
|
|
62
|
+
function validateFrontmatterFields(keys) {
|
|
63
|
+
const errors = [];
|
|
64
|
+
for (const key of keys) {
|
|
65
|
+
if (!ALLOWED_FRONTMATTER_FIELDS.has(key)) {
|
|
66
|
+
errors.push(`unknown frontmatter field "${key}"`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return errors;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Load skills from a directory.
|
|
73
|
+
*
|
|
74
|
+
* Discovery rules:
|
|
75
|
+
* - direct .md children in the root
|
|
76
|
+
* - recursive SKILL.md under subdirectories
|
|
77
|
+
*/
|
|
78
|
+
export function loadSkillsFromDir(options) {
|
|
79
|
+
const { dir, source } = options;
|
|
80
|
+
return loadSkillsFromDirInternal(dir, source, true);
|
|
81
|
+
}
|
|
82
|
+
function loadSkillsFromDirInternal(dir, source, includeRootFiles) {
|
|
83
|
+
const skills = [];
|
|
84
|
+
const diagnostics = [];
|
|
85
|
+
if (!existsSync(dir)) {
|
|
86
|
+
return { skills, diagnostics };
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
90
|
+
for (const entry of entries) {
|
|
91
|
+
if (entry.name.startsWith(".")) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
// Skip node_modules to avoid scanning dependencies
|
|
95
|
+
if (entry.name === "node_modules") {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const fullPath = join(dir, entry.name);
|
|
99
|
+
// For symlinks, check if they point to a directory and follow them
|
|
100
|
+
let isDirectory = entry.isDirectory();
|
|
101
|
+
let isFile = entry.isFile();
|
|
102
|
+
if (entry.isSymbolicLink()) {
|
|
103
|
+
try {
|
|
104
|
+
const stats = statSync(fullPath);
|
|
105
|
+
isDirectory = stats.isDirectory();
|
|
106
|
+
isFile = stats.isFile();
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// Broken symlink, skip it
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (isDirectory) {
|
|
114
|
+
const subResult = loadSkillsFromDirInternal(fullPath, source, false);
|
|
115
|
+
skills.push(...subResult.skills);
|
|
116
|
+
diagnostics.push(...subResult.diagnostics);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (!isFile) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const isRootMd = includeRootFiles && entry.name.endsWith(".md");
|
|
123
|
+
const isSkillMd = !includeRootFiles && entry.name === "SKILL.md";
|
|
124
|
+
if (!isRootMd && !isSkillMd) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const result = loadSkillFromFile(fullPath, source);
|
|
128
|
+
if (result.skill) {
|
|
129
|
+
skills.push(result.skill);
|
|
130
|
+
}
|
|
131
|
+
diagnostics.push(...result.diagnostics);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch { }
|
|
135
|
+
return { skills, diagnostics };
|
|
136
|
+
}
|
|
137
|
+
function loadSkillFromFile(filePath, source) {
|
|
138
|
+
const diagnostics = [];
|
|
139
|
+
try {
|
|
140
|
+
const rawContent = readFileSync(filePath, "utf-8");
|
|
141
|
+
const { frontmatter } = parseFrontmatter(rawContent);
|
|
142
|
+
const allKeys = Object.keys(frontmatter);
|
|
143
|
+
const skillDir = dirname(filePath);
|
|
144
|
+
const parentDirName = basename(skillDir);
|
|
145
|
+
// Validate frontmatter fields
|
|
146
|
+
const fieldErrors = validateFrontmatterFields(allKeys);
|
|
147
|
+
for (const error of fieldErrors) {
|
|
148
|
+
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
149
|
+
}
|
|
150
|
+
// Validate description
|
|
151
|
+
const descErrors = validateDescription(frontmatter.description);
|
|
152
|
+
for (const error of descErrors) {
|
|
153
|
+
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
154
|
+
}
|
|
155
|
+
// Use name from frontmatter, or fall back to parent directory name
|
|
156
|
+
const name = frontmatter.name || parentDirName;
|
|
157
|
+
// Validate name
|
|
158
|
+
const nameErrors = validateName(name, parentDirName);
|
|
159
|
+
for (const error of nameErrors) {
|
|
160
|
+
diagnostics.push({ type: "warning", message: error, path: filePath });
|
|
161
|
+
}
|
|
162
|
+
// Still load the skill even with warnings (unless description is completely missing)
|
|
163
|
+
if (!frontmatter.description || frontmatter.description.trim() === "") {
|
|
164
|
+
return { skill: null, diagnostics };
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
skill: {
|
|
168
|
+
name,
|
|
169
|
+
description: frontmatter.description,
|
|
170
|
+
filePath,
|
|
171
|
+
baseDir: skillDir,
|
|
172
|
+
source,
|
|
173
|
+
disableModelInvocation: frontmatter["disable-model-invocation"] === true,
|
|
174
|
+
},
|
|
175
|
+
diagnostics,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
const message = error instanceof Error ? error.message : "failed to parse skill file";
|
|
180
|
+
diagnostics.push({ type: "warning", message, path: filePath });
|
|
181
|
+
return { skill: null, diagnostics };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Format skills for inclusion in a system prompt.
|
|
186
|
+
* Uses XML format per Agent Skills standard.
|
|
187
|
+
* See: https://agentskills.io/integrate-skills
|
|
188
|
+
*
|
|
189
|
+
* Skills with disableModelInvocation=true are excluded from the prompt
|
|
190
|
+
* (they can only be invoked explicitly via /skill:name commands).
|
|
191
|
+
*/
|
|
192
|
+
export function formatSkillsForPrompt(skills) {
|
|
193
|
+
const visibleSkills = skills.filter((s) => !s.disableModelInvocation);
|
|
194
|
+
if (visibleSkills.length === 0) {
|
|
195
|
+
return "";
|
|
196
|
+
}
|
|
197
|
+
const lines = [
|
|
198
|
+
"\n\nThe following skills provide specialized instructions for specific tasks.",
|
|
199
|
+
"Use the read tool to load a skill's file when the task matches its description.",
|
|
200
|
+
"",
|
|
201
|
+
"<available_skills>",
|
|
202
|
+
];
|
|
203
|
+
for (const skill of visibleSkills) {
|
|
204
|
+
lines.push(" <skill>");
|
|
205
|
+
lines.push(` <name>${escapeXml(skill.name)}</name>`);
|
|
206
|
+
lines.push(` <description>${escapeXml(skill.description)}</description>`);
|
|
207
|
+
lines.push(` <location>${escapeXml(skill.filePath)}</location>`);
|
|
208
|
+
lines.push(" </skill>");
|
|
209
|
+
}
|
|
210
|
+
lines.push("</available_skills>");
|
|
211
|
+
return lines.join("\n");
|
|
212
|
+
}
|
|
213
|
+
function escapeXml(str) {
|
|
214
|
+
return str
|
|
215
|
+
.replace(/&/g, "&")
|
|
216
|
+
.replace(/</g, "<")
|
|
217
|
+
.replace(/>/g, ">")
|
|
218
|
+
.replace(/"/g, """)
|
|
219
|
+
.replace(/'/g, "'");
|
|
220
|
+
}
|
|
221
|
+
function normalizePath(input) {
|
|
222
|
+
const trimmed = input.trim();
|
|
223
|
+
if (trimmed === "~")
|
|
224
|
+
return homedir();
|
|
225
|
+
if (trimmed.startsWith("~/"))
|
|
226
|
+
return join(homedir(), trimmed.slice(2));
|
|
227
|
+
if (trimmed.startsWith("~"))
|
|
228
|
+
return join(homedir(), trimmed.slice(1));
|
|
229
|
+
return trimmed;
|
|
230
|
+
}
|
|
231
|
+
function resolveSkillPath(p, cwd) {
|
|
232
|
+
const normalized = normalizePath(p);
|
|
233
|
+
return isAbsolute(normalized) ? normalized : resolve(cwd, normalized);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Load skills from all configured locations.
|
|
237
|
+
* Returns skills and any validation diagnostics.
|
|
238
|
+
*/
|
|
239
|
+
export function loadSkills(options = {}) {
|
|
240
|
+
const { cwd = process.cwd(), agentDir, skillPaths = [], includeDefaults = true } = options;
|
|
241
|
+
// Resolve agentDir - if not provided, use default from config
|
|
242
|
+
const resolvedAgentDir = agentDir ?? getAgentDir();
|
|
243
|
+
const skillMap = new Map();
|
|
244
|
+
const realPathSet = new Set();
|
|
245
|
+
const allDiagnostics = [];
|
|
246
|
+
const collisionDiagnostics = [];
|
|
247
|
+
function addSkills(result) {
|
|
248
|
+
allDiagnostics.push(...result.diagnostics);
|
|
249
|
+
for (const skill of result.skills) {
|
|
250
|
+
// Resolve symlinks to detect duplicate files
|
|
251
|
+
let realPath;
|
|
252
|
+
try {
|
|
253
|
+
realPath = realpathSync(skill.filePath);
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
realPath = skill.filePath;
|
|
257
|
+
}
|
|
258
|
+
// Skip silently if we've already loaded this exact file (via symlink)
|
|
259
|
+
if (realPathSet.has(realPath)) {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const existing = skillMap.get(skill.name);
|
|
263
|
+
if (existing) {
|
|
264
|
+
collisionDiagnostics.push({
|
|
265
|
+
type: "collision",
|
|
266
|
+
message: `name "${skill.name}" collision`,
|
|
267
|
+
path: skill.filePath,
|
|
268
|
+
collision: {
|
|
269
|
+
resourceType: "skill",
|
|
270
|
+
name: skill.name,
|
|
271
|
+
winnerPath: existing.filePath,
|
|
272
|
+
loserPath: skill.filePath,
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
skillMap.set(skill.name, skill);
|
|
278
|
+
realPathSet.add(realPath);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (includeDefaults) {
|
|
283
|
+
addSkills(loadSkillsFromDirInternal(join(resolvedAgentDir, "skills"), "user", true));
|
|
284
|
+
addSkills(loadSkillsFromDirInternal(resolve(cwd, CONFIG_DIR_NAME, "skills"), "project", true));
|
|
285
|
+
}
|
|
286
|
+
const userSkillsDir = join(resolvedAgentDir, "skills");
|
|
287
|
+
const projectSkillsDir = resolve(cwd, CONFIG_DIR_NAME, "skills");
|
|
288
|
+
const isUnderPath = (target, root) => {
|
|
289
|
+
const normalizedRoot = resolve(root);
|
|
290
|
+
if (target === normalizedRoot) {
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
const prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;
|
|
294
|
+
return target.startsWith(prefix);
|
|
295
|
+
};
|
|
296
|
+
const getSource = (resolvedPath) => {
|
|
297
|
+
if (!includeDefaults) {
|
|
298
|
+
if (isUnderPath(resolvedPath, userSkillsDir))
|
|
299
|
+
return "user";
|
|
300
|
+
if (isUnderPath(resolvedPath, projectSkillsDir))
|
|
301
|
+
return "project";
|
|
302
|
+
}
|
|
303
|
+
return "path";
|
|
304
|
+
};
|
|
305
|
+
for (const rawPath of skillPaths) {
|
|
306
|
+
const resolvedPath = resolveSkillPath(rawPath, cwd);
|
|
307
|
+
if (!existsSync(resolvedPath)) {
|
|
308
|
+
allDiagnostics.push({ type: "warning", message: "skill path does not exist", path: resolvedPath });
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
try {
|
|
312
|
+
const stats = statSync(resolvedPath);
|
|
313
|
+
const source = getSource(resolvedPath);
|
|
314
|
+
if (stats.isDirectory()) {
|
|
315
|
+
addSkills(loadSkillsFromDirInternal(resolvedPath, source, true));
|
|
316
|
+
}
|
|
317
|
+
else if (stats.isFile() && resolvedPath.endsWith(".md")) {
|
|
318
|
+
const result = loadSkillFromFile(resolvedPath, source);
|
|
319
|
+
if (result.skill) {
|
|
320
|
+
addSkills({ skills: [result.skill], diagnostics: result.diagnostics });
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
allDiagnostics.push(...result.diagnostics);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
allDiagnostics.push({ type: "warning", message: "skill path is not a markdown file", path: resolvedPath });
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
const message = error instanceof Error ? error.message : "failed to read skill path";
|
|
332
|
+
allDiagnostics.push({ type: "warning", message, path: resolvedPath });
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
skills: Array.from(skillMap.values()),
|
|
337
|
+
diagnostics: [...allDiagnostics, ...collisionDiagnostics],
|
|
338
|
+
};
|
|
339
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System prompt construction and project context loading
|
|
3
|
+
*/
|
|
4
|
+
import { getDocsPath, getExamplesPath, getReadmePath } from "../config.js";
|
|
5
|
+
import { formatSkillsForPrompt } from "./skills.js";
|
|
6
|
+
/** Tool descriptions for system prompt */
|
|
7
|
+
const toolDescriptions = {
|
|
8
|
+
read: "Read file contents",
|
|
9
|
+
bash: "Execute bash commands (ls, grep, find, etc.)",
|
|
10
|
+
edit: "Make surgical edits to files (find exact text and replace)",
|
|
11
|
+
write: "Create or overwrite files",
|
|
12
|
+
grep: "Search file contents for patterns (respects .gitignore)",
|
|
13
|
+
find: "Find files by glob pattern (respects .gitignore)",
|
|
14
|
+
ls: "List directory contents",
|
|
15
|
+
};
|
|
16
|
+
/** Build the system prompt with tools, guidelines, and context */
|
|
17
|
+
export function buildSystemPrompt(options = {}) {
|
|
18
|
+
const { customPrompt, selectedTools, appendSystemPrompt, cwd, contextFiles: providedContextFiles, skills: providedSkills, } = options;
|
|
19
|
+
const resolvedCwd = cwd ?? process.cwd();
|
|
20
|
+
const now = new Date();
|
|
21
|
+
const dateTime = now.toLocaleString("en-US", {
|
|
22
|
+
weekday: "long",
|
|
23
|
+
year: "numeric",
|
|
24
|
+
month: "long",
|
|
25
|
+
day: "numeric",
|
|
26
|
+
hour: "2-digit",
|
|
27
|
+
minute: "2-digit",
|
|
28
|
+
second: "2-digit",
|
|
29
|
+
timeZoneName: "short",
|
|
30
|
+
});
|
|
31
|
+
const appendSection = appendSystemPrompt ? `\n\n${appendSystemPrompt}` : "";
|
|
32
|
+
const contextFiles = providedContextFiles ?? [];
|
|
33
|
+
const skills = providedSkills ?? [];
|
|
34
|
+
if (customPrompt) {
|
|
35
|
+
let prompt = customPrompt;
|
|
36
|
+
if (appendSection) {
|
|
37
|
+
prompt += appendSection;
|
|
38
|
+
}
|
|
39
|
+
// Append project context files
|
|
40
|
+
if (contextFiles.length > 0) {
|
|
41
|
+
prompt += "\n\n# Project Context\n\n";
|
|
42
|
+
prompt += "Project-specific instructions and guidelines:\n\n";
|
|
43
|
+
for (const { path: filePath, content } of contextFiles) {
|
|
44
|
+
prompt += `## ${filePath}\n\n${content}\n\n`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Append skills section (only if read tool is available)
|
|
48
|
+
const customPromptHasRead = !selectedTools || selectedTools.includes("read");
|
|
49
|
+
if (customPromptHasRead && skills.length > 0) {
|
|
50
|
+
prompt += formatSkillsForPrompt(skills);
|
|
51
|
+
}
|
|
52
|
+
// Add date/time and working directory last
|
|
53
|
+
prompt += `\nCurrent date and time: ${dateTime}`;
|
|
54
|
+
prompt += `\nCurrent working directory: ${resolvedCwd}`;
|
|
55
|
+
return prompt;
|
|
56
|
+
}
|
|
57
|
+
// Get absolute paths to documentation and examples
|
|
58
|
+
const readmePath = getReadmePath();
|
|
59
|
+
const docsPath = getDocsPath();
|
|
60
|
+
const examplesPath = getExamplesPath();
|
|
61
|
+
// Build tools list based on selected tools (only built-in tools with known descriptions)
|
|
62
|
+
const tools = (selectedTools || ["read", "bash", "edit", "write"]).filter((t) => t in toolDescriptions);
|
|
63
|
+
const toolsList = tools.length > 0 ? tools.map((t) => `- ${t}: ${toolDescriptions[t]}`).join("\n") : "(none)";
|
|
64
|
+
// Build guidelines based on which tools are actually available
|
|
65
|
+
const guidelinesList = [];
|
|
66
|
+
const hasBash = tools.includes("bash");
|
|
67
|
+
const hasEdit = tools.includes("edit");
|
|
68
|
+
const hasWrite = tools.includes("write");
|
|
69
|
+
const hasGrep = tools.includes("grep");
|
|
70
|
+
const hasFind = tools.includes("find");
|
|
71
|
+
const hasLs = tools.includes("ls");
|
|
72
|
+
const hasRead = tools.includes("read");
|
|
73
|
+
// File exploration guidelines
|
|
74
|
+
if (hasBash && !hasGrep && !hasFind && !hasLs) {
|
|
75
|
+
guidelinesList.push("Use bash for file operations like ls, rg, find");
|
|
76
|
+
}
|
|
77
|
+
else if (hasBash && (hasGrep || hasFind || hasLs)) {
|
|
78
|
+
guidelinesList.push("Prefer grep/find/ls tools over bash for file exploration (faster, respects .gitignore)");
|
|
79
|
+
}
|
|
80
|
+
// Read before edit guideline
|
|
81
|
+
if (hasRead && hasEdit) {
|
|
82
|
+
guidelinesList.push("Use read to examine files before editing. You must use this tool instead of cat or sed.");
|
|
83
|
+
}
|
|
84
|
+
// Edit guideline
|
|
85
|
+
if (hasEdit) {
|
|
86
|
+
guidelinesList.push("Use edit for precise changes (old text must match exactly)");
|
|
87
|
+
}
|
|
88
|
+
// Write guideline
|
|
89
|
+
if (hasWrite) {
|
|
90
|
+
guidelinesList.push("Use write only for new files or complete rewrites");
|
|
91
|
+
}
|
|
92
|
+
// Output guideline (only when actually writing or executing)
|
|
93
|
+
if (hasEdit || hasWrite) {
|
|
94
|
+
guidelinesList.push("When summarizing your actions, output plain text directly - do NOT use cat or bash to display what you did");
|
|
95
|
+
}
|
|
96
|
+
// Always include these
|
|
97
|
+
guidelinesList.push("Be concise in your responses");
|
|
98
|
+
guidelinesList.push("Show file paths clearly when working with files");
|
|
99
|
+
const guidelines = guidelinesList.map((g) => `- ${g}`).join("\n");
|
|
100
|
+
let prompt = `You are an expert coding assistant operating inside indusagi, a coding agent harness. You help users by reading files, executing commands, editing code, and writing new files.
|
|
101
|
+
|
|
102
|
+
Available tools:
|
|
103
|
+
${toolsList}
|
|
104
|
+
|
|
105
|
+
In addition to the tools above, you may have access to other custom tools depending on the project.
|
|
106
|
+
|
|
107
|
+
Guidelines:
|
|
108
|
+
${guidelines}
|
|
109
|
+
|
|
110
|
+
Indusagi documentation (read only when the user asks about indusagi itself, its SDK, extensions, themes, skills, or TUI):
|
|
111
|
+
- Main documentation: ${readmePath}
|
|
112
|
+
- Additional docs: ${docsPath}
|
|
113
|
+
- Examples: ${examplesPath} (extensions, custom tools, SDK)
|
|
114
|
+
- When asked about: extensions (docs/extensions.md, examples/extensions/), themes (docs/themes.md), skills (docs/skills.md), prompt templates (docs/prompt-templates.md), TUI components (docs/tui.md), keybindings (docs/keybindings.md), SDK integrations (docs/sdk.md), custom providers (docs/custom-provider.md), adding models (docs/models.md), indusagi packages (docs/packages.md)
|
|
115
|
+
- When working on indusagi topics, read the docs and examples, and follow .md cross-references before implementing
|
|
116
|
+
- Always read indusagi .md files completely and follow links to related docs (e.g., tui.md for TUI API details)`;
|
|
117
|
+
if (appendSection) {
|
|
118
|
+
prompt += appendSection;
|
|
119
|
+
}
|
|
120
|
+
// Append project context files
|
|
121
|
+
if (contextFiles.length > 0) {
|
|
122
|
+
prompt += "\n\n# Project Context\n\n";
|
|
123
|
+
prompt += "Project-specific instructions and guidelines:\n\n";
|
|
124
|
+
for (const { path: filePath, content } of contextFiles) {
|
|
125
|
+
prompt += `## ${filePath}\n\n${content}\n\n`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Append skills section (only if read tool is available)
|
|
129
|
+
if (hasRead && skills.length > 0) {
|
|
130
|
+
prompt += formatSkillsForPrompt(skills);
|
|
131
|
+
}
|
|
132
|
+
// Add date/time and working directory last
|
|
133
|
+
prompt += `\nCurrent date and time: ${dateTime}`;
|
|
134
|
+
prompt += `\nCurrent working directory: ${resolvedCwd}`;
|
|
135
|
+
return prompt;
|
|
136
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central timing instrumentation for startup profiling.
|
|
3
|
+
* Enable with INDUSAGI_TIMING=1 environment variable.
|
|
4
|
+
*/
|
|
5
|
+
const ENABLED = process.env.INDUSAGI_TIMING === "1";
|
|
6
|
+
const timings = [];
|
|
7
|
+
let lastTime = Date.now();
|
|
8
|
+
export function time(label) {
|
|
9
|
+
if (!ENABLED)
|
|
10
|
+
return;
|
|
11
|
+
const now = Date.now();
|
|
12
|
+
timings.push({ label, ms: now - lastTime });
|
|
13
|
+
lastTime = now;
|
|
14
|
+
}
|
|
15
|
+
export function printTimings() {
|
|
16
|
+
if (!ENABLED || timings.length === 0)
|
|
17
|
+
return;
|
|
18
|
+
console.error("\n--- Startup Timings ---");
|
|
19
|
+
for (const t of timings) {
|
|
20
|
+
console.error(` ${t.label}: ${t.ms}ms`);
|
|
21
|
+
}
|
|
22
|
+
console.error(` TOTAL: ${timings.reduce((a, b) => a + b.ms, 0)}ms`);
|
|
23
|
+
console.error("------------------------\n");
|
|
24
|
+
}
|