march-cli 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/bin/march.mjs +13 -0
- package/package.json +36 -0
- package/src/agent/command-exec-tool.mjs +91 -0
- package/src/agent/context-stats-tool.mjs +57 -0
- package/src/agent/editing/diff-apply.mjs +28 -0
- package/src/agent/editing/diff-format.mjs +57 -0
- package/src/agent/file-edit-tool.mjs +276 -0
- package/src/agent/find-tool.mjs +112 -0
- package/src/agent/model-payload-dumper.mjs +201 -0
- package/src/agent/pi-session/pi-session-sidecar-failure.mjs +10 -0
- package/src/agent/provider/payload-messages.mjs +138 -0
- package/src/agent/read-file-tool.mjs +112 -0
- package/src/agent/runner/fast-model.mjs +36 -0
- package/src/agent/runner/runner-cleanup.mjs +12 -0
- package/src/agent/runner/runner-init.mjs +15 -0
- package/src/agent/runner/runner-session-state.mjs +40 -0
- package/src/agent/runner.mjs +266 -0
- package/src/agent/runtime/runner-runtime-host.mjs +73 -0
- package/src/agent/runtime/runtime-factory.mjs +42 -0
- package/src/agent/runtime/runtime-host.mjs +34 -0
- package/src/agent/session/session-auto-name.mjs +41 -0
- package/src/agent/session/session-binding.mjs +12 -0
- package/src/agent/session/session-options.mjs +46 -0
- package/src/agent/tool-names.mjs +1 -0
- package/src/agent/tool-result.mjs +3 -0
- package/src/agent/tools.mjs +54 -0
- package/src/agent/turn/turn-events.mjs +64 -0
- package/src/agent/turn/turn-runner.mjs +103 -0
- package/src/auth/login-command.mjs +90 -0
- package/src/auth/storage.mjs +33 -0
- package/src/cli/args.mjs +71 -0
- package/src/cli/commands/copy-command.mjs +73 -0
- package/src/cli/commands/export-command.mjs +206 -0
- package/src/cli/commands/extensions-command.mjs +53 -0
- package/src/cli/commands/help-command.mjs +7 -0
- package/src/cli/commands/model-command.mjs +110 -0
- package/src/cli/commands/paste-image-command.mjs +43 -0
- package/src/cli/commands/provider-command.mjs +55 -0
- package/src/cli/commands/status-command.mjs +157 -0
- package/src/cli/commands/thinking-command.mjs +80 -0
- package/src/cli/fallback-ui.mjs +156 -0
- package/src/cli/input/attachment-tokens.mjs +20 -0
- package/src/cli/input/autocomplete.mjs +106 -0
- package/src/cli/input/external-editor.mjs +39 -0
- package/src/cli/input/history-store.mjs +35 -0
- package/src/cli/input/image-clipboard.mjs +55 -0
- package/src/cli/input/keybinding-dispatch.mjs +76 -0
- package/src/cli/input/keybindings.mjs +96 -0
- package/src/cli/input/mode-state.mjs +43 -0
- package/src/cli/input/prompt-templates.mjs +84 -0
- package/src/cli/input/select-with-keyboard.mjs +67 -0
- package/src/cli/permissions.mjs +103 -0
- package/src/cli/repl-commands.mjs +86 -0
- package/src/cli/repl-loop.mjs +157 -0
- package/src/cli/selector-list.mjs +21 -0
- package/src/cli/session/pi-session-switch-command.mjs +41 -0
- package/src/cli/session/session-command.mjs +23 -0
- package/src/cli/session/session-list-command.mjs +68 -0
- package/src/cli/session/session-name-command.mjs +26 -0
- package/src/cli/session/session-source-command.mjs +89 -0
- package/src/cli/session/session-switch-command.mjs +1 -0
- package/src/cli/shell/shell-command.mjs +55 -0
- package/src/cli/shell/shell-drawer-controls.mjs +33 -0
- package/src/cli/shell/shell-drawer.mjs +192 -0
- package/src/cli/shell/shell-split-layout.mjs +70 -0
- package/src/cli/slash-commands.mjs +176 -0
- package/src/cli/startup/startup-banner.mjs +17 -0
- package/src/cli/startup/startup-session.mjs +51 -0
- package/src/cli/status-line-updater.mjs +74 -0
- package/src/cli/tool-output.mjs +9 -0
- package/src/cli/tui/editor/external-editor-runner.mjs +24 -0
- package/src/cli/tui/input/mouse-selection-controller.mjs +89 -0
- package/src/cli/tui/input/mouse-tracking.mjs +20 -0
- package/src/cli/tui/layout/main-pane-layout.mjs +38 -0
- package/src/cli/tui/layout/safe-render-boundary.mjs +46 -0
- package/src/cli/tui/markdown-renderer.mjs +279 -0
- package/src/cli/tui/output/scroll-state.mjs +79 -0
- package/src/cli/tui/output/tool-card-renderer.mjs +59 -0
- package/src/cli/tui/output-buffer.mjs +297 -0
- package/src/cli/tui/permission-request-ui.mjs +18 -0
- package/src/cli/tui/recall-rendering.mjs +25 -0
- package/src/cli/tui/select/editor-select-list.mjs +111 -0
- package/src/cli/tui/selection-screen.mjs +212 -0
- package/src/cli/tui/status/retry-status.mjs +72 -0
- package/src/cli/tui/status/spinner-status.mjs +42 -0
- package/src/cli/tui/status/status-bar.mjs +88 -0
- package/src/cli/tui/syntax/highlighting.mjs +277 -0
- package/src/cli/tui/syntax/languages.mjs +91 -0
- package/src/cli/tui/syntax/tree-sitter/bash.highlights.scm +261 -0
- package/src/cli/tui/syntax/tree-sitter/c.highlights.scm +341 -0
- package/src/cli/tui/syntax/tree-sitter/cpp.highlights.scm +268 -0
- package/src/cli/tui/syntax/tree-sitter/csharp.highlights.scm +577 -0
- package/src/cli/tui/syntax/tree-sitter/css.highlights.scm +109 -0
- package/src/cli/tui/syntax/tree-sitter/diff.highlights.scm +49 -0
- package/src/cli/tui/syntax/tree-sitter/go.highlights.scm +254 -0
- package/src/cli/tui/syntax/tree-sitter/html.highlights.scm +13 -0
- package/src/cli/tui/syntax/tree-sitter/java.highlights.scm +330 -0
- package/src/cli/tui/syntax/tree-sitter/json.highlights.scm +38 -0
- package/src/cli/tui/syntax/tree-sitter/php.highlights.scm +203 -0
- package/src/cli/tui/syntax/tree-sitter/python.highlights.scm +137 -0
- package/src/cli/tui/syntax/tree-sitter/ruby.highlights.scm +309 -0
- package/src/cli/tui/syntax/tree-sitter/rust.highlights.scm +531 -0
- package/src/cli/tui/syntax/tree-sitter/toml.highlights.scm +39 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-bash.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-c-sharp.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-c.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-cpp.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-css.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-diff.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-go.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-html.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-java.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-json.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-php.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-python.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-ruby.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-rust.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-toml.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-tsx.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-typescript.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tree-sitter-yaml.wasm +0 -0
- package/src/cli/tui/syntax/tree-sitter/tsx.highlights.scm +35 -0
- package/src/cli/tui/syntax/tree-sitter/typescript.highlights.scm +35 -0
- package/src/cli/tui/syntax/tree-sitter/yaml.highlights.scm +99 -0
- package/src/cli/tui/tool-rendering.mjs +194 -0
- package/src/cli/tui/tui-diff-rendering.mjs +157 -0
- package/src/cli/tui/tui-handlers.mjs +110 -0
- package/src/cli/tui/tui-input-controller.mjs +61 -0
- package/src/cli/tui/ui-theme.mjs +148 -0
- package/src/cli/ui.mjs +299 -0
- package/src/config/config-json.mjs +73 -0
- package/src/config/dotenv.mjs +20 -0
- package/src/config/features.mjs +75 -0
- package/src/config/loader.mjs +109 -0
- package/src/config/settings-command.mjs +97 -0
- package/src/context/diagnostics.mjs +70 -0
- package/src/context/engine.mjs +148 -0
- package/src/context/injections.mjs +26 -0
- package/src/context/project-context.mjs +20 -0
- package/src/context/session-status.mjs +15 -0
- package/src/context/shell-layers.mjs +23 -0
- package/src/context/system-core/base.md +60 -0
- package/src/context/system-core/prompts/deepseek-v4-pro.md +3 -0
- package/src/context/system-core/prompts/default.md +3 -0
- package/src/context/system-core.mjs +35 -0
- package/src/debug/model-context-dumper.mjs +52 -0
- package/src/extensions/discovery.mjs +40 -0
- package/src/extensions/lifecycle-adapter.mjs +210 -0
- package/src/extensions/lifecycle-manifest.mjs +69 -0
- package/src/image-gen/index.mjs +7 -0
- package/src/image-gen/provider.mjs +231 -0
- package/src/image-gen/tool.mjs +84 -0
- package/src/lsp/client.mjs +204 -0
- package/src/lsp/diagnostic-store.mjs +39 -0
- package/src/lsp/servers.mjs +212 -0
- package/src/lsp/service.mjs +65 -0
- package/src/main.mjs +294 -0
- package/src/mcp/client.mjs +195 -0
- package/src/mcp/config.mjs +130 -0
- package/src/mcp/index.mjs +48 -0
- package/src/mcp/tools.mjs +98 -0
- package/src/memory/database.mjs +219 -0
- package/src/memory/glossary.mjs +124 -0
- package/src/memory/graph/graph-cascades.mjs +109 -0
- package/src/memory/graph/graph-diagnostics.mjs +73 -0
- package/src/memory/graph/graph-path-removal.mjs +50 -0
- package/src/memory/graph/graph-path-utils.mjs +17 -0
- package/src/memory/graph/graph-primitives.mjs +103 -0
- package/src/memory/graph/graph-read.mjs +159 -0
- package/src/memory/graph.mjs +282 -0
- package/src/memory/markdown/markdown-delete.mjs +23 -0
- package/src/memory/markdown/markdown-format.mjs +128 -0
- package/src/memory/markdown/markdown-recall.mjs +28 -0
- package/src/memory/markdown/ripgrep.mjs +16 -0
- package/src/memory/markdown/sqlite-index.mjs +87 -0
- package/src/memory/markdown-store.mjs +286 -0
- package/src/memory/markdown-tools.mjs +103 -0
- package/src/memory/search.mjs +142 -0
- package/src/memory/snapshot.mjs +86 -0
- package/src/memory/system-views.mjs +120 -0
- package/src/memory/tools.mjs +282 -0
- package/src/notification/desktop-notifier.mjs +85 -0
- package/src/platform/open-file.mjs +28 -0
- package/src/provider/config-command.mjs +129 -0
- package/src/provider/presets.mjs +72 -0
- package/src/session/attachment-display.mjs +16 -0
- package/src/session/attachment-references.mjs +65 -0
- package/src/session/attachments.mjs +140 -0
- package/src/session/persist.mjs +1 -0
- package/src/session/pi-manager.mjs +34 -0
- package/src/session/session-utils.mjs +16 -0
- package/src/session/sidecar-sync.mjs +19 -0
- package/src/session/sidecar.mjs +68 -0
- package/src/session/transcript.mjs +83 -0
- package/src/session/tree.mjs +42 -0
- package/src/shell/cli-runtime.mjs +11 -0
- package/src/shell/hints.mjs +12 -0
- package/src/shell/node-pty-adapter.mjs +81 -0
- package/src/shell/runtime-state.mjs +126 -0
- package/src/shell/runtime.mjs +244 -0
- package/src/shell/screen-buffer.mjs +136 -0
- package/src/shell/tool-read.mjs +74 -0
- package/src/shell/tools.mjs +299 -0
- package/src/supergrok/actions/image-generate.mjs +60 -0
- package/src/supergrok/actions/search.mjs +78 -0
- package/src/supergrok/auth.mjs +36 -0
- package/src/supergrok/constants.mjs +18 -0
- package/src/supergrok/oauth-provider.mjs +278 -0
- package/src/supergrok/provider.mjs +36 -0
- package/src/supergrok/response.mjs +76 -0
- package/src/supergrok/tool.mjs +61 -0
- package/src/text/ansi.mjs +3 -0
- package/src/web/config-command.mjs +43 -0
- package/src/web/fetch.mjs +78 -0
- package/src/web/presets.mjs +16 -0
- package/src/web/search.mjs +83 -0
- package/src/web/tools.mjs +107 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { resolveImageAttachmentReferences } from "../../session/attachment-references.mjs";
|
|
2
|
+
import { closeAssistantReply, createTurnEventState, handleRunnerSessionEvent } from "./turn-events.mjs";
|
|
3
|
+
|
|
4
|
+
export async function runRunnerTurn({
|
|
5
|
+
prompt,
|
|
6
|
+
userMessage,
|
|
7
|
+
options = {},
|
|
8
|
+
sessionBinding,
|
|
9
|
+
engine,
|
|
10
|
+
ui,
|
|
11
|
+
projectMarchDir,
|
|
12
|
+
memoryStore,
|
|
13
|
+
setModelCallKind,
|
|
14
|
+
onMidTurnRecallHints,
|
|
15
|
+
syncCurrentPiSidecar,
|
|
16
|
+
autoNameSession,
|
|
17
|
+
contextMode = "rebuild",
|
|
18
|
+
}) {
|
|
19
|
+
const { userRecallHints = [], currentProject = "" } = options;
|
|
20
|
+
const activeSession = sessionBinding.get();
|
|
21
|
+
const turnState = createTurnEventState();
|
|
22
|
+
const midTurnRecallHints = [];
|
|
23
|
+
ui.turnStart();
|
|
24
|
+
|
|
25
|
+
const unsubscribe = activeSession.subscribe((event) => {
|
|
26
|
+
handleRunnerSessionEvent(event, { ui, engine, state: turnState });
|
|
27
|
+
if (event.type === "tool_execution_end") {
|
|
28
|
+
const hints = recallForAssistantState({ memoryStore, engine, turnState, currentProject });
|
|
29
|
+
if (hints.length > 0) {
|
|
30
|
+
midTurnRecallHints.push(...hints);
|
|
31
|
+
onMidTurnRecallHints?.(hints);
|
|
32
|
+
ui.memoryHint?.({ source: "assistant", hints });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const attachmentReferences = resolveImageAttachmentReferences({
|
|
39
|
+
text: userMessage ?? prompt,
|
|
40
|
+
projectMarchDir,
|
|
41
|
+
});
|
|
42
|
+
setModelCallKind("user");
|
|
43
|
+
try {
|
|
44
|
+
if (contextMode === "rebuild") resetPiMessageHistory(activeSession);
|
|
45
|
+
await activeSession.prompt(
|
|
46
|
+
contextMode === "continueExistingPiTranscript" ? (userMessage ?? prompt) : prompt,
|
|
47
|
+
attachmentReferences.images.length > 0 ? { images: attachmentReferences.images } : undefined,
|
|
48
|
+
);
|
|
49
|
+
} finally {
|
|
50
|
+
setModelCallKind("model");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
closeAssistantReply({ ui, state: turnState });
|
|
54
|
+
const assistantRecallHints = recallForAssistantState({ memoryStore, engine, turnState, currentProject });
|
|
55
|
+
ui.memoryHint?.({ source: "assistant", hints: assistantRecallHints });
|
|
56
|
+
const recordedAssistantRecallHints = uniqueHints([...midTurnRecallHints, ...assistantRecallHints]);
|
|
57
|
+
|
|
58
|
+
engine.recordTurn({
|
|
59
|
+
userMessage: userMessage ?? prompt.slice(0, 300),
|
|
60
|
+
assistantMessage: turnState.draft,
|
|
61
|
+
userRecallHints,
|
|
62
|
+
assistantRecallHints: recordedAssistantRecallHints,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
autoNameSession?.();
|
|
66
|
+
syncCurrentPiSidecar();
|
|
67
|
+
return { draft: turnState.draft };
|
|
68
|
+
} finally {
|
|
69
|
+
ui.turnEnd();
|
|
70
|
+
unsubscribe();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function recallForAssistantState({ memoryStore, engine, turnState, currentProject }) {
|
|
75
|
+
if (!memoryStore) return [];
|
|
76
|
+
return memoryStore.recallForAssistant(assistantRecallText(turnState), {
|
|
77
|
+
currentProject,
|
|
78
|
+
excludedIds: engine.getRecentRecallMemoryIds?.() ?? [],
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function assistantRecallText(turnState) {
|
|
83
|
+
return [turnState.draft, turnState.thinkingAccumulator, turnState.thinkingText]
|
|
84
|
+
.filter(Boolean)
|
|
85
|
+
.join("\n");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function uniqueHints(hints) {
|
|
89
|
+
const seen = new Set();
|
|
90
|
+
const unique = [];
|
|
91
|
+
for (const hint of hints) {
|
|
92
|
+
if (!hint?.id || seen.has(hint.id)) continue;
|
|
93
|
+
seen.add(hint.id);
|
|
94
|
+
unique.push(hint);
|
|
95
|
+
}
|
|
96
|
+
return unique;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function resetPiMessageHistory(session) {
|
|
100
|
+
if (Array.isArray(session?.agent?.state?.messages)) {
|
|
101
|
+
session.agent.state.messages = [];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { AuthStorage } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { getMarchAuthPath } from "./storage.mjs";
|
|
5
|
+
|
|
6
|
+
export async function runLoginCommand({
|
|
7
|
+
providerId,
|
|
8
|
+
homeDir = homedir(),
|
|
9
|
+
authPath = getMarchAuthPath(homeDir),
|
|
10
|
+
authStorage = AuthStorage.create(authPath),
|
|
11
|
+
input = process.stdin,
|
|
12
|
+
output = process.stdout,
|
|
13
|
+
} = {}) {
|
|
14
|
+
const providers = authStorage.getOAuthProviders?.() ?? [];
|
|
15
|
+
const selectedProvider = providerId || await selectProvider({ providers, input, output });
|
|
16
|
+
if (!selectedProvider) {
|
|
17
|
+
output.write("Login cancelled.\n");
|
|
18
|
+
return 1;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!providers.some((provider) => provider.id === selectedProvider)) {
|
|
22
|
+
output.write(`Unknown OAuth provider: ${selectedProvider}\n`);
|
|
23
|
+
output.write(formatProviderList(providers));
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const rl = createInterface({ input, output });
|
|
28
|
+
try {
|
|
29
|
+
output.write(`Logging in to ${selectedProvider}...\n`);
|
|
30
|
+
await authStorage.login(selectedProvider, {
|
|
31
|
+
onAuth: (info) => {
|
|
32
|
+
output.write(`\nOpen this URL in your browser:\n${info.url}\n`);
|
|
33
|
+
if (info.instructions) output.write(`${info.instructions}\n`);
|
|
34
|
+
output.write("\n");
|
|
35
|
+
},
|
|
36
|
+
onPrompt: (prompt) => ask(rl, `${prompt.message}${prompt.placeholder ? ` (${prompt.placeholder})` : ""}: `),
|
|
37
|
+
onManualCodeInput: () => ask(rl, "Paste redirect URL or code: "),
|
|
38
|
+
onProgress: (message) => output.write(`${message}\n`),
|
|
39
|
+
onSelect: async (prompt) => selectOption({ prompt, rl, output }),
|
|
40
|
+
});
|
|
41
|
+
output.write(`\nCredentials saved to ${authPath}\n`);
|
|
42
|
+
return 0;
|
|
43
|
+
} finally {
|
|
44
|
+
rl.close();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function formatProviderList(providers) {
|
|
49
|
+
if (!providers.length) return "No OAuth providers are available.\n";
|
|
50
|
+
const lines = ["Available OAuth providers:"];
|
|
51
|
+
for (const provider of providers) {
|
|
52
|
+
lines.push(` ${provider.id.padEnd(20)} ${provider.name}`);
|
|
53
|
+
}
|
|
54
|
+
return `${lines.join("\n")}\n`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function selectProvider({ providers, input, output }) {
|
|
58
|
+
if (providers.length === 1) return providers[0].id;
|
|
59
|
+
output.write(`${formatProviderList(providers)}\n`);
|
|
60
|
+
const rl = createInterface({ input, output });
|
|
61
|
+
try {
|
|
62
|
+
const answer = await ask(rl, `Enter provider id or number (1-${providers.length}): `);
|
|
63
|
+
return resolveSelection(answer, providers.map((provider) => ({ id: provider.id, label: provider.name })));
|
|
64
|
+
} finally {
|
|
65
|
+
rl.close();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function selectOption({ prompt, rl, output }) {
|
|
70
|
+
output.write(`${prompt.message}\n`);
|
|
71
|
+
for (let i = 0; i < prompt.options.length; i++) {
|
|
72
|
+
const option = prompt.options[i];
|
|
73
|
+
output.write(` ${i + 1}. ${option.label} (${option.id})\n`);
|
|
74
|
+
}
|
|
75
|
+
const answer = await ask(rl, `Enter option id or number (1-${prompt.options.length}): `);
|
|
76
|
+
return resolveSelection(answer, prompt.options);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function resolveSelection(answer, options) {
|
|
80
|
+
const trimmed = answer.trim();
|
|
81
|
+
const index = Number.parseInt(trimmed, 10);
|
|
82
|
+
if (Number.isInteger(index) && String(index) === trimmed && index >= 1 && index <= options.length) {
|
|
83
|
+
return options[index - 1].id;
|
|
84
|
+
}
|
|
85
|
+
return options.some((option) => option.id === trimmed) ? trimmed : undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function ask(rl, question) {
|
|
89
|
+
return new Promise((resolve) => rl.question(question, resolve));
|
|
90
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { AuthStorage } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
|
|
5
|
+
export function getMarchAuthPath(homeDir = homedir()) {
|
|
6
|
+
return resolve(homeDir, ".march", "auth.json");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createMarchAuthStorage({
|
|
10
|
+
providers = {},
|
|
11
|
+
homeDir = homedir(),
|
|
12
|
+
authStorage = null,
|
|
13
|
+
} = {}) {
|
|
14
|
+
const resolvedAuthStorage = authStorage ?? AuthStorage.create(getMarchAuthPath(homeDir));
|
|
15
|
+
|
|
16
|
+
for (const profile of Object.values(providers ?? {})) {
|
|
17
|
+
if (!profile || typeof profile !== "object") continue;
|
|
18
|
+
const type = profile.type ?? profile.provider;
|
|
19
|
+
const profileKey = profile.auth?.method === "apiKey" ? profile.auth?.apiKey : null;
|
|
20
|
+
if (type && profileKey) resolvedAuthStorage.setRuntimeApiKey(type, profileKey);
|
|
21
|
+
}
|
|
22
|
+
const hasStoredAuth = Boolean(resolvedAuthStorage.list?.().length);
|
|
23
|
+
const hasConfiguredProvider = Object.values(providers ?? {}).some((profile) => {
|
|
24
|
+
if (!profile || typeof profile !== "object") return false;
|
|
25
|
+
return Boolean(profile.auth?.apiKey);
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
authStorage: resolvedAuthStorage,
|
|
29
|
+
authPath: getMarchAuthPath(homeDir),
|
|
30
|
+
hasAuth: hasStoredAuth || hasConfiguredProvider,
|
|
31
|
+
diagnostics: [],
|
|
32
|
+
};
|
|
33
|
+
}
|
package/src/cli/args.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
export function parseCliArgs(argv) {
|
|
4
|
+
const { values, positionals } = parseArgs({
|
|
5
|
+
args: argv,
|
|
6
|
+
options: {
|
|
7
|
+
model: { type: "string", short: "m" },
|
|
8
|
+
provider: { type: "string" },
|
|
9
|
+
resume: { type: "string" },
|
|
10
|
+
json: { type: "boolean" },
|
|
11
|
+
extension: { type: "string", short: "e", multiple: true },
|
|
12
|
+
extension: { type: "string", short: "e", multiple: true },
|
|
13
|
+
config: { type: "boolean" },
|
|
14
|
+
"dump-context": { type: "boolean" },
|
|
15
|
+
"pi-sessions": { type: "boolean" },
|
|
16
|
+
"pi-runtime-host": { type: "boolean" },
|
|
17
|
+
"shell-runtime": { type: "boolean" },
|
|
18
|
+
"no-shell-runtime": { type: "boolean" },
|
|
19
|
+
"permission-mode": { type: "string" },
|
|
20
|
+
help: { type: "boolean", short: "h" },
|
|
21
|
+
},
|
|
22
|
+
allowPositionals: true,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const commandName = ["login", "provider", "websearch"].includes(positionals[0]) ? positionals[0] : null;
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
command: commandName ? { name: commandName, args: positionals.slice(1) } : null,
|
|
29
|
+
model: values.model ?? null,
|
|
30
|
+
provider: values.provider,
|
|
31
|
+
resume: values.resume,
|
|
32
|
+
json: values.json ?? false,
|
|
33
|
+
extensions: values.extension ?? [],
|
|
34
|
+
dumpContext: values["dump-context"] ?? false,
|
|
35
|
+
providerConfig: values.config ?? false,
|
|
36
|
+
piSessions: values["pi-sessions"] ?? false,
|
|
37
|
+
piRuntimeHost: values["pi-runtime-host"] ?? false,
|
|
38
|
+
shellRuntime: values["no-shell-runtime"] ? false : true,
|
|
39
|
+
permissionMode: values["permission-mode"] ?? "bypassPermissions",
|
|
40
|
+
help: values.help ?? false,
|
|
41
|
+
prompt: commandName ? "" : positionals.join(" "),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function showHelp() {
|
|
46
|
+
process.stdout.write(`march — terminal-native coding agent
|
|
47
|
+
|
|
48
|
+
Usage:
|
|
49
|
+
march [options] [prompt]
|
|
50
|
+
march [options] (starts REPL)
|
|
51
|
+
march login [provider] Login to an OAuth provider
|
|
52
|
+
march provider --config Configure provider credentials
|
|
53
|
+
march websearch --config Configure web search credentials
|
|
54
|
+
|
|
55
|
+
Options:
|
|
56
|
+
-m, --model <id> Initial model ID override
|
|
57
|
+
--provider <name> Initial provider override
|
|
58
|
+
--resume <id> Resume a pi session by default
|
|
59
|
+
--json JSON output mode (no TUI)
|
|
60
|
+
--config With provider/websearch command, open configuration
|
|
61
|
+
--dump-context Write every prompt sent to the model under .march/context-dumps/
|
|
62
|
+
--pi-sessions Force pi JSONL SessionManager persistence
|
|
63
|
+
--pi-runtime-host Force pi AgentSessionRuntime host path
|
|
64
|
+
--shell-runtime Enable interactive PTY shell tools (default)
|
|
65
|
+
--no-shell-runtime Disable interactive PTY shell tools and shell pane
|
|
66
|
+
--permission-mode <mode> Permission mode: default, bypassPermissions, dontAsk (default: bypassPermissions)
|
|
67
|
+
-e, --extension <path>
|
|
68
|
+
Load a pi extension path in the default runtime host (repeatable)
|
|
69
|
+
-h, --help Show this help
|
|
70
|
+
`);
|
|
71
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
export function copyLastAssistantMessage({ engine, writeClipboard = writeSystemClipboard } = {}) {
|
|
4
|
+
const message = findLastAssistantMessage(engine);
|
|
5
|
+
if (!message) return ["Error: no assistant response to copy"];
|
|
6
|
+
const result = writeClipboard(message);
|
|
7
|
+
if (result?.ok === false) return [`Error: ${result.message}`];
|
|
8
|
+
return [`Copied last assistant response (${message.length} chars)`];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function findLastAssistantMessage(engine) {
|
|
12
|
+
const turns = engine?.turns ?? [];
|
|
13
|
+
for (let i = turns.length - 1; i >= 0; i -= 1) {
|
|
14
|
+
const text = turns[i]?.assistantMessage;
|
|
15
|
+
if (typeof text === "string" && text.trim()) return text;
|
|
16
|
+
}
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function writeSystemClipboard(text, { platform = process.platform } = {}) {
|
|
21
|
+
const command = clipboardCommand(platform);
|
|
22
|
+
if (!command) return { ok: false, message: `clipboard is not supported on ${platform}` };
|
|
23
|
+
const result = spawnSync(command.bin, command.args, {
|
|
24
|
+
input: text,
|
|
25
|
+
encoding: "utf8",
|
|
26
|
+
windowsHide: true,
|
|
27
|
+
});
|
|
28
|
+
if (result.error) return { ok: false, message: result.error.message };
|
|
29
|
+
if (result.status !== 0) {
|
|
30
|
+
const stderr = (result.stderr || "").trim();
|
|
31
|
+
return { ok: false, message: stderr || `${command.bin} exited ${result.status}` };
|
|
32
|
+
}
|
|
33
|
+
return { ok: true };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function writeSystemClipboardAsync(text, { platform = process.platform } = {}) {
|
|
37
|
+
const command = clipboardCommand(platform);
|
|
38
|
+
if (!command) return Promise.resolve({ ok: false, message: `clipboard is not supported on ${platform}` });
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
let settled = false;
|
|
41
|
+
let stderr = "";
|
|
42
|
+
const done = (result) => {
|
|
43
|
+
if (settled) return;
|
|
44
|
+
settled = true;
|
|
45
|
+
resolve(result);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const child = spawn(command.bin, command.args, {
|
|
49
|
+
windowsHide: true,
|
|
50
|
+
stdio: ["pipe", "ignore", "pipe"],
|
|
51
|
+
});
|
|
52
|
+
child.stderr?.setEncoding?.("utf8");
|
|
53
|
+
child.stderr?.on("data", (chunk) => { stderr += chunk; });
|
|
54
|
+
child.on("error", (err) => done({ ok: false, message: err.message }));
|
|
55
|
+
child.on("close", (status) => {
|
|
56
|
+
if (status === 0) done({ ok: true });
|
|
57
|
+
else done({ ok: false, message: stderr.trim() || `${command.bin} exited ${status}` });
|
|
58
|
+
});
|
|
59
|
+
child.stdin?.on("error", (err) => done({ ok: false, message: err.message }));
|
|
60
|
+
child.stdin?.end(text, "utf8");
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function clipboardCommand(platform) {
|
|
65
|
+
if (platform === "win32") {
|
|
66
|
+
return {
|
|
67
|
+
bin: "powershell.exe",
|
|
68
|
+
args: ["-NoProfile", "-Command", "Set-Clipboard -Value ([Console]::In.ReadToEnd())"],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (platform === "darwin") return { bin: "pbcopy", args: [] };
|
|
72
|
+
return { bin: "sh", args: ["-lc", "command -v wl-copy >/dev/null && wl-copy || xclip -selection clipboard || xsel --clipboard --input"] };
|
|
73
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
export function parseExportCommand(input) {
|
|
5
|
+
if (input !== "/export" && !input.startsWith("/export ")) return { type: "none" };
|
|
6
|
+
const args = input.slice("/export".length).trim().split(/\s+/).filter(Boolean);
|
|
7
|
+
if (args.length === 0) return { type: "error", message: "usage: /export jsonl|html|gist <jsonl|html>" };
|
|
8
|
+
if (args[0] === "gist") {
|
|
9
|
+
if (args.length !== 2) return { type: "error", message: "usage: /export gist <jsonl|html>" };
|
|
10
|
+
if (args[1] !== "jsonl" && args[1] !== "html") return { type: "error", message: `unsupported gist export format: ${args[1]}` };
|
|
11
|
+
return { type: "gist", format: args[1] };
|
|
12
|
+
}
|
|
13
|
+
if (args.length > 1) return { type: "error", message: "usage: /export jsonl|html|gist <jsonl|html>" };
|
|
14
|
+
if (args[0] !== "jsonl" && args[0] !== "html") return { type: "error", message: `unsupported export format: ${args[0]}` };
|
|
15
|
+
return { type: args[0] };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function handleExportCommand(command, { runner, sessionState, sessionSource = "pi", projectMarchDir, now = new Date(), env = process.env, fetchImpl = globalThis.fetch } = {}) {
|
|
19
|
+
if (command.type === "error") return [`Error: ${command.message}`];
|
|
20
|
+
if (command.type !== "jsonl" && command.type !== "html" && command.type !== "gist") return [];
|
|
21
|
+
|
|
22
|
+
const options = {
|
|
23
|
+
engine: runner.engine,
|
|
24
|
+
sessionStats: runner.getSessionStats?.(),
|
|
25
|
+
sessionState,
|
|
26
|
+
sessionSource,
|
|
27
|
+
projectMarchDir,
|
|
28
|
+
now,
|
|
29
|
+
};
|
|
30
|
+
if (command.type === "gist") {
|
|
31
|
+
try {
|
|
32
|
+
const result = await createSessionGist({ ...options, format: command.format, env, fetchImpl });
|
|
33
|
+
return [`Created Gist: ${result.url}`];
|
|
34
|
+
} catch (err) {
|
|
35
|
+
return [`Error: ${err.message}`];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const result = command.type === "jsonl"
|
|
39
|
+
? exportSessionJsonl(options)
|
|
40
|
+
: exportSessionHtml(options);
|
|
41
|
+
return [`Exported ${command.type.toUpperCase()}: ${result.path} (${result.turnCount} turns)`];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function exportSessionJsonl({ engine, sessionStats, sessionState, sessionSource = "pi", projectMarchDir, now = new Date() }) {
|
|
45
|
+
const exportDir = join(projectMarchDir ?? join(engine.cwd, ".march"), "exports");
|
|
46
|
+
mkdirSync(exportDir, { recursive: true });
|
|
47
|
+
const sessionId = sessionStats?.sessionId ?? sessionState?.sessionId ?? "session";
|
|
48
|
+
const filename = `${formatTimestamp(now)}_${sanitizeFilename(sessionId)}.jsonl`;
|
|
49
|
+
const path = join(exportDir, filename);
|
|
50
|
+
const records = buildSessionJsonlRecords({ engine, sessionStats, sessionState, sessionSource, now });
|
|
51
|
+
writeFileSync(path, records.map((record) => JSON.stringify(record)).join("\n") + "\n", "utf8");
|
|
52
|
+
return { path, turnCount: engine.turns.length };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function exportSessionHtml({ engine, sessionStats, sessionState, sessionSource = "pi", projectMarchDir, now = new Date() }) {
|
|
56
|
+
const exportDir = join(projectMarchDir ?? join(engine.cwd, ".march"), "exports");
|
|
57
|
+
mkdirSync(exportDir, { recursive: true });
|
|
58
|
+
const sessionId = sessionStats?.sessionId ?? sessionState?.sessionId ?? "session";
|
|
59
|
+
const filename = `${formatTimestamp(now)}_${sanitizeFilename(sessionId)}.html`;
|
|
60
|
+
const path = join(exportDir, filename);
|
|
61
|
+
const records = buildSessionJsonlRecords({ engine, sessionStats, sessionState, sessionSource, now });
|
|
62
|
+
writeFileSync(path, buildSessionHtml(records), "utf8");
|
|
63
|
+
return { path, turnCount: engine.turns.length };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function createSessionGist({ engine, sessionStats, sessionState, sessionSource = "pi", now = new Date(), format = "html", env = process.env, fetchImpl = globalThis.fetch }) {
|
|
67
|
+
const token = env.GITHUB_TOKEN || env.GH_TOKEN;
|
|
68
|
+
if (!token) throw new Error("GITHUB_TOKEN or GH_TOKEN is required for /export gist");
|
|
69
|
+
if (typeof fetchImpl !== "function") throw new Error("fetch is not available for /export gist");
|
|
70
|
+
|
|
71
|
+
const records = buildSessionJsonlRecords({ engine, sessionStats, sessionState, sessionSource, now });
|
|
72
|
+
const session = records.find((record) => record.type === "session") ?? {};
|
|
73
|
+
const sessionId = session.sessionId ?? "session";
|
|
74
|
+
const extension = format === "html" ? "html" : "jsonl";
|
|
75
|
+
const filename = `${formatTimestamp(now)}_${sanitizeFilename(sessionId)}.${extension}`;
|
|
76
|
+
const content = format === "html"
|
|
77
|
+
? buildSessionHtml(records)
|
|
78
|
+
: records.map((record) => JSON.stringify(record)).join("\n") + "\n";
|
|
79
|
+
const response = await fetchImpl(`${env.GITHUB_API_URL || "https://api.github.com"}/gists`, {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: {
|
|
82
|
+
Accept: "application/vnd.github+json",
|
|
83
|
+
Authorization: `Bearer ${token}`,
|
|
84
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
85
|
+
"Content-Type": "application/json",
|
|
86
|
+
"User-Agent": "march-cli",
|
|
87
|
+
},
|
|
88
|
+
body: JSON.stringify({
|
|
89
|
+
description: `March session export: ${session.sessionName || sessionId}`,
|
|
90
|
+
public: false,
|
|
91
|
+
files: {
|
|
92
|
+
[filename]: { content },
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
});
|
|
96
|
+
const body = await response.json().catch(() => ({}));
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
throw new Error(`GitHub Gist create failed (${response.status}): ${body.message || response.statusText || "unknown error"}`);
|
|
99
|
+
}
|
|
100
|
+
if (!body.html_url) throw new Error("GitHub Gist create response did not include html_url");
|
|
101
|
+
return { url: body.html_url, filename };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function buildSessionJsonlRecords({ engine, sessionStats, sessionState, sessionSource = "pi", now = new Date() }) {
|
|
105
|
+
const sessionId = sessionStats?.sessionId ?? sessionState?.sessionId ?? null;
|
|
106
|
+
const records = [
|
|
107
|
+
{
|
|
108
|
+
type: "session",
|
|
109
|
+
exportedAt: now.toISOString(),
|
|
110
|
+
sessionId,
|
|
111
|
+
sessionName: engine.sessionName || null,
|
|
112
|
+
source: sessionSource,
|
|
113
|
+
cwd: engine.cwd,
|
|
114
|
+
provider: engine.provider,
|
|
115
|
+
modelId: engine.modelId,
|
|
116
|
+
thinkingLevel: engine.thinkingLevel,
|
|
117
|
+
sessionFile: sessionStats?.sessionFile ?? null,
|
|
118
|
+
stats: sessionStats ? {
|
|
119
|
+
userMessages: sessionStats.userMessages,
|
|
120
|
+
assistantMessages: sessionStats.assistantMessages,
|
|
121
|
+
toolCalls: sessionStats.toolCalls,
|
|
122
|
+
totalMessages: sessionStats.totalMessages,
|
|
123
|
+
tokens: sessionStats.tokens,
|
|
124
|
+
cost: sessionStats.cost,
|
|
125
|
+
} : null,
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
for (const turn of engine.turns) {
|
|
130
|
+
records.push({
|
|
131
|
+
type: "turn",
|
|
132
|
+
index: turn.index,
|
|
133
|
+
userMessage: turn.userMessage ?? "",
|
|
134
|
+
assistantMessage: turn.assistantMessage ?? "",
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return records;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function buildSessionHtml(records) {
|
|
142
|
+
const session = records.find((record) => record.type === "session") ?? {};
|
|
143
|
+
const turns = records.filter((record) => record.type === "turn");
|
|
144
|
+
return `<!doctype html>
|
|
145
|
+
<html lang="en">
|
|
146
|
+
<head>
|
|
147
|
+
<meta charset="utf-8">
|
|
148
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
149
|
+
<title>${escapeHtml(session.sessionName || session.sessionId || "March session")}</title>
|
|
150
|
+
<style>
|
|
151
|
+
:root { color-scheme: light dark; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
|
152
|
+
body { margin: 0; padding: 32px; line-height: 1.5; background: Canvas; color: CanvasText; }
|
|
153
|
+
main { max-width: 920px; margin: 0 auto; }
|
|
154
|
+
h1 { font-size: 28px; margin: 0 0 8px; }
|
|
155
|
+
.meta { color: color-mix(in srgb, CanvasText 65%, Canvas); margin-bottom: 24px; }
|
|
156
|
+
.turn { border-top: 1px solid color-mix(in srgb, CanvasText 20%, Canvas); padding: 20px 0; }
|
|
157
|
+
.label { font-weight: 700; margin: 16px 0 6px; }
|
|
158
|
+
pre { white-space: pre-wrap; word-wrap: break-word; margin: 0; padding: 12px; border-radius: 8px; background: color-mix(in srgb, CanvasText 8%, Canvas); }
|
|
159
|
+
</style>
|
|
160
|
+
</head>
|
|
161
|
+
<body>
|
|
162
|
+
<main>
|
|
163
|
+
<h1>${escapeHtml(session.sessionName || "March session")}</h1>
|
|
164
|
+
<div class="meta">${escapeHtml(formatSessionMeta(session))}</div>
|
|
165
|
+
${turns.map(formatTurnHtml).join("\n")}
|
|
166
|
+
</main>
|
|
167
|
+
</body>
|
|
168
|
+
</html>
|
|
169
|
+
`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function formatTurnHtml(turn) {
|
|
173
|
+
return `<section class="turn">
|
|
174
|
+
<h2>Turn ${escapeHtml(String(turn.index))}</h2>
|
|
175
|
+
<div class="label">User</div>
|
|
176
|
+
<pre>${escapeHtml(turn.userMessage)}</pre>
|
|
177
|
+
<div class="label">Assistant</div>
|
|
178
|
+
<pre>${escapeHtml(turn.assistantMessage || "(no assistant message)")}</pre>
|
|
179
|
+
</section>`;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function formatSessionMeta(session) {
|
|
183
|
+
return [
|
|
184
|
+
session.sessionId ? `session ${session.sessionId}` : null,
|
|
185
|
+
session.source ? `source ${session.source}` : null,
|
|
186
|
+
session.provider && session.modelId ? `${session.provider}/${session.modelId}` : null,
|
|
187
|
+
session.thinkingLevel ? `thinking ${session.thinkingLevel}` : null,
|
|
188
|
+
session.exportedAt ? `exported ${session.exportedAt}` : null,
|
|
189
|
+
].filter(Boolean).join(" | ");
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function escapeHtml(value) {
|
|
193
|
+
return String(value ?? "")
|
|
194
|
+
.replace(/&/g, "&")
|
|
195
|
+
.replace(/</g, "<")
|
|
196
|
+
.replace(/>/g, ">")
|
|
197
|
+
.replace(/"/g, """);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function formatTimestamp(date) {
|
|
201
|
+
return date.toISOString().replace(/[:.]/g, "-");
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function sanitizeFilename(value) {
|
|
205
|
+
return String(value || "session").replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
206
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export function listExtensionPathsCommand(extensionPaths = [], diagnostics = [], lifecycleState = null) {
|
|
2
|
+
const lines = [];
|
|
3
|
+
|
|
4
|
+
if (extensionPaths.length === 0) {
|
|
5
|
+
lines.push("(no configured extension paths)");
|
|
6
|
+
} else {
|
|
7
|
+
lines.push(
|
|
8
|
+
"Configured extension paths:",
|
|
9
|
+
...extensionPaths.map((extensionPath, index) => `${index + 1}. ${extensionPath}`),
|
|
10
|
+
"(paths are passed to the pi runtime host; this list does not guarantee successful extension startup)",
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (lifecycleState) {
|
|
15
|
+
lines.push(
|
|
16
|
+
"March lifecycle hooks:",
|
|
17
|
+
`- status: ${lifecycleState.status}`,
|
|
18
|
+
`- registered hooks: ${lifecycleState.registeredHookCount}`,
|
|
19
|
+
`- policy: ${lifecycleState.policy?.mode ?? "unknown"}; blocking by default: ${lifecycleState.policy?.defaultBlocking ? "yes" : "no"}`,
|
|
20
|
+
);
|
|
21
|
+
const deniedEffects = lifecycleState.policy?.deniedEffects ?? [];
|
|
22
|
+
if (deniedEffects.length > 0) {
|
|
23
|
+
lines.push(`- denied effects: ${deniedEffects.join(", ")}`);
|
|
24
|
+
}
|
|
25
|
+
const lifecycleDiagnostics = uniqueLifecycleDiagnostics(lifecycleState.diagnostics ?? [], diagnostics);
|
|
26
|
+
if (lifecycleDiagnostics.length > 0) {
|
|
27
|
+
lines.push("March lifecycle diagnostics:");
|
|
28
|
+
for (const diagnostic of lifecycleDiagnostics) {
|
|
29
|
+
lines.push(`- ${diagnostic.type ?? "info"}: ${diagnostic.message ?? String(diagnostic)}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (diagnostics.length === 0) {
|
|
35
|
+
lines.push("(no extension diagnostics)");
|
|
36
|
+
return lines;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
lines.push("Extension diagnostics:");
|
|
40
|
+
for (const diagnostic of diagnostics) {
|
|
41
|
+
lines.push(`- ${diagnostic.type ?? "info"}: ${diagnostic.message ?? String(diagnostic)}`);
|
|
42
|
+
}
|
|
43
|
+
return lines;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function uniqueLifecycleDiagnostics(lifecycleDiagnostics, extensionDiagnostics) {
|
|
47
|
+
const extensionKeys = new Set(extensionDiagnostics.map(formatDiagnosticKey));
|
|
48
|
+
return lifecycleDiagnostics.filter((diagnostic) => !extensionKeys.has(formatDiagnosticKey(diagnostic)));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function formatDiagnosticKey(diagnostic) {
|
|
52
|
+
return `${diagnostic?.type ?? "info"}:${diagnostic?.message ?? String(diagnostic)}`;
|
|
53
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function formatHelpLines() {
|
|
2
|
+
return [
|
|
3
|
+
"Commands: /new, /exit, /help, /hotkeys, /templates, /export jsonl, /export html, /export gist <jsonl|html>, /settings, /extensions, /providers, /providers <name>, /model, /models, /session, /status, /shell, /shell spawn [name], /save, /name, /copy, /mouse",
|
|
4
|
+
"Sessions: /session opens previous sessions and restores the selected one.",
|
|
5
|
+
"Shortcuts: Tab = toggle Do/Discuss, Esc = abort turn, Ctrl+C = abort turn / press twice to exit when idle, Ctrl+O = toggle tool output, Alt+S = shell pane, Alt+N = next shell, Alt+K/J = shell scroll, PageUp/PageDown = output scroll, Ctrl+G = external editor, Shift+Tab = thinking selector, Ctrl+T = thinking selector, Ctrl+L = model selector",
|
|
6
|
+
];
|
|
7
|
+
}
|