@dimassetoid/septum-mcp 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +124 -2
- package/bin/septum.ts +4 -0
- package/package.json +70 -4
- package/scripts/postinstall.ts +25 -0
- package/src/cli/commands/check.ts +122 -0
- package/src/cli/commands/hook.ts +268 -0
- package/src/cli/commands/init.ts +553 -0
- package/src/cli/commands/serve.ts +5 -0
- package/src/cli/commands/sync.ts +41 -0
- package/src/cli/commands/topology.ts +161 -0
- package/src/cli/index.ts +167 -0
- package/src/cli/scaffold/harness-config.ts +621 -0
- package/src/cli/templates/hooks.ts +75 -0
- package/src/cli/templates/rules.ts +50 -0
- package/src/cli/templates/skill.ts +51 -0
- package/src/cli/ui/prompts.ts +122 -0
- package/src/core/boundary/evaluator.ts +442 -0
- package/src/core/boundary/staged-auditor.ts +58 -0
- package/src/core/config/loader.ts +122 -0
- package/src/core/config/schema.ts +69 -0
- package/src/core/database/client.ts +60 -0
- package/src/core/database/repositories/dependency.repository.ts +712 -0
- package/src/core/database/repositories/domain.repository.ts +330 -0
- package/src/core/database/repositories/environment.repository.ts +207 -0
- package/src/core/database/repositories/file.repository.ts +117 -0
- package/src/core/database/repositories/meta.repository.ts +33 -0
- package/src/core/database/repositories/symbol.repository.ts +508 -0
- package/src/core/database/repository.ts +303 -0
- package/src/core/database/schema.ts +154 -0
- package/src/core/discovery/topology-detector.ts +805 -0
- package/src/core/ingestion/hasher.ts +5 -0
- package/src/core/ingestion/pipeline.ts +623 -0
- package/src/core/parser/behavioral-analyzer.ts +119 -0
- package/src/core/parser/boundary-tracker.ts +443 -0
- package/src/core/parser/extractors/base.ts +67 -0
- package/src/core/parser/extractors/blade.ts +159 -0
- package/src/core/parser/extractors/csharp.ts +244 -0
- package/src/core/parser/extractors/django-semantic.ts +687 -0
- package/src/core/parser/extractors/elysia-semantic.ts +538 -0
- package/src/core/parser/extractors/express-semantic.ts +444 -0
- package/src/core/parser/extractors/fastapi-semantic.ts +736 -0
- package/src/core/parser/extractors/fastify-semantic.ts +774 -0
- package/src/core/parser/extractors/flask-semantic.ts +515 -0
- package/src/core/parser/extractors/frontend.ts +149 -0
- package/src/core/parser/extractors/go-semantic.ts +611 -0
- package/src/core/parser/extractors/go.ts +491 -0
- package/src/core/parser/extractors/hono-semantic.ts +567 -0
- package/src/core/parser/extractors/java.ts +225 -0
- package/src/core/parser/extractors/laravel-semantic.ts +1122 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +368 -0
- package/src/core/parser/extractors/nestjs-semantic.ts +543 -0
- package/src/core/parser/extractors/php.ts +569 -0
- package/src/core/parser/extractors/python.ts +498 -0
- package/src/core/parser/extractors/registry.ts +78 -0
- package/src/core/parser/extractors/ruby.ts +234 -0
- package/src/core/parser/extractors/rust.ts +286 -0
- package/src/core/parser/extractors/semantic-extractor.interface.ts +22 -0
- package/src/core/parser/extractors/symfony-semantic.ts +354 -0
- package/src/core/parser/extractors/typescript.ts +826 -0
- package/src/core/parser/language-capabilities.ts +71 -0
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +216 -0
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +90 -0
- package/src/core/parser/schema/schema-provider-registry.ts +43 -0
- package/src/core/parser/schema/schema-provider.interface.ts +33 -0
- package/src/core/parser/tree-sitter.ts +63 -0
- package/src/core/parser/wasm-assets.ts +25 -0
- package/src/core/parser/wasm-loader.ts +274 -0
- package/src/core/resolver/call-graph-tracer.ts +724 -0
- package/src/core/resolver/import-resolver.ts +437 -0
- package/src/core/resolver/module-resolver.ts +482 -0
- package/src/core/resolver/path-resolver.ts +200 -0
- package/src/core/resolver/symbol-locator.ts +276 -0
- package/src/core/resolver/symbol-reference.ts +53 -0
- package/src/core/resolver/vertical-slice-tracer.ts +366 -0
- package/src/core/resources/ignore.ts +123 -0
- package/src/core/resources/limits.ts +14 -0
- package/src/core/resources/source-files.ts +62 -0
- package/src/core/resources/work-queue.ts +74 -0
- package/src/core/session/session-manager.ts +107 -0
- package/src/core/telemetry/telemetry.ts +97 -0
- package/src/core/topology/environment-detector.ts +973 -0
- package/src/core/topology/types.ts +83 -0
- package/src/index.ts +21 -0
- package/src/mcp/schemas.ts +1105 -0
- package/src/mcp/server.ts +774 -0
- package/src/mcp/tools/boundary.ts +17 -0
- package/src/mcp/tools/check-boundary.ts +387 -0
- package/src/mcp/tools/domain.ts +40 -0
- package/src/mcp/tools/feature.ts +67 -0
- package/src/mcp/tools/get-domain-catalog.ts +226 -0
- package/src/mcp/tools/get-environment-topology.ts +138 -0
- package/src/mcp/tools/get-feature-context.ts +224 -0
- package/src/mcp/tools/get-symbol-hotspots.ts +54 -0
- package/src/mcp/tools/get-symbol-impact.ts +64 -0
- package/src/mcp/tools/get-symbol.ts +175 -0
- package/src/mcp/tools/locate-symbol.ts +196 -0
- package/src/mcp/tools/register-domain.ts +75 -0
- package/src/mcp/tools/register-feature.ts +110 -0
- package/src/mcp/tools/slice.ts +16 -0
- package/src/mcp/tools/symbol.ts +93 -0
- package/src/mcp/tools/trace-vertical-slice.ts +80 -0
- package/src/mcp/workspace-manager.ts +159 -0
- package/src/mcp/workspace-watcher.ts +202 -0
- package/src/types/index.ts +456 -0
- package/src/types/wasm.d.ts +4 -0
- package/src/utils/version-check.ts +209 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export const SEPTUM_HOOKS_CONFIG = {
|
|
2
|
+
"septum-boundary-guard": {
|
|
3
|
+
"PreToolUse": [
|
|
4
|
+
{
|
|
5
|
+
"matcher": "write_to_file|replace_file_content|multi_replace_file_content|Write|Edit|MultiEdit",
|
|
6
|
+
"hooks": [
|
|
7
|
+
{
|
|
8
|
+
"type": "command",
|
|
9
|
+
"command": "sh -c 'ROOT=\"$(pwd -P)\"; for d in .gemini .claude .codex opencode .agents; do if [ -f \"$ROOT/$d/hooks/septum-pre-write.sh\" ]; then exec \"$ROOT/$d/hooks/septum-pre-write.sh\" \"$@\"; fi; done; exit 0'",
|
|
10
|
+
"timeout": 10,
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
"PostToolUse": [
|
|
16
|
+
{
|
|
17
|
+
"matcher": "write_to_file|replace_file_content|multi_replace_file_content|Write|Edit|MultiEdit",
|
|
18
|
+
"hooks": [
|
|
19
|
+
{
|
|
20
|
+
"type": "command",
|
|
21
|
+
"command": "sh -c 'ROOT=\"$(pwd -P)\"; for d in .gemini .claude .codex opencode .agents; do if [ -f \"$ROOT/$d/hooks/septum-post-write.sh\" ]; then exec \"$ROOT/$d/hooks/septum-post-write.sh\" \"$@\"; fi; done; exit 0'",
|
|
22
|
+
"timeout": 15,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const SEPTUM_PRE_WRITE_SCRIPT = `#!/usr/bin/env sh
|
|
31
|
+
# Septum 3-Gate Boundary Guard Pre-Write Hook
|
|
32
|
+
# Intercepts write_to_file and replace_file_content before disk mutation
|
|
33
|
+
|
|
34
|
+
ROOT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd -P)"
|
|
35
|
+
if [ ! -f "$ROOT_DIR/.septum/septum.db" ]; then
|
|
36
|
+
exit 0
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
# Delegate directly to Septum's active 3-gate hook engine
|
|
40
|
+
if command -v bun >/dev/null 2>&1 && [ -f "$ROOT_DIR/bin/septum.ts" ]; then
|
|
41
|
+
exec bun run "$ROOT_DIR/bin/septum.ts" hook pre-write "$@"
|
|
42
|
+
elif command -v septum >/dev/null 2>&1; then
|
|
43
|
+
exec septum hook pre-write "$@"
|
|
44
|
+
elif [ -f "$ROOT_DIR/node_modules/.bin/septum" ]; then
|
|
45
|
+
exec "$ROOT_DIR/node_modules/.bin/septum" hook pre-write "$@"
|
|
46
|
+
elif command -v bunx >/dev/null 2>&1; then
|
|
47
|
+
exec bunx septum hook pre-write "$@"
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
exit 0
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
export const SEPTUM_POST_WRITE_SCRIPT = `#!/usr/bin/env sh
|
|
54
|
+
# Septum Automated Incremental Post-Write Hook
|
|
55
|
+
# Syncs modified AST into SQLite SSOT after file mutations
|
|
56
|
+
|
|
57
|
+
ROOT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd -P)"
|
|
58
|
+
if [ ! -f "$ROOT_DIR/.septum/septum.db" ]; then
|
|
59
|
+
exit 0
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
# Trigger background incremental sync
|
|
63
|
+
if command -v bun >/dev/null 2>&1 && [ -f "$ROOT_DIR/bin/septum.ts" ]; then
|
|
64
|
+
bun run "$ROOT_DIR/bin/septum.ts" sync >/dev/null 2>&1 &
|
|
65
|
+
elif command -v septum >/dev/null 2>&1; then
|
|
66
|
+
septum sync >/dev/null 2>&1 &
|
|
67
|
+
elif [ -f "$ROOT_DIR/node_modules/.bin/septum" ]; then
|
|
68
|
+
"$ROOT_DIR/node_modules/.bin/septum" sync >/dev/null 2>&1 &
|
|
69
|
+
elif command -v bunx >/dev/null 2>&1; then
|
|
70
|
+
bunx septum sync >/dev/null 2>&1 &
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
exit 0
|
|
74
|
+
`;
|
|
75
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const SEPTUM_RULES_TEMPLATE = `# Software Architecture, Modular Boundaries & Symbol Reuse Guidelines
|
|
2
|
+
|
|
3
|
+
> **Core Principle:** This codebase enforces modular architecture and the DRY (Don't Repeat Yourself) principle. An embedded database (\`.septum/septum.db\`) maintains the Single Source of Truth (SSOT) for the project symbol table, call graph, and dependency graph. Code modifications must respect module boundaries and reuse existing abstractions.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Symbol Reuse & Module Discovery (Before Writing New Code)
|
|
8
|
+
|
|
9
|
+
Before declaring a new class, interface, function, method, or shared type:
|
|
10
|
+
1. **Inspect Module Catalog & File Dependencies:**
|
|
11
|
+
Call \`septum_domain({ action: "catalog", domain: "<domain_name>", detail_level: "compact" })\` (or omit \`domain\` for the top-level architecture overview).
|
|
12
|
+
* Review existing declarations (\`class\`, \`interface\`, \`struct\`, \`function\`, \`type\`, \`constant\`, \`variable\`) and their line span.
|
|
13
|
+
* Review imported modules (\`connections.imports_from\`) and consumer count (\`connections.imported_by_count\`).
|
|
14
|
+
* For complete method signatures of a specific component, call \`septum_symbol({ action: "inspect", query: "<SymbolName>" })\`.
|
|
15
|
+
2. **Search for Existing Utilities and Abstractions:**
|
|
16
|
+
Call \`septum_symbol({ action: "locate", query: "<keyword>" })\` to verify whether a utility, service, or helper already exists before implementing duplicate logic.
|
|
17
|
+
3. **Scope Constraints for Features:**
|
|
18
|
+
When working within an assigned feature branch or task, call \`septum_feature({ action: "get", feature_key: "<feature_name>" })\`:
|
|
19
|
+
* **Respect \`allowed_touchpoints\`:** Restrict modifications strictly to files within the designated module scope.
|
|
20
|
+
* **Reuse \`reuse_symbols\`:** Import and extend registered components from \`reuse_symbols\` instead of re-implementing them.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 2. Impact Analysis & Breaking Change Prevention (Before Refactoring)
|
|
25
|
+
|
|
26
|
+
1. **Analyze Call Graph Dependencies (\`inbound_callers\`):**
|
|
27
|
+
Before altering method signatures, changing parameter contracts, or deprecating public symbols, check all dependents:
|
|
28
|
+
\`\`\`json
|
|
29
|
+
septum_symbol({ "action": "impact", "query": "ClassNameOrFunction" })
|
|
30
|
+
\`\`\`
|
|
31
|
+
Review all \`inbound_callers\` (direct callers and cross-module named imports) to prevent breaking upstream consumers.
|
|
32
|
+
2. **Trace End-to-End Execution Flow (Vertical Slices):**
|
|
33
|
+
Call \`septum_slice({ query: "<route|command|handler>", max_depth: 5 })\` (scale up to \`max_depth: 8\` for asynchronous events, message queues, or layered middleware) to trace call chains from API ingress down to data persistence.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 3. Dependency Validation & Static Boundary Checks
|
|
38
|
+
|
|
39
|
+
1. **Pre-Validate Proposed Module Imports:**
|
|
40
|
+
Before adding new cross-module dependencies, validate whether the dependency direction conforms to the architecture:
|
|
41
|
+
\`\`\`json
|
|
42
|
+
septum_boundary({
|
|
43
|
+
"file_path": "src/modules/order/service.ts",
|
|
44
|
+
"proposed_imports": ["../billing/service"],
|
|
45
|
+
"feature_key": "optional_feature_key"
|
|
46
|
+
})
|
|
47
|
+
\`\`\`
|
|
48
|
+
2. **Verify Against Circular Dependencies and Boundary Leaks:**
|
|
49
|
+
Run \`septum_boundary({ scope: "staged" })\` or \`septum_boundary({ scope: "all" })\` prior to committing changes. If the check returns \`rejected\` (due to \`forbidden_dependency\`, \`disallowed_dependency\`, \`touchpoint_violation\`, or \`circular_dependency\`), refactor the import hierarchy to preserve clean dependency inversion.
|
|
50
|
+
`;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const SEPTUM_MAP_SKILL_TEMPLATE = `---
|
|
2
|
+
name: septum-map
|
|
3
|
+
description: Framework-agnostic codebase architecture and dependency graph analysis. Use when initializing project boundaries, inspecting the symbol table, validating cross-module imports, or reviewing static analysis check results.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# \`septum-map\` — Codebase Architecture & Static Analysis
|
|
7
|
+
|
|
8
|
+
> **Core Principle:** Static analysis indexes AST declarations and dependency graphs to provide deterministic structural evidence. Treat index data as static structural facts, not full runtime trace validation.
|
|
9
|
+
|
|
10
|
+
## Scope
|
|
11
|
+
|
|
12
|
+
Use this skill to navigate the project architecture, verify module boundaries, locate reusable symbols, trace execution flows, and validate dependency rules. This skill guides architectural compliance; domain business decisions remain governed by project specifications.
|
|
13
|
+
|
|
14
|
+
## Tool & Command Reference
|
|
15
|
+
|
|
16
|
+
The active MCP schema and \`septum --help\` represent the authoritative interface contracts:
|
|
17
|
+
|
|
18
|
+
| Tool | Capability | Considerations |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| \`septum_domain\` | \`catalog\` inspects module architecture (supports \`detail_level: "compact"\`); \`register\` defines domain roots; \`topology\` logs infrastructure layers. | Domain registration mutates database state. Directory structures serve as modular hints. |
|
|
21
|
+
| \`septum_symbol\` | \`locate\`, \`inspect\`, \`impact\`, or \`hotspots\` across the project symbol table. | Backed by Tree-Sitter AST parsers. Impact analysis reports static inbound callers across the dependency graph. |
|
|
22
|
+
| \`septum_slice\` | Traces end-to-end execution paths from ingress handlers down through services and repositories; \`max_depth\` bounds call graph traversal. | Returns matched call graph chains; confidence metrics reflect static AST resolution depth. |
|
|
23
|
+
| \`septum_boundary\` | Validates proposed imports and detects \`circular_dependency\` cycles across scopes (\`file\`, \`staged\`, \`domain\`, \`all\`). | Evaluates allowed/forbidden dependency rules. Status \`approved\` confirms zero policy violations in the checked scope. |
|
|
24
|
+
| \`septum_feature\` | \`get\` retrieves active task context; \`lock\` registers task touchpoints; \`release\` clears locks. | Restricts edits to authorized module touchpoints during concurrent development sessions. |
|
|
25
|
+
|
|
26
|
+
Common CLI commands: \`septum init\` initializes project configuration and agent hooks; \`septum sync\` updates the AST index; \`septum check\` runs static boundary checks on staged or workspace files.
|
|
27
|
+
|
|
28
|
+
## Architectural Review Workflow
|
|
29
|
+
|
|
30
|
+
1. **Verify Project Context:** Ensure working directory is aligned. Check that \`.septum/septum.db\` is present. Pass \`workspace_path\` when operating in multi-root workspaces.
|
|
31
|
+
2. **Inspect Module Inventory:** Query the domain catalog to determine registered modules, AST index status, and file coverage metrics. If files are marked unsupported or skipped, note partial coverage.
|
|
32
|
+
3. **Differentiate Evidence from Assumptions:** Use concrete AST symbols, public exports, and declared configuration as evidence. Never guess interfaces or assume unverified dependencies.
|
|
33
|
+
4. **Identify Reusable Components:** Search existing services, models, and utility classes before introducing new declarations to adhere to the DRY principle.
|
|
34
|
+
5. **Analyze Refactoring Blast Radius:** Check inbound callers (\`septum_symbol impact\`) before modifying public method signatures or removing exported declarations.
|
|
35
|
+
6. **Validate Dependency Boundaries:** Run pre-commit checks (\`septum_boundary\`) to ensure proposed imports avoid circular dependencies and respect architectural layering.
|
|
36
|
+
|
|
37
|
+
## Interpreting Analysis Results
|
|
38
|
+
|
|
39
|
+
- \`approved\`: No architectural violations or circular dependencies detected within the evaluated scope.
|
|
40
|
+
- \`rejected\`: A boundary violation (\`forbidden_dependency\`, \`disallowed_dependency\`, or \`circular_dependency\`) occurred. The import hierarchy must be refactored.
|
|
41
|
+
- \`unknown\` or partial index status: Indexing is incomplete; review unsupported files before concluding compliance.
|
|
42
|
+
- Absence of a symbol: Indicates no match in the current AST index, signaling an opportunity to implement or check naming spelling.
|
|
43
|
+
|
|
44
|
+
## Standardized Reporting Format
|
|
45
|
+
|
|
46
|
+
When summarizing architectural checks:
|
|
47
|
+
- **Scope & Action:** Audited file path or module, tool invoked, and whether database state was modified.
|
|
48
|
+
- **Structural Evidence:** Exact symbol declarations, caller counts, or dependency paths identified.
|
|
49
|
+
- **Status & Violations:** Clear pass/fail outcome with specific rule violations or circular dependency paths if detected.
|
|
50
|
+
- **Recommended Action:** Remediation steps (e.g. dependency inversion, extracting shared interfaces, or reusing existing utilities).
|
|
51
|
+
`;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as readline from "node:readline";
|
|
2
|
+
import type { HarnessOption } from "../scaffold/harness-config.ts";
|
|
3
|
+
|
|
4
|
+
const RESET = "\x1b[0m";
|
|
5
|
+
const BOLD = "\x1b[1m";
|
|
6
|
+
const DIM = "\x1b[2m";
|
|
7
|
+
const CYAN = "\x1b[36m";
|
|
8
|
+
const GREEN = "\x1b[32m";
|
|
9
|
+
const YELLOW = "\x1b[33m";
|
|
10
|
+
const HIDE_CURSOR = "\x1b[?25l";
|
|
11
|
+
const SHOW_CURSOR = "\x1b[?25h";
|
|
12
|
+
|
|
13
|
+
export async function promptSelectHarnesses(options: HarnessOption[]): Promise<string[]> {
|
|
14
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
15
|
+
// Non-interactive fallback (CI/scripts/piped): return default selections
|
|
16
|
+
return options.filter((o) => o.selectedByDefault).map((o) => o.id);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const selected = new Set<string>(
|
|
20
|
+
options.filter((o) => o.selectedByDefault).map((o) => o.id)
|
|
21
|
+
);
|
|
22
|
+
let cursor = 0;
|
|
23
|
+
|
|
24
|
+
process.stdout.write(HIDE_CURSOR);
|
|
25
|
+
|
|
26
|
+
function render(firstTime: boolean = false) {
|
|
27
|
+
if (!firstTime) {
|
|
28
|
+
// Move up by number of options + header lines
|
|
29
|
+
readline.moveCursor(process.stdout, 0, -(options.length + 2));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
readline.clearLine(process.stdout, 0);
|
|
33
|
+
console.log(
|
|
34
|
+
`${CYAN}◇${RESET} ${BOLD}Select AI Agent Harnesses for this project:${RESET} ${DIM}(Space: toggle, Enter: confirm, 'a': all)${RESET}`
|
|
35
|
+
);
|
|
36
|
+
readline.clearLine(process.stdout, 0);
|
|
37
|
+
console.log(`${CYAN}│${RESET}`);
|
|
38
|
+
|
|
39
|
+
for (let i = 0; i < options.length; i++) {
|
|
40
|
+
const opt = options[i];
|
|
41
|
+
const isCurrent = i === cursor;
|
|
42
|
+
const isChecked = selected.has(opt.id);
|
|
43
|
+
|
|
44
|
+
const pointer = isCurrent ? `${CYAN}❯${RESET}` : " ";
|
|
45
|
+
const box = isChecked ? `${GREEN}[●]${RESET}` : `${DIM}[○]${RESET}`;
|
|
46
|
+
const name = isCurrent ? `${BOLD}${opt.name}${RESET}` : opt.name;
|
|
47
|
+
const file = `${DIM}(${opt.targetFile})${RESET}`;
|
|
48
|
+
|
|
49
|
+
readline.clearLine(process.stdout, 0);
|
|
50
|
+
console.log(`${CYAN}│${RESET} ${pointer} ${box} ${name.padEnd(26)} ${file}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
render(true);
|
|
55
|
+
|
|
56
|
+
return new Promise<string[]>((resolve) => {
|
|
57
|
+
readline.emitKeypressEvents(process.stdin);
|
|
58
|
+
const wasRaw = process.stdin.isRaw;
|
|
59
|
+
process.stdin.setRawMode(true);
|
|
60
|
+
process.stdin.resume();
|
|
61
|
+
|
|
62
|
+
const onKeypress = (str: string, key: readline.Key) => {
|
|
63
|
+
if (key.ctrl && key.name === "c") {
|
|
64
|
+
cleanup();
|
|
65
|
+
process.exit(130);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (key.name === "up" || key.name === "k") {
|
|
69
|
+
cursor = (cursor - 1 + options.length) % options.length;
|
|
70
|
+
render();
|
|
71
|
+
} else if (key.name === "down" || key.name === "j") {
|
|
72
|
+
cursor = (cursor + 1) % options.length;
|
|
73
|
+
render();
|
|
74
|
+
} else if (key.name === "space") {
|
|
75
|
+
const id = options[cursor].id;
|
|
76
|
+
if (selected.has(id)) {
|
|
77
|
+
selected.delete(id);
|
|
78
|
+
} else {
|
|
79
|
+
selected.add(id);
|
|
80
|
+
}
|
|
81
|
+
render();
|
|
82
|
+
} else if (str === "a" || str === "A") {
|
|
83
|
+
if (selected.size === options.length) {
|
|
84
|
+
selected.clear();
|
|
85
|
+
} else {
|
|
86
|
+
for (const opt of options) selected.add(opt.id);
|
|
87
|
+
}
|
|
88
|
+
render();
|
|
89
|
+
} else if (key.name === "return" || key.name === "enter") {
|
|
90
|
+
cleanup();
|
|
91
|
+
// Clear prompt display and print finalized selection summary
|
|
92
|
+
readline.moveCursor(process.stdout, 0, -(options.length + 2));
|
|
93
|
+
for (let i = 0; i < options.length + 2; i++) {
|
|
94
|
+
readline.clearLine(process.stdout, 0);
|
|
95
|
+
readline.moveCursor(process.stdout, 0, 1);
|
|
96
|
+
}
|
|
97
|
+
readline.moveCursor(process.stdout, 0, -(options.length + 2));
|
|
98
|
+
|
|
99
|
+
const names = options
|
|
100
|
+
.filter((o) => selected.has(o.id))
|
|
101
|
+
.map((o) => o.name)
|
|
102
|
+
.join(", ");
|
|
103
|
+
console.log(
|
|
104
|
+
`${GREEN}✓${RESET} ${BOLD}Configured AI Harnesses:${RESET} ${names || `${YELLOW}None (skipped)${RESET}`}`
|
|
105
|
+
);
|
|
106
|
+
console.log(`${CYAN}│${RESET}`);
|
|
107
|
+
|
|
108
|
+
resolve(Array.from(selected));
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
function cleanup() {
|
|
113
|
+
process.stdin.removeListener("keypress", onKeypress);
|
|
114
|
+
process.stdin.setRawMode(wasRaw);
|
|
115
|
+
process.stdin.pause();
|
|
116
|
+
process.stdout.write(SHOW_CURSOR);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
process.stdin.on("keypress", onKeypress);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|