@gajae-code/coding-agent 0.11.3 → 0.11.5
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 +47 -0
- package/dist/types/cli/notify-cli.d.ts +5 -1
- package/dist/types/cli/worktree-cli.d.ts +8 -25
- package/dist/types/commands/gc.d.ts +4 -0
- package/dist/types/commands/worktree.d.ts +7 -32
- package/dist/types/config/settings-schema.d.ts +20 -0
- package/dist/types/export/html/template.generated.d.ts +1 -1
- package/dist/types/gjc-runtime/deep-interview-state.d.ts +28 -0
- package/dist/types/gjc-runtime/gc-runtime.d.ts +9 -0
- package/dist/types/gjc-runtime/launch-tmux.d.ts +3 -0
- package/dist/types/gjc-runtime/managed-owner-admission.d.ts +42 -0
- package/dist/types/gjc-runtime/managed-owner-supervisor.d.ts +41 -0
- package/dist/types/gjc-runtime/state-argv.d.ts +38 -0
- package/dist/types/gjc-runtime/tmux-owner-isolation.d.ts +9 -0
- package/dist/types/gjc-runtime/ultragoal-owner-loss-recovery.d.ts +94 -0
- package/dist/types/gjc-runtime/ultragoal-runtime.d.ts +1 -0
- package/dist/types/harness-control-plane/owner.d.ts +3 -1
- package/dist/types/internal-urls/local-protocol.d.ts +18 -0
- package/dist/types/main.d.ts +2 -2
- package/dist/types/modes/components/ansi-display-validator.d.ts +2 -0
- package/dist/types/modes/components/custom-editor.d.ts +8 -3
- package/dist/types/modes/components/notifications-settings-editor.d.ts +4 -0
- package/dist/types/modes/components/session-observer-overlay.d.ts +3 -1
- package/dist/types/modes/components/settings-selector.d.ts +2 -0
- package/dist/types/modes/components/tool-transcript-format.d.ts +77 -0
- package/dist/types/modes/components/transcript-viewer-overlay.d.ts +3 -0
- package/dist/types/modes/controllers/goal-mode-controller.d.ts +8 -1
- package/dist/types/modes/controllers/input-controller.d.ts +8 -2
- package/dist/types/modes/controllers/selector-controller.d.ts +15 -0
- package/dist/types/modes/shared/agent-wire/workflow-gate-broker.d.ts +3 -0
- package/dist/types/modes/shared/agent-wire/workflow-gate-types.d.ts +16 -0
- package/dist/types/plan-mode/approved-plan.d.ts +1 -0
- package/dist/types/runtime-mcp/manager.d.ts +2 -0
- package/dist/types/runtime-mcp/oauth-discovery.d.ts +12 -1
- package/dist/types/sdk/broker/broker.d.ts +1 -0
- package/dist/types/sdk/broker/discovery.d.ts +10 -0
- package/dist/types/sdk/broker/ensure.d.ts +24 -1
- package/dist/types/sdk/broker/internal.d.ts +3 -0
- package/dist/types/sdk/broker/session-index.d.ts +12 -0
- package/dist/types/sdk/broker/state-version.d.ts +2 -1
- package/dist/types/sdk/bus/chat-daemon-cli.d.ts +3 -1
- package/dist/types/sdk/bus/chat-daemon-control.d.ts +39 -4
- package/dist/types/sdk/bus/config-commands.d.ts +8 -0
- package/dist/types/sdk/bus/config.d.ts +22 -0
- package/dist/types/sdk/bus/index.d.ts +162 -2
- package/dist/types/sdk/bus/notification-service.d.ts +71 -8
- package/dist/types/sdk/bus/session-control.d.ts +11 -8
- package/dist/types/sdk/bus/telegram-daemon-cli.d.ts +5 -0
- package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +6 -3
- package/dist/types/sdk/bus/telegram-daemon-control.d.ts +23 -4
- package/dist/types/sdk/bus/telegram-daemon.d.ts +214 -20
- package/dist/types/sdk/session.d.ts +16 -1
- package/dist/types/secrets/index.d.ts +4 -2
- package/dist/types/secrets/obfuscator.d.ts +1 -1
- package/dist/types/session/agent-session.d.ts +31 -2
- package/dist/types/session/artifacts.d.ts +30 -8
- package/dist/types/session/internal/managed-session-scope.d.ts +7 -0
- package/dist/types/session/internal/managed-session-storage.d.ts +63 -6
- package/dist/types/session/session-manager.d.ts +88 -18
- package/dist/types/session/session-storage.d.ts +27 -0
- package/dist/types/session/streaming-output.d.ts +4 -0
- package/dist/types/task/executor.d.ts +9 -0
- package/dist/types/tool-discovery/tool-index.d.ts +2 -0
- package/dist/types/tools/ask.d.ts +87 -12
- package/dist/types/tools/bash-skill-urls.d.ts +2 -2
- package/dist/types/tools/browser/screenshot-format.d.ts +8 -0
- package/dist/types/tools/browser/tab-protocol.d.ts +11 -0
- package/dist/types/tools/browser/tab-supervisor.d.ts +1 -1
- package/dist/types/tools/browser/tab-worker-path-resolver.d.ts +2 -0
- package/dist/types/tools/browser/tab-worker-smoke.d.ts +16 -0
- package/dist/types/tools/index.d.ts +4 -0
- package/dist/types/tools/path-utils.d.ts +9 -14
- package/dist/types/tools/render-utils.d.ts +1 -8
- package/dist/types/tools/resource-gc.d.ts +14 -0
- package/dist/types/utils/image-loading.d.ts +23 -0
- package/dist/types/utils/image-resize.d.ts +2 -0
- package/dist/types/utils/pasted-image-loading.d.ts +39 -0
- package/dist/types/utils/pasted-image-path.d.ts +21 -19
- package/dist/types/web/scrapers/html-to-markdown.d.ts +5 -0
- package/dist/types/web/scrapers/types.d.ts +1 -5
- package/package.json +25 -9
- package/scripts/generate-sdk-operation-inventory.ts +2 -0
- package/scripts/run-threat-model-check.ts +60 -0
- package/src/cli/notify-cli.ts +40 -18
- package/src/cli/worktree-cli.ts +9 -287
- package/src/cli.ts +10 -9
- package/src/commands/gc.ts +11 -1
- package/src/commands/sdk.ts +10 -4
- package/src/commands/worktree.ts +10 -53
- package/src/config/model-profiles.ts +15 -15
- package/src/config/settings-schema.ts +17 -0
- package/src/daemon/runtime.ts +2 -2
- package/src/defaults/gjc/skills/deep-interview/SKILL.md +70 -49
- package/src/defaults/gjc/skills/ralplan/SKILL.md +0 -6
- package/src/defaults/gjc/skills/team/SKILL.md +7 -9
- package/src/defaults/gjc/skills/ultragoal/SKILL.md +0 -2
- package/src/eval/js/shared/runtime.ts +1 -1
- package/src/eval/py/index.ts +2 -2
- package/src/export/html/template.generated.ts +1 -1
- package/src/extensibility/plugins/marketplace/manager.ts +94 -10
- package/src/gjc-runtime/deep-interview-recorder.ts +7 -0
- package/src/gjc-runtime/deep-interview-runtime.ts +10 -0
- package/src/gjc-runtime/deep-interview-state.ts +127 -3
- package/src/gjc-runtime/gc-render.ts +19 -1
- package/src/gjc-runtime/gc-runtime.ts +68 -3
- package/src/gjc-runtime/launch-tmux.ts +61 -6
- package/src/gjc-runtime/managed-owner-admission.ts +352 -0
- package/src/gjc-runtime/managed-owner-supervisor.ts +162 -0
- package/src/gjc-runtime/state-argv.ts +292 -0
- package/src/gjc-runtime/state-runtime.ts +80 -222
- package/src/gjc-runtime/team-runtime.ts +1 -1
- package/src/gjc-runtime/tmux-owner-isolation.ts +117 -0
- package/src/gjc-runtime/ultragoal-owner-loss-recovery.ts +328 -0
- package/src/gjc-runtime/ultragoal-runtime.ts +14 -0
- package/src/harness-control-plane/owner.ts +59 -3
- package/src/hindsight/client.ts +65 -2
- package/src/internal-urls/agent-protocol.ts +76 -5
- package/src/internal-urls/docs-index.generated.ts +7 -6
- package/src/internal-urls/local-protocol.ts +416 -18
- package/src/lsp/index.ts +4 -88
- package/src/main.ts +37 -13
- package/src/modes/acp/acp-agent.ts +8 -0
- package/src/modes/components/ansi-display-validator.ts +54 -0
- package/src/modes/components/custom-editor.ts +103 -32
- package/src/modes/components/custom-provider-wizard.ts +26 -1
- package/src/modes/components/notifications-settings-editor.ts +26 -2
- package/src/modes/components/session-observer-overlay.ts +40 -37
- package/src/modes/components/settings-selector.ts +3 -1
- package/src/modes/components/tool-transcript-format.ts +393 -0
- package/src/modes/components/transcript-viewer-overlay.ts +63 -1
- package/src/modes/controllers/goal-mode-controller.ts +20 -1
- package/src/modes/controllers/input-controller.ts +98 -37
- package/src/modes/controllers/plan-mode-controller.ts +2 -0
- package/src/modes/controllers/runtime-mcp-command-controller.ts +3 -0
- package/src/modes/controllers/selector-controller.ts +71 -9
- package/src/modes/interactive-mode.ts +14 -2
- package/src/modes/shared/agent-wire/deep-interview-gate.ts +31 -1
- package/src/modes/shared/agent-wire/workflow-gate-broker.ts +17 -1
- package/src/modes/shared/agent-wire/workflow-gate-schema.ts +4 -2
- package/src/modes/shared/agent-wire/workflow-gate-types.ts +120 -3
- package/src/plan-mode/approved-plan.ts +3 -1
- package/src/prompts/agents/architect.md +1 -0
- package/src/prompts/agents/critic.md +1 -0
- package/src/prompts/system/custom-system-prompt.md +1 -1
- package/src/prompts/system/system-prompt.md +2 -1
- package/src/prompts/tools/lsp.md +3 -3
- package/src/runtime-mcp/manager.ts +16 -1
- package/src/runtime-mcp/oauth-discovery.ts +116 -26
- package/src/sdk/broker/broker.ts +139 -32
- package/src/sdk/broker/discovery.ts +125 -0
- package/src/sdk/broker/ensure.ts +103 -19
- package/src/sdk/broker/internal.ts +10 -0
- package/src/sdk/broker/session-index.ts +309 -38
- package/src/sdk/broker/state-version.ts +5 -2
- package/src/sdk/bus/chat-daemon-cli.ts +72 -10
- package/src/sdk/bus/chat-daemon-control.ts +526 -130
- package/src/sdk/bus/chat-daemon-runtime.ts +1 -0
- package/src/sdk/bus/config-commands.ts +22 -0
- package/src/sdk/bus/config.ts +37 -0
- package/src/sdk/bus/index.ts +384 -92
- package/src/sdk/bus/lifecycle-control-runtime.ts +53 -3
- package/src/sdk/bus/notification-service.ts +284 -62
- package/src/sdk/bus/recent-activity.ts +14 -5
- package/src/sdk/bus/session-control.ts +150 -44
- package/src/sdk/bus/telegram-daemon-cli.ts +20 -14
- package/src/sdk/bus/telegram-daemon-contract.ts +6 -3
- package/src/sdk/bus/telegram-daemon-control.ts +294 -76
- package/src/sdk/bus/telegram-daemon.ts +1842 -281
- package/src/sdk/protocol/operation-inventory.generated.json +11 -0
- package/src/sdk/session.ts +155 -27
- package/src/secrets/index.ts +53 -10
- package/src/secrets/obfuscator.ts +21 -18
- package/src/secrets/regex.ts +2 -0
- package/src/session/agent-session.ts +495 -253
- package/src/session/artifacts.ts +188 -23
- package/src/session/context-estimation.ts +7 -2
- package/src/session/internal/managed-session-scope.ts +215 -39
- package/src/session/internal/managed-session-storage.ts +1152 -46
- package/src/session/session-manager.ts +1055 -148
- package/src/session/session-storage.ts +109 -11
- package/src/session/streaming-output.ts +6 -0
- package/src/task/executor.ts +71 -26
- package/src/task/index.ts +63 -20
- package/src/tool-discovery/tool-index.ts +18 -0
- package/src/tools/ask.ts +329 -57
- package/src/tools/bash-allowed-prefixes.ts +79 -29
- package/src/tools/bash-skill-urls.ts +14 -3
- package/src/tools/bash.ts +2 -2
- package/src/tools/browser/launch.ts +3 -1
- package/src/tools/browser/readable.ts +1 -1
- package/src/tools/browser/screenshot-format.ts +34 -0
- package/src/tools/browser/tab-protocol.ts +3 -0
- package/src/tools/browser/tab-supervisor.ts +125 -122
- package/src/tools/browser/tab-worker-entry.ts +33 -14
- package/src/tools/browser/tab-worker-path-resolver.ts +67 -0
- package/src/tools/browser/tab-worker-smoke.ts +87 -0
- package/src/tools/browser/tab-worker.ts +7 -5
- package/src/tools/index.ts +4 -0
- package/src/tools/path-utils.ts +42 -35
- package/src/tools/plan-mode-guard.ts +1 -0
- package/src/tools/read.ts +7 -1
- package/src/tools/render-utils.ts +1 -27
- package/src/tools/resource-gc.ts +123 -34
- package/src/tools/sqlite-reader.ts +3 -2
- package/src/tools/subagent.ts +2 -0
- package/src/utils/image-loading.ts +85 -34
- package/src/utils/image-resize.ts +16 -9
- package/src/utils/pasted-image-loading.ts +514 -0
- package/src/utils/pasted-image-path.ts +223 -98
- package/src/web/scrapers/html-to-markdown.ts +68 -0
- package/src/web/scrapers/readthedocs.ts +1 -1
- package/src/web/scrapers/types.ts +1 -68
- package/src/web/search/providers/openai-compatible.ts +76 -23
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { CANONICAL_GJC_WORKFLOW_SKILLS, type CanonicalGjcWorkflowSkill } from "../skill-state/canonical-skills";
|
|
2
|
+
import { typedArgsFor } from "./workflow-manifest";
|
|
3
|
+
|
|
4
|
+
export type StateAction =
|
|
5
|
+
| "read"
|
|
6
|
+
| "write"
|
|
7
|
+
| "clear"
|
|
8
|
+
| "contract"
|
|
9
|
+
| "handoff"
|
|
10
|
+
| "graph"
|
|
11
|
+
| "prune"
|
|
12
|
+
| "gc"
|
|
13
|
+
| "migrate"
|
|
14
|
+
| "status"
|
|
15
|
+
| "doctor";
|
|
16
|
+
|
|
17
|
+
export const STATE_ACTION_NAMES: ReadonlySet<StateAction> = new Set([
|
|
18
|
+
"read",
|
|
19
|
+
"write",
|
|
20
|
+
"clear",
|
|
21
|
+
"contract",
|
|
22
|
+
"handoff",
|
|
23
|
+
"graph",
|
|
24
|
+
"prune",
|
|
25
|
+
"gc",
|
|
26
|
+
"migrate",
|
|
27
|
+
"status",
|
|
28
|
+
"doctor",
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
export const STATE_FLAGS_WITH_VALUES: ReadonlySet<string> = new Set([
|
|
32
|
+
"--input",
|
|
33
|
+
"--mode",
|
|
34
|
+
"--session-id",
|
|
35
|
+
"--thread-id",
|
|
36
|
+
"--turn-id",
|
|
37
|
+
"--to",
|
|
38
|
+
"--skill",
|
|
39
|
+
"--format",
|
|
40
|
+
"--older-than",
|
|
41
|
+
"--status",
|
|
42
|
+
"--fields",
|
|
43
|
+
"--since",
|
|
44
|
+
"--limit",
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
export const STATE_BOOLEAN_FLAGS: ReadonlySet<string> = new Set([
|
|
48
|
+
"--json",
|
|
49
|
+
"--replace",
|
|
50
|
+
"--hard",
|
|
51
|
+
"--dry-run",
|
|
52
|
+
"--migrate",
|
|
53
|
+
"--compact",
|
|
54
|
+
"--history",
|
|
55
|
+
"--force",
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
export interface StateFlagOccurrence {
|
|
59
|
+
name: string;
|
|
60
|
+
index: number;
|
|
61
|
+
value?: string;
|
|
62
|
+
arity: "boolean" | "value";
|
|
63
|
+
form: "separate" | "attached";
|
|
64
|
+
malformed: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface StateSelectorCandidate {
|
|
68
|
+
source: "mode" | "positional" | "input.mode" | "input.skill";
|
|
69
|
+
value: string | undefined;
|
|
70
|
+
index: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type StateInputKind = "empty" | "inline" | "file" | "invalid";
|
|
74
|
+
|
|
75
|
+
export interface StateInputClassification {
|
|
76
|
+
index: number;
|
|
77
|
+
raw: string;
|
|
78
|
+
kind: StateInputKind;
|
|
79
|
+
selectors: StateSelectorCandidate[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface StateArgvClassification {
|
|
83
|
+
argv: readonly string[];
|
|
84
|
+
action: StateAction;
|
|
85
|
+
effectiveAction: StateAction;
|
|
86
|
+
positionalSkill?: string;
|
|
87
|
+
positionals: readonly string[];
|
|
88
|
+
flags: readonly StateFlagOccurrence[];
|
|
89
|
+
unknownFlags: readonly string[];
|
|
90
|
+
inputs: readonly StateInputClassification[];
|
|
91
|
+
runtimeSelectorCandidates: readonly StateSelectorCandidate[];
|
|
92
|
+
selectorCandidates: readonly StateSelectorCandidate[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function normalizedFlagName(arg: string): string | undefined {
|
|
96
|
+
if (!arg.startsWith("--")) return undefined;
|
|
97
|
+
const equalsIndex = arg.indexOf("=");
|
|
98
|
+
return equalsIndex < 0 ? arg : arg.slice(0, equalsIndex);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function normalizedSelector(value: unknown): string | undefined {
|
|
102
|
+
return typeof value === "string" ? value.trim() || undefined : undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface StatePositional {
|
|
106
|
+
value: string;
|
|
107
|
+
index: number;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function parseRuntimePositionals(argv: readonly string[]): StatePositional[] {
|
|
111
|
+
const positionals: StatePositional[] = [];
|
|
112
|
+
let skipNext = false;
|
|
113
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
114
|
+
const arg = argv[index]!;
|
|
115
|
+
if (skipNext) {
|
|
116
|
+
skipNext = false;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (STATE_FLAGS_WITH_VALUES.has(arg)) {
|
|
120
|
+
skipNext = true;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (!arg.startsWith("-")) positionals.push({ value: arg, index });
|
|
124
|
+
}
|
|
125
|
+
return positionals;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function parseAction(positionals: readonly StatePositional[]): {
|
|
129
|
+
action: StateAction;
|
|
130
|
+
positionalSkill?: string;
|
|
131
|
+
positionalSkillIndex: number;
|
|
132
|
+
} {
|
|
133
|
+
const [first, second] = positionals;
|
|
134
|
+
if (first?.value && STATE_ACTION_NAMES.has(first.value as StateAction)) {
|
|
135
|
+
return {
|
|
136
|
+
action: first.value as StateAction,
|
|
137
|
+
...(second?.value ? { positionalSkill: second.value } : {}),
|
|
138
|
+
positionalSkillIndex: second?.value ? second.index : -1,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (first?.value && second?.value && STATE_ACTION_NAMES.has(second.value as StateAction)) {
|
|
142
|
+
return { action: second.value as StateAction, positionalSkill: first.value, positionalSkillIndex: first.index };
|
|
143
|
+
}
|
|
144
|
+
if (first?.value && !second?.value) {
|
|
145
|
+
return { action: "read", positionalSkill: first.value, positionalSkillIndex: first.index };
|
|
146
|
+
}
|
|
147
|
+
return { action: "read", positionalSkillIndex: -1 };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function stateFlagArities(
|
|
151
|
+
action: StateAction,
|
|
152
|
+
positionalSkill: string | undefined,
|
|
153
|
+
): ReadonlyMap<string, "boolean" | "value"> {
|
|
154
|
+
const arities = new Map<string, "boolean" | "value">();
|
|
155
|
+
for (const flag of STATE_FLAGS_WITH_VALUES) arities.set(flag, "value");
|
|
156
|
+
for (const flag of STATE_BOOLEAN_FLAGS) arities.set(flag, "boolean");
|
|
157
|
+
|
|
158
|
+
const skills =
|
|
159
|
+
positionalSkill && CANONICAL_GJC_WORKFLOW_SKILLS.includes(positionalSkill as CanonicalGjcWorkflowSkill)
|
|
160
|
+
? [positionalSkill as CanonicalGjcWorkflowSkill]
|
|
161
|
+
: CANONICAL_GJC_WORKFLOW_SKILLS;
|
|
162
|
+
for (const skill of skills) {
|
|
163
|
+
for (const arg of typedArgsFor(skill, action)) {
|
|
164
|
+
const name = `--${arg.name}`;
|
|
165
|
+
if (!arities.has(name)) arities.set(name, arg.type === "boolean" ? "boolean" : "value");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return arities;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function classifyInput(occurrence: StateFlagOccurrence): StateInputClassification {
|
|
172
|
+
const raw = occurrence.value ?? "";
|
|
173
|
+
const trimmed = raw.trim();
|
|
174
|
+
if (!trimmed) return { index: occurrence.index, raw, kind: "empty", selectors: [] };
|
|
175
|
+
if (trimmed.startsWith("@")) return { index: occurrence.index, raw, kind: "file", selectors: [] };
|
|
176
|
+
try {
|
|
177
|
+
const payload = JSON.parse(trimmed) as unknown;
|
|
178
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
179
|
+
return { index: occurrence.index, raw, kind: "invalid", selectors: [] };
|
|
180
|
+
}
|
|
181
|
+
const record = payload as Record<string, unknown>;
|
|
182
|
+
return {
|
|
183
|
+
index: occurrence.index,
|
|
184
|
+
raw,
|
|
185
|
+
kind: "inline",
|
|
186
|
+
selectors: [
|
|
187
|
+
{ source: "input.mode", value: normalizedSelector(record.mode), index: occurrence.index },
|
|
188
|
+
{ source: "input.skill", value: normalizedSelector(record.skill), index: occurrence.index },
|
|
189
|
+
],
|
|
190
|
+
};
|
|
191
|
+
} catch {
|
|
192
|
+
return { index: occurrence.index, raw, kind: "invalid", selectors: [] };
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function firstStateFlagValue(classification: StateArgvClassification, name: string): string | undefined {
|
|
197
|
+
const index = classification.argv.indexOf(name);
|
|
198
|
+
return index < 0 ? undefined : classification.argv[index + 1];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function classifyStateArgv(argv: readonly string[]): StateArgvClassification {
|
|
202
|
+
const preservedArgv = [...argv];
|
|
203
|
+
const positionalEntries = parseRuntimePositionals(preservedArgv);
|
|
204
|
+
const positionals = positionalEntries.map(positional => positional.value);
|
|
205
|
+
const { action, positionalSkill, positionalSkillIndex } = parseAction(positionalEntries);
|
|
206
|
+
const flagArities = stateFlagArities(action, positionalSkill);
|
|
207
|
+
const flags: StateFlagOccurrence[] = [];
|
|
208
|
+
const unknownFlags: string[] = [];
|
|
209
|
+
|
|
210
|
+
for (let index = 0; index < preservedArgv.length; index += 1) {
|
|
211
|
+
const arg = preservedArgv[index]!;
|
|
212
|
+
const name = normalizedFlagName(arg);
|
|
213
|
+
if (!name) continue;
|
|
214
|
+
const arity = flagArities.get(name);
|
|
215
|
+
if (!arity) {
|
|
216
|
+
unknownFlags.push(name);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (arg !== name) {
|
|
220
|
+
flags.push({
|
|
221
|
+
name,
|
|
222
|
+
index,
|
|
223
|
+
value: arg.slice(name.length + 1),
|
|
224
|
+
arity,
|
|
225
|
+
form: "attached",
|
|
226
|
+
malformed: true,
|
|
227
|
+
});
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (arity === "boolean") {
|
|
231
|
+
flags.push({ name, index, arity, form: "separate", malformed: false });
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const value = preservedArgv[index + 1];
|
|
235
|
+
flags.push({
|
|
236
|
+
name,
|
|
237
|
+
index,
|
|
238
|
+
...(value === undefined ? {} : { value }),
|
|
239
|
+
arity,
|
|
240
|
+
form: "separate",
|
|
241
|
+
malformed: value === undefined || value.startsWith("--"),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
const effectiveAction = action === "read" && preservedArgv.includes("--migrate") ? "migrate" : action;
|
|
245
|
+
|
|
246
|
+
const modeFlags = flags.filter(flag => flag.name === "--mode" && flag.form === "separate");
|
|
247
|
+
const inputFlags = flags.filter(flag => flag.name === "--input" && flag.form === "separate");
|
|
248
|
+
const inputs = inputFlags.map(classifyInput);
|
|
249
|
+
const positionalCandidate: StateSelectorCandidate = {
|
|
250
|
+
source: "positional",
|
|
251
|
+
value: normalizedSelector(positionalSkill),
|
|
252
|
+
index: positionalSkillIndex,
|
|
253
|
+
};
|
|
254
|
+
const modeCandidates = modeFlags.map(flag => ({
|
|
255
|
+
source: "mode" as const,
|
|
256
|
+
value: normalizedSelector(flag.value),
|
|
257
|
+
index: flag.index,
|
|
258
|
+
}));
|
|
259
|
+
const selectorCandidates = [positionalCandidate, ...modeCandidates, ...inputs.flatMap(input => input.selectors)];
|
|
260
|
+
const firstModeIndex = preservedArgv.indexOf("--mode");
|
|
261
|
+
const firstModeCandidate: StateSelectorCandidate = {
|
|
262
|
+
source: "mode",
|
|
263
|
+
value: normalizedSelector(firstModeIndex < 0 ? undefined : preservedArgv[firstModeIndex + 1]),
|
|
264
|
+
index: firstModeIndex,
|
|
265
|
+
};
|
|
266
|
+
const firstInputIndex = preservedArgv.indexOf("--input");
|
|
267
|
+
const firstInput =
|
|
268
|
+
firstInputIndex < 0
|
|
269
|
+
? undefined
|
|
270
|
+
: classifyInput({
|
|
271
|
+
name: "--input",
|
|
272
|
+
index: firstInputIndex,
|
|
273
|
+
value: preservedArgv[firstInputIndex + 1],
|
|
274
|
+
arity: "value",
|
|
275
|
+
form: "separate",
|
|
276
|
+
malformed: false,
|
|
277
|
+
});
|
|
278
|
+
const runtimeSelectorCandidates = [firstModeCandidate, positionalCandidate, ...(firstInput?.selectors ?? [])];
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
argv: preservedArgv,
|
|
282
|
+
action,
|
|
283
|
+
effectiveAction,
|
|
284
|
+
...(positionalSkill === undefined ? {} : { positionalSkill }),
|
|
285
|
+
positionals,
|
|
286
|
+
flags,
|
|
287
|
+
unknownFlags,
|
|
288
|
+
inputs,
|
|
289
|
+
runtimeSelectorCandidates,
|
|
290
|
+
selectorCandidates,
|
|
291
|
+
};
|
|
292
|
+
}
|