@sayknow-cli/coding-agent 0.2.4 → 0.2.6
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 +24 -0
- package/dist/types/cli/migrate-cli.d.ts +20 -0
- package/dist/types/cli/update-cli.d.ts +3 -0
- package/dist/types/commands/migrate.d.ts +33 -0
- package/dist/types/config/keybindings.d.ts +4 -0
- package/dist/types/config/model-registry.d.ts +3 -0
- package/dist/types/config/models-config-schema.d.ts +5 -0
- package/dist/types/config/settings-schema.d.ts +27 -0
- package/dist/types/harness-control-plane/storage.d.ts +2 -1
- package/dist/types/hooks/skill-state.d.ts +12 -4
- package/dist/types/lsp/startup-events.d.ts +1 -0
- package/dist/types/migrate/action-planner.d.ts +11 -0
- package/dist/types/migrate/adapters/claude-code.d.ts +2 -0
- package/dist/types/migrate/adapters/codex.d.ts +5 -0
- package/dist/types/migrate/adapters/index.d.ts +45 -0
- package/dist/types/migrate/adapters/opencode.d.ts +2 -0
- package/dist/types/migrate/executor.d.ts +2 -0
- package/dist/types/migrate/mcp-mapper.d.ts +20 -0
- package/dist/types/migrate/report.d.ts +18 -0
- package/dist/types/migrate/skill-normalizer.d.ts +27 -0
- package/dist/types/migrate/types.d.ts +126 -0
- package/dist/types/modes/components/custom-editor.d.ts +1 -1
- package/dist/types/modes/components/welcome.d.ts +3 -1
- package/dist/types/modes/interactive-mode.d.ts +3 -0
- package/dist/types/modes/prompt-action-autocomplete.d.ts +1 -0
- package/dist/types/modes/shared/agent-wire/unattended-audit.d.ts +1 -1
- package/dist/types/research-plan/index.d.ts +1 -0
- package/dist/types/research-plan/ledger.d.ts +33 -0
- package/dist/types/rlm/artifacts.d.ts +1 -1
- package/dist/types/runtime-mcp/config-writer.d.ts +26 -0
- package/dist/types/skc-runtime/deep-interview-recorder.d.ts +2 -0
- package/dist/types/skc-runtime/deep-interview-runtime.d.ts +2 -2
- package/dist/types/skc-runtime/goal-mode-request.d.ts +1 -1
- package/dist/types/skc-runtime/session-layout.d.ts +59 -0
- package/dist/types/skc-runtime/session-resolution.d.ts +47 -0
- package/dist/types/skc-runtime/state-graph.d.ts +1 -1
- package/dist/types/skc-runtime/state-runtime.d.ts +5 -4
- package/dist/types/skc-runtime/state-schema.d.ts +2 -0
- package/dist/types/skc-runtime/state-writer.d.ts +36 -7
- package/dist/types/skc-runtime/tmux-sessions.d.ts +2 -0
- package/dist/types/skc-runtime/ultragoal-runtime.d.ts +7 -4
- package/dist/types/skc-runtime/workflow-command-ref.d.ts +1 -1
- package/dist/types/skc-runtime/workflow-manifest.d.ts +1 -1
- package/dist/types/skill-state/active-state.d.ts +6 -11
- package/dist/types/skill-state/canonical-skills.d.ts +3 -0
- package/dist/types/skill-state/deep-interview-mutation-guard.d.ts +5 -0
- package/dist/types/skill-state/workflow-hud.d.ts +2 -0
- package/dist/types/task/spawn-gate.d.ts +1 -10
- package/package.json +7 -7
- package/scripts/build-binary.ts +0 -7
- package/src/cli/migrate-cli.ts +106 -0
- package/src/cli/setup-cli.ts +14 -1
- package/src/cli/update-cli.ts +53 -3
- package/src/cli.ts +1 -0
- package/src/commands/deep-interview.ts +2 -2
- package/src/commands/launch.ts +1 -1
- package/src/commands/migrate.ts +46 -0
- package/src/commands/state.ts +2 -1
- package/src/commands/team.ts +7 -3
- package/src/config/model-registry.ts +9 -2
- package/src/config/model-resolver.ts +13 -2
- package/src/config/models-config-schema.ts +1 -0
- package/src/config/settings-schema.ts +17 -0
- package/src/coordinator-mcp/policy.ts +10 -2
- package/src/defaults/skc/extensions/grok-cli-vendor/biome.json +0 -1
- package/src/defaults/skc/skills/deep-interview/SKILL.md +30 -24
- package/src/defaults/skc/skills/ralplan/SKILL.md +10 -4
- package/src/defaults/skc/skills/team/SKILL.md +51 -47
- package/src/defaults/skc/skills/ultragoal/SKILL.md +17 -13
- package/src/exec/bash-executor.ts +3 -1
- package/src/extensibility/custom-commands/loader.ts +0 -7
- package/src/extensibility/skc-plugins/injection.ts +23 -4
- package/src/extensibility/skc-plugins/state.ts +16 -1
- package/src/harness-control-plane/storage.ts +14 -4
- package/src/hooks/native-skill-hook.ts +38 -12
- package/src/hooks/skill-state.ts +178 -83
- package/src/internal-urls/docs-index.generated.ts +11 -9
- package/src/lsp/startup-events.ts +24 -0
- package/src/migrate/action-planner.ts +318 -0
- package/src/migrate/adapters/claude-code.ts +39 -0
- package/src/migrate/adapters/codex.ts +70 -0
- package/src/migrate/adapters/index.ts +277 -0
- package/src/migrate/adapters/opencode.ts +52 -0
- package/src/migrate/executor.ts +81 -0
- package/src/migrate/mcp-mapper.ts +152 -0
- package/src/migrate/report.ts +104 -0
- package/src/migrate/skill-normalizer.ts +80 -0
- package/src/migrate/types.ts +163 -0
- package/src/modes/bridge/bridge-mode.ts +2 -2
- package/src/modes/components/custom-editor.ts +30 -20
- package/src/modes/components/welcome.ts +20 -9
- package/src/modes/controllers/input-controller.ts +21 -3
- package/src/modes/interactive-mode.ts +27 -19
- package/src/modes/prompt-action-autocomplete.ts +11 -1
- package/src/modes/rpc/rpc-mode.ts +2 -2
- package/src/modes/shared/agent-wire/unattended-audit.ts +3 -2
- package/src/prompts/agents/init.md +1 -1
- package/src/prompts/system/plan-mode-active.md +1 -1
- package/src/prompts/tools/ast-grep.md +1 -1
- package/src/prompts/tools/search.md +1 -1
- package/src/prompts/tools/task.md +1 -2
- package/src/research-plan/index.ts +1 -0
- package/src/research-plan/ledger.ts +177 -0
- package/src/rlm/artifacts.ts +12 -3
- package/src/rlm/index.ts +7 -0
- package/src/runtime-mcp/config-writer.ts +46 -0
- package/src/session/agent-session.ts +43 -41
- package/src/session/session-manager.ts +19 -2
- package/src/setup/hermes/templates/operator-instructions.v1.md +8 -0
- package/src/setup/hermes-setup.ts +1 -1
- package/src/skc-runtime/deep-interview-recorder.ts +51 -18
- package/src/skc-runtime/deep-interview-runtime.ts +49 -23
- package/src/skc-runtime/goal-mode-request.ts +26 -11
- package/src/skc-runtime/launch-tmux.ts +68 -15
- package/src/skc-runtime/ralplan-runtime.ts +79 -50
- package/src/skc-runtime/session-layout.ts +180 -0
- package/src/skc-runtime/session-resolution.ts +217 -0
- package/src/skc-runtime/state-graph.ts +1 -2
- package/src/skc-runtime/state-migrations.ts +1 -0
- package/src/skc-runtime/state-runtime.ts +237 -114
- package/src/skc-runtime/state-schema.ts +2 -0
- package/src/skc-runtime/state-writer.ts +310 -42
- package/src/skc-runtime/team-runtime.ts +43 -19
- package/src/skc-runtime/tmux-sessions.ts +43 -2
- package/src/skc-runtime/ultragoal-guard.ts +45 -2
- package/src/skc-runtime/ultragoal-runtime.ts +121 -41
- package/src/skc-runtime/workflow-command-ref.ts +1 -2
- package/src/skc-runtime/workflow-manifest.ts +1 -2
- package/src/skill-state/active-state.ts +116 -129
- package/src/skill-state/canonical-skills.ts +4 -0
- package/src/skill-state/deep-interview-mutation-guard.ts +238 -111
- package/src/skill-state/workflow-hud.ts +4 -2
- package/src/skill-state/workflow-state-contract.ts +3 -3
- package/src/slash-commands/builtin-registry.ts +8 -4
- package/src/system-prompt.ts +11 -9
- package/src/task/agents.ts +1 -22
- package/src/task/index.ts +1 -41
- package/src/task/spawn-gate.ts +1 -38
- package/src/task/types.ts +1 -1
- package/src/tools/ask.ts +34 -12
- package/src/tools/ast-edit.ts +2 -2
- package/src/tools/computer.ts +58 -4
- package/src/utils/edit-mode.ts +1 -1
- package/dist/types/extensibility/custom-commands/bundled/review/index.d.ts +0 -10
- package/src/extensibility/custom-commands/bundled/review/index.ts +0 -456
- package/src/prompts/agents/explore.md +0 -58
- package/src/prompts/agents/plan.md +0 -49
- package/src/prompts/agents/reviewer.md +0 -141
- package/src/prompts/agents/task.md +0 -16
- package/src/prompts/review-request.md +0 -70
|
@@ -21,5 +21,5 @@ Searches files using powerful regex matching.
|
|
|
21
21
|
- You MUST use the built-in `search` tool for any content search. NEVER shell out to `grep`, `rg`, `ripgrep`, `ag`, `ack`, `git grep`, `awk`, `sed`-for-search, or any other CLI search via Bash — even for a single match, even "just to check quickly", even piped through other commands.
|
|
22
22
|
- Bash `grep`/`rg` loses `.gitignore` semantics, bypasses result limits, and wastes tokens. The `search` tool is faster, structured, and already wired into the workspace — there is no scenario where Bash search is preferable.
|
|
23
23
|
- If you catch yourself typing `grep`, `rg`, or `| grep` in a Bash command, stop and re-issue the lookup through the `search` tool instead.
|
|
24
|
-
- If the search is open-ended
|
|
24
|
+
- If the search is open-ended and requires multiple rounds across subsystems, delegate a bounded fact-finding task to an appropriate canonical role agent (`planner` for sequencing/context maps or `architect` for read-only architecture assessment) instead of chaining broad `search` calls yourself.
|
|
25
25
|
</critical>
|
|
@@ -28,13 +28,12 @@ Subagents have no conversation history. Every fact, file path, and direction the
|
|
|
28
28
|
{{/if}}
|
|
29
29
|
{{#if independentMode}}- `.inheritContext`: independent mode cannot inherit parent conversation. Omit it or set `"none"`; any non-`none` value is rejected before scheduling.{{/if}}
|
|
30
30
|
{{#if customSchemaEnabled}}- `schema`: JTD schema for expected structured output (do not put format rules in assignments){{/if}}
|
|
31
|
-
- `spawnPlan` (optional): required before any batch with more than 4 tasks
|
|
31
|
+
- `spawnPlan` (optional): required before any batch with more than 4 tasks; include whyParallel, whyNotLocal, independence, expectedReceiptShape, and maxInlineTokens.
|
|
32
32
|
{{#if isolationEnabled}}- `isolated`: run in isolated env; use when tasks edit overlapping files{{/if}}
|
|
33
33
|
</parameters>
|
|
34
34
|
|
|
35
35
|
<rules>
|
|
36
36
|
- HARD runtime gate: calls with more than 4 tasks are rejected before any child launches unless `spawnPlan` is complete.
|
|
37
|
-
- Reviewer->explore gate: a `reviewer` spawning `explore` is rejected before launch unless `spawnPlan` is complete, even for a single task.
|
|
38
37
|
- NEVER assign tasks to run project-wide build/test/lint. Caller verifies after the batch.
|
|
39
38
|
- **Subagents do not verify, lint, or format.** Every assignment MUST instruct the subagent to skip all gates and formatters. You run them once at the end across the union of changed files — avoids redundant runs and racing formatter passes.
|
|
40
39
|
{{#if ircEnabled}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ledger";
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
export type ResearchPlanConfidence = "low" | "medium" | "high";
|
|
2
|
+
|
|
3
|
+
export type ResearchEvidenceVerdict = "support" | "contradict" | "uncertain";
|
|
4
|
+
|
|
5
|
+
export interface ResearchPlanItem {
|
|
6
|
+
claim: string;
|
|
7
|
+
confidence: ResearchPlanConfidence;
|
|
8
|
+
unknowns: string[];
|
|
9
|
+
evidenceNeeded: string[];
|
|
10
|
+
counterexampleQueries: string[];
|
|
11
|
+
sourceConflictPolicy: string;
|
|
12
|
+
dropCondition: string;
|
|
13
|
+
verifierChecks: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ResearchEvidenceEntry {
|
|
17
|
+
claim: string;
|
|
18
|
+
source: string;
|
|
19
|
+
confidence: ResearchPlanConfidence;
|
|
20
|
+
verdict: ResearchEvidenceVerdict;
|
|
21
|
+
notes?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ResearchLedgerVerdict {
|
|
25
|
+
claim: string;
|
|
26
|
+
finalVerdict: "accepted" | "rejected" | "uncertain";
|
|
27
|
+
survivingSources: ResearchEvidenceEntry[];
|
|
28
|
+
rejectReason?: string;
|
|
29
|
+
unresolvedUnknowns: string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ResearchPlanValidationResult {
|
|
33
|
+
valid: boolean;
|
|
34
|
+
errors: string[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const CONFIDENCE_VALUES = new Set<ResearchPlanConfidence>(["low", "medium", "high"]);
|
|
38
|
+
const EVIDENCE_VERDICTS = new Set<ResearchEvidenceVerdict>(["support", "contradict", "uncertain"]);
|
|
39
|
+
|
|
40
|
+
function isNonEmptyString(value: unknown): value is string {
|
|
41
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function validateStringArray(value: unknown, field: string, minLength = 1): string[] {
|
|
45
|
+
if (!Array.isArray(value)) return [`${field} must be an array`];
|
|
46
|
+
if (value.length < minLength) return [`${field} must contain at least ${minLength} item(s)`];
|
|
47
|
+
return value.flatMap((item, index) =>
|
|
48
|
+
isNonEmptyString(item) ? [] : [`${field}[${index}] must be a non-empty string`],
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function validateResearchPlanItem(item: Partial<ResearchPlanItem>): ResearchPlanValidationResult {
|
|
53
|
+
const errors: string[] = [];
|
|
54
|
+
if (!isNonEmptyString(item.claim)) errors.push("claim must be a non-empty string");
|
|
55
|
+
if (!item.confidence || !CONFIDENCE_VALUES.has(item.confidence)) {
|
|
56
|
+
errors.push("confidence must be one of: low, medium, high");
|
|
57
|
+
}
|
|
58
|
+
errors.push(...validateStringArray(item.unknowns, "unknowns", 0));
|
|
59
|
+
errors.push(...validateStringArray(item.evidenceNeeded, "evidenceNeeded"));
|
|
60
|
+
errors.push(...validateStringArray(item.counterexampleQueries, "counterexampleQueries"));
|
|
61
|
+
if (!isNonEmptyString(item.sourceConflictPolicy)) errors.push("sourceConflictPolicy must be a non-empty string");
|
|
62
|
+
if (!isNonEmptyString(item.dropCondition)) errors.push("dropCondition must be a non-empty string");
|
|
63
|
+
errors.push(...validateStringArray(item.verifierChecks, "verifierChecks"));
|
|
64
|
+
return { valid: errors.length === 0, errors };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function validateResearchEvidenceEntry(entry: Partial<ResearchEvidenceEntry>): ResearchPlanValidationResult {
|
|
68
|
+
const errors: string[] = [];
|
|
69
|
+
if (!isNonEmptyString(entry.claim)) errors.push("claim must be a non-empty string");
|
|
70
|
+
if (!isNonEmptyString(entry.source)) errors.push("source must be a non-empty string");
|
|
71
|
+
if (!entry.confidence || !CONFIDENCE_VALUES.has(entry.confidence)) {
|
|
72
|
+
errors.push("confidence must be one of: low, medium, high");
|
|
73
|
+
}
|
|
74
|
+
if (!entry.verdict || !EVIDENCE_VERDICTS.has(entry.verdict)) {
|
|
75
|
+
errors.push("verdict must be one of: support, contradict, uncertain");
|
|
76
|
+
}
|
|
77
|
+
return { valid: errors.length === 0, errors };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function lower(value: string): string {
|
|
81
|
+
return value.toLowerCase();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function matchesDropCondition(item: ResearchPlanItem, evidence: ResearchEvidenceEntry[]): string | undefined {
|
|
85
|
+
const condition = lower(item.dropCondition);
|
|
86
|
+
const contradiction = evidence.find(entry => entry.verdict === "contradict");
|
|
87
|
+
if (contradiction && /(counterexample|contradict|conflict|falsif)/.test(condition)) {
|
|
88
|
+
return `dropCondition matched by contradictory source: ${contradiction.source}`;
|
|
89
|
+
}
|
|
90
|
+
const unresolved = evidence.find(entry => entry.verdict === "uncertain");
|
|
91
|
+
if (unresolved && /(unknown|unresolved|uncertain)/.test(condition)) {
|
|
92
|
+
return `dropCondition matched by unresolved evidence: ${unresolved.source}`;
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function sourceConflictReason(item: ResearchPlanItem, evidence: ResearchEvidenceEntry[]): string | undefined {
|
|
98
|
+
const supporting = evidence.filter(entry => entry.verdict === "support");
|
|
99
|
+
const contradicting = evidence.filter(entry => entry.verdict === "contradict");
|
|
100
|
+
if (supporting.length === 0 || contradicting.length === 0) return undefined;
|
|
101
|
+
const policy = lower(item.sourceConflictPolicy);
|
|
102
|
+
if (/(reject|drop|do not accept|prefer contradiction|requires resolution)/.test(policy)) {
|
|
103
|
+
return `sourceConflictPolicy rejected mixed support/contradiction (${supporting.length} support, ${contradicting.length} contradict)`;
|
|
104
|
+
}
|
|
105
|
+
return "source conflict remains unresolved";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function evaluateResearchLedger(
|
|
109
|
+
item: ResearchPlanItem,
|
|
110
|
+
evidence: readonly ResearchEvidenceEntry[],
|
|
111
|
+
): ResearchLedgerVerdict {
|
|
112
|
+
const relevantEvidence = evidence.filter(entry => entry.claim === item.claim);
|
|
113
|
+
const invalidItem = validateResearchPlanItem(item);
|
|
114
|
+
if (!invalidItem.valid) {
|
|
115
|
+
return {
|
|
116
|
+
claim: item.claim,
|
|
117
|
+
finalVerdict: "rejected",
|
|
118
|
+
survivingSources: [],
|
|
119
|
+
rejectReason: `invalid research plan item: ${invalidItem.errors.join("; ")}`,
|
|
120
|
+
unresolvedUnknowns: item.unknowns,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const invalidEvidence = relevantEvidence.flatMap(entry => validateResearchEvidenceEntry(entry).errors);
|
|
124
|
+
if (invalidEvidence.length > 0) {
|
|
125
|
+
return {
|
|
126
|
+
claim: item.claim,
|
|
127
|
+
finalVerdict: "rejected",
|
|
128
|
+
survivingSources: [],
|
|
129
|
+
rejectReason: `invalid evidence entry: ${invalidEvidence.join("; ")}`,
|
|
130
|
+
unresolvedUnknowns: item.unknowns,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
if (relevantEvidence.length === 0) {
|
|
134
|
+
return {
|
|
135
|
+
claim: item.claim,
|
|
136
|
+
finalVerdict: "uncertain",
|
|
137
|
+
survivingSources: [],
|
|
138
|
+
rejectReason: "no evidence collected for claim",
|
|
139
|
+
unresolvedUnknowns: item.unknowns,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const supporting = relevantEvidence.filter(entry => entry.verdict === "support");
|
|
143
|
+
const firstContradiction = relevantEvidence.find(entry => entry.verdict === "contradict");
|
|
144
|
+
let dropReason = matchesDropCondition(item, relevantEvidence) ?? sourceConflictReason(item, relevantEvidence);
|
|
145
|
+
// A counterexample with no surviving support falsifies the claim regardless of how the
|
|
146
|
+
// dropCondition / sourceConflictPolicy prose is worded. Without this, a purely contradicted
|
|
147
|
+
// claim would slip through as "uncertain" and reopen the hallucination survival path the
|
|
148
|
+
// evidence ledger exists to close (a contested claim already rejects via sourceConflictReason).
|
|
149
|
+
if (!dropReason && firstContradiction && supporting.length === 0) {
|
|
150
|
+
dropReason = `claim contradicted by counterexample with no supporting evidence: ${firstContradiction.source}`;
|
|
151
|
+
}
|
|
152
|
+
if (dropReason) {
|
|
153
|
+
return {
|
|
154
|
+
claim: item.claim,
|
|
155
|
+
finalVerdict: "rejected",
|
|
156
|
+
survivingSources: supporting,
|
|
157
|
+
rejectReason: dropReason,
|
|
158
|
+
unresolvedUnknowns: item.unknowns,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const uncertain = relevantEvidence.some(entry => entry.verdict === "uncertain");
|
|
162
|
+
if (uncertain || supporting.length === 0) {
|
|
163
|
+
return {
|
|
164
|
+
claim: item.claim,
|
|
165
|
+
finalVerdict: "uncertain",
|
|
166
|
+
survivingSources: supporting,
|
|
167
|
+
rejectReason: uncertain ? "unresolved uncertainty remains" : "no supporting evidence survived verification",
|
|
168
|
+
unresolvedUnknowns: item.unknowns,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
claim: item.claim,
|
|
173
|
+
finalVerdict: "accepted",
|
|
174
|
+
survivingSources: supporting,
|
|
175
|
+
unresolvedUnknowns: [],
|
|
176
|
+
};
|
|
177
|
+
}
|
package/src/rlm/artifacts.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* RLM session artifact layout under <cwd>/.skc/rlm/<
|
|
2
|
+
* RLM session artifact layout under <cwd>/.skc/_session-{skcSessionId}/rlm/<rlmSessionId>/.
|
|
3
|
+
*
|
|
4
|
+
* The SKC session id (process boundary) scopes the directory; the RLM session id
|
|
5
|
+
* names the individual research run within it. The two ids are kept distinct.
|
|
3
6
|
*/
|
|
4
7
|
import * as fs from "node:fs/promises";
|
|
5
8
|
import * as path from "node:path";
|
|
6
9
|
import { readNotebookDocument } from "../edit/notebook";
|
|
10
|
+
import { rlmArtifactRoot } from "../skc-runtime/session-layout";
|
|
11
|
+
import { resolveSkcSessionForWrite } from "../skc-runtime/session-resolution";
|
|
7
12
|
import type { RlmArtifactPaths } from "./types";
|
|
8
13
|
|
|
9
|
-
export const RLM_DIR_SEGMENT =
|
|
14
|
+
export const RLM_DIR_SEGMENT = "rlm";
|
|
10
15
|
|
|
11
16
|
const SESSION_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
12
17
|
|
|
@@ -25,7 +30,11 @@ export function resolveRlmArtifactPaths(cwd: string, sessionId: string): RlmArti
|
|
|
25
30
|
if (!isValidRlmSessionId(sessionId)) {
|
|
26
31
|
throw new Error(`Invalid RLM session id: ${JSON.stringify(sessionId)}`);
|
|
27
32
|
}
|
|
28
|
-
const dir =
|
|
33
|
+
const dir = rlmArtifactRoot(
|
|
34
|
+
cwd,
|
|
35
|
+
resolveSkcSessionForWrite(cwd, { envSessionId: process.env.SKC_SESSION_ID }).skcSessionId,
|
|
36
|
+
sessionId,
|
|
37
|
+
);
|
|
29
38
|
return {
|
|
30
39
|
dir,
|
|
31
40
|
notebookPath: path.join(dir, "notebook.ipynb"),
|
package/src/rlm/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { type RlmPreset, runRootCommand } from "../main";
|
|
|
15
15
|
import rlmReportCommandPrompt from "../prompts/system/rlm-report-command.md" with { type: "text" };
|
|
16
16
|
import type { CreateAgentSessionOptions } from "../sdk";
|
|
17
17
|
import type { AgentSession } from "../session/agent-session";
|
|
18
|
+
import { resolveSessionIdFromSources, writeSessionActivityMarker } from "../skc-runtime/session-resolution";
|
|
18
19
|
import {
|
|
19
20
|
ensureRlmSessionDir,
|
|
20
21
|
generateRlmSessionId,
|
|
@@ -231,6 +232,12 @@ async function writeRlmMetadata(input: {
|
|
|
231
232
|
successfulRuns: input.successfulRuns,
|
|
232
233
|
};
|
|
233
234
|
await Bun.write(input.paths.metadataPath, `${JSON.stringify(metadata, null, 2)}\n`);
|
|
235
|
+
// Best-effort: update the per-session activity marker so latest-session auto-detect
|
|
236
|
+
// accounts for RLM-only generated output (AC2). Never let marker failure break RLM.
|
|
237
|
+
const skcSessionId = resolveSessionIdFromSources({ envSessionId: process.env.SKC_SESSION_ID })?.skcSessionId;
|
|
238
|
+
if (skcSessionId) {
|
|
239
|
+
await writeSessionActivityMarker(input.cwd, skcSessionId, { writer: "rlm" }).catch(() => {});
|
|
240
|
+
}
|
|
234
241
|
}
|
|
235
242
|
|
|
236
243
|
export async function runRlmCommand(argv: string[]): Promise<void> {
|
|
@@ -149,6 +149,52 @@ export async function updateMCPServer(filePath: string, name: string, config: MC
|
|
|
149
149
|
await writeMCPConfigFile(filePath, updated);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Result of an {@link upsertMCPServer} call.
|
|
154
|
+
* - `added`: server did not exist and was written.
|
|
155
|
+
* - `updated`: server existed and was overwritten because `force` was set.
|
|
156
|
+
* - `skipped`: server existed and `force` was not set, so nothing was written.
|
|
157
|
+
*/
|
|
158
|
+
export type UpsertMCPServerResult =
|
|
159
|
+
| { status: "added" }
|
|
160
|
+
| { status: "updated" }
|
|
161
|
+
| { status: "skipped"; reason: "exists" };
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Add an MCP server, or overwrite an existing one only when `force` is set.
|
|
165
|
+
*
|
|
166
|
+
* Collision-aware wrapper over {@link addMCPServer} / {@link updateMCPServer} used by
|
|
167
|
+
* `skc migrate`. Never connects to the server. Reuses the underlying writers so the
|
|
168
|
+
* rest of the config file (including `disabledServers`) is preserved on update.
|
|
169
|
+
*
|
|
170
|
+
* @throws Error if the server name or config is invalid (validated before any write).
|
|
171
|
+
*/
|
|
172
|
+
export async function upsertMCPServer(
|
|
173
|
+
filePath: string,
|
|
174
|
+
name: string,
|
|
175
|
+
config: MCPServerConfig,
|
|
176
|
+
options: { force?: boolean } = {},
|
|
177
|
+
): Promise<UpsertMCPServerResult> {
|
|
178
|
+
// Validate name up front so an invalid name fails regardless of collision state.
|
|
179
|
+
const nameError = validateServerName(name);
|
|
180
|
+
if (nameError) {
|
|
181
|
+
throw new Error(nameError);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const existing = await getMCPServer(filePath, name);
|
|
185
|
+
if (existing) {
|
|
186
|
+
if (!options.force) {
|
|
187
|
+
return { status: "skipped", reason: "exists" };
|
|
188
|
+
}
|
|
189
|
+
// updateMCPServer preserves the rest of MCPConfigFile, incl. disabledServers.
|
|
190
|
+
await updateMCPServer(filePath, name, config);
|
|
191
|
+
return { status: "updated" };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
await addMCPServer(filePath, name, config);
|
|
195
|
+
return { status: "added" };
|
|
196
|
+
}
|
|
197
|
+
|
|
152
198
|
/**
|
|
153
199
|
* Remove an MCP server from a config file.
|
|
154
200
|
*
|
|
@@ -44,7 +44,6 @@ import {
|
|
|
44
44
|
type EmergencyCompactionSample,
|
|
45
45
|
emergencyCompactionReason,
|
|
46
46
|
estimateMessageTokensHeuristic,
|
|
47
|
-
estimateTokens,
|
|
48
47
|
generateBranchSummary,
|
|
49
48
|
generateHandoff,
|
|
50
49
|
prepareCompaction,
|
|
@@ -217,6 +216,11 @@ import { MCPManager } from "../runtime-mcp/manager";
|
|
|
217
216
|
import { deobfuscateSessionContext, type SecretObfuscator } from "../secrets/obfuscator";
|
|
218
217
|
import { formatNoCredentialOnboardingError, formatNoModelOnboardingError } from "../setup/model-onboarding-guidance";
|
|
219
218
|
import { buildSkcRuntimeSessionEnv, consumePendingGoalModeRequest } from "../skc-runtime/goal-mode-request";
|
|
219
|
+
import {
|
|
220
|
+
assertNonEmptySkcSessionId,
|
|
221
|
+
modeStatePath as sessionModeStatePath,
|
|
222
|
+
sessionStateDir,
|
|
223
|
+
} from "../skc-runtime/session-layout";
|
|
220
224
|
import { persistCoordinatorRuntimeStateFromEvent } from "../skc-runtime/session-state-sidecar";
|
|
221
225
|
import { writeArtifact } from "../skc-runtime/state-writer";
|
|
222
226
|
import { requestSkcWorkerIntegrationAttempt } from "../skc-runtime/team-runtime";
|
|
@@ -225,7 +229,7 @@ import {
|
|
|
225
229
|
readVisibleSkillActiveState,
|
|
226
230
|
syncSkillActiveState,
|
|
227
231
|
} from "../skill-state/active-state";
|
|
228
|
-
import {
|
|
232
|
+
import { assertWorkflowMutationAllowed } from "../skill-state/deep-interview-mutation-guard";
|
|
229
233
|
import { invalidateHostMetadata } from "../ssh/connection-manager";
|
|
230
234
|
import { resolveThinkingLevelForModel, toReasoningEffort } from "../thinking";
|
|
231
235
|
import {
|
|
@@ -313,13 +317,6 @@ export type AgentSessionEvent =
|
|
|
313
317
|
| { type: "thinking_level_changed"; thinkingLevel: ThinkingLevel | undefined }
|
|
314
318
|
| { type: "goal_updated"; goal: Goal | null; state?: GoalModeState };
|
|
315
319
|
|
|
316
|
-
/**
|
|
317
|
-
* Safe path component pattern used to validate session-id segments before
|
|
318
|
-
* joining them into `.skc/state` paths. Mirrors the regex used by the
|
|
319
|
-
* `skc state` runtime selector resolver.
|
|
320
|
-
*/
|
|
321
|
-
const SAFE_PATH_COMPONENT = /^[A-Za-z0-9_-][A-Za-z0-9._-]{0,63}$/;
|
|
322
|
-
|
|
323
320
|
function isUnderProjectSkc(cwd: string, targetPath: string): boolean {
|
|
324
321
|
const relative = path.relative(path.join(path.resolve(cwd), ".skc"), path.resolve(targetPath));
|
|
325
322
|
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
@@ -1371,21 +1368,17 @@ export class AgentSession {
|
|
|
1371
1368
|
getActiveSkillPhase(): string | undefined {
|
|
1372
1369
|
const active = this.#activeSkillState;
|
|
1373
1370
|
if (!active) return undefined;
|
|
1374
|
-
// Path safety: refuse to read mode-state files when the skill or
|
|
1375
|
-
// session-id are not safe path components. The `skill` tool
|
|
1376
|
-
// interprets undefined as a non-terminal phase, so chaining is
|
|
1377
|
-
// refused — there is no risk of bypassing the guard via a custom
|
|
1378
|
-
// skill name with `..` or a session-id with separators.
|
|
1379
1371
|
if (!isCanonicalSkcWorkflowSkill(active.skill)) return undefined;
|
|
1380
|
-
|
|
1381
|
-
return undefined;
|
|
1382
|
-
}
|
|
1372
|
+
const sessionId = active.sessionId ?? this.sessionManager.getSessionId();
|
|
1383
1373
|
try {
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
const filePath = path.join(
|
|
1374
|
+
assertNonEmptySkcSessionId(sessionId, "AgentSession.getActiveSkillPhase");
|
|
1375
|
+
// Keep the session-state-dir construction explicit here so the chain guard
|
|
1376
|
+
// refuses to fall back to a legacy root `.skc/state` read.
|
|
1377
|
+
const stateDir = sessionStateDir(this.sessionManager.getCwd(), sessionId);
|
|
1378
|
+
const filePath = path.join(
|
|
1379
|
+
stateDir,
|
|
1380
|
+
path.basename(sessionModeStatePath(this.sessionManager.getCwd(), sessionId, active.skill)),
|
|
1381
|
+
);
|
|
1389
1382
|
const raw = fs.readFileSync(filePath, "utf-8");
|
|
1390
1383
|
const parsed = JSON.parse(raw) as { current_phase?: unknown };
|
|
1391
1384
|
return typeof parsed.current_phase === "string" ? parsed.current_phase : undefined;
|
|
@@ -1475,7 +1468,7 @@ export class AgentSession {
|
|
|
1475
1468
|
}
|
|
1476
1469
|
const sanitized = sanitizeMessage(providerMessages[i]!);
|
|
1477
1470
|
if (!sanitized) continue;
|
|
1478
|
-
const messageTokens =
|
|
1471
|
+
const messageTokens = estimateMessageTokensHeuristic(sanitized);
|
|
1479
1472
|
if (maxTokens > 0 && approximateTokens + messageTokens > maxTokens) {
|
|
1480
1473
|
recordSkip("token-limit");
|
|
1481
1474
|
continue;
|
|
@@ -3764,7 +3757,7 @@ export class AgentSession {
|
|
|
3764
3757
|
* prompts or tool execution can run.
|
|
3765
3758
|
*/
|
|
3766
3759
|
#wrapToolForDeepInterviewMutationGuard<T extends AgentTool>(tool: T): T {
|
|
3767
|
-
if (!["edit", "write", "ast_edit"
|
|
3760
|
+
if (!["edit", "write", "ast_edit"].includes(tool.name)) return tool;
|
|
3768
3761
|
return new Proxy(tool, {
|
|
3769
3762
|
get: (target, prop) => {
|
|
3770
3763
|
if (prop !== "execute") return Reflect.get(target, prop, target);
|
|
@@ -3775,7 +3768,7 @@ export class AgentSession {
|
|
|
3775
3768
|
onUpdate: never,
|
|
3776
3769
|
ctx: never,
|
|
3777
3770
|
) => {
|
|
3778
|
-
await
|
|
3771
|
+
await assertWorkflowMutationAllowed({
|
|
3779
3772
|
cwd: this.sessionManager.getCwd(),
|
|
3780
3773
|
sessionId: this.sessionManager.getSessionId(),
|
|
3781
3774
|
tool: target,
|
|
@@ -9901,9 +9894,9 @@ export class AgentSession {
|
|
|
9901
9894
|
#estimateContextTokensForCompaction(pendingMessages: readonly AgentMessage[]): {
|
|
9902
9895
|
tokens: number;
|
|
9903
9896
|
} {
|
|
9904
|
-
const estimate = this.#estimateContextTokensWith(message => this.#
|
|
9897
|
+
const estimate = this.#estimateContextTokensWith(message => this.#estimateMessageCompactionDeltaTokens(message));
|
|
9905
9898
|
return {
|
|
9906
|
-
tokens: estimate.tokens + this.#
|
|
9899
|
+
tokens: estimate.tokens + this.#estimateMessagesCompactionDeltaTokens(pendingMessages),
|
|
9907
9900
|
};
|
|
9908
9901
|
}
|
|
9909
9902
|
|
|
@@ -9949,10 +9942,10 @@ export class AgentSession {
|
|
|
9949
9942
|
};
|
|
9950
9943
|
}
|
|
9951
9944
|
|
|
9952
|
-
#
|
|
9945
|
+
#estimateMessagesCompactionDeltaTokens(messages: readonly AgentMessage[]): number {
|
|
9953
9946
|
let tokens = 0;
|
|
9954
9947
|
for (const message of messages) {
|
|
9955
|
-
tokens += this.#
|
|
9948
|
+
tokens += this.#estimateMessageCompactionDeltaTokens(message);
|
|
9956
9949
|
}
|
|
9957
9950
|
return tokens;
|
|
9958
9951
|
}
|
|
@@ -9965,11 +9958,17 @@ export class AgentSession {
|
|
|
9965
9958
|
return tokens;
|
|
9966
9959
|
}
|
|
9967
9960
|
|
|
9968
|
-
|
|
9961
|
+
/**
|
|
9962
|
+
* Conservative inflation applied to the native-free chars/4 estimate of the
|
|
9963
|
+
* UNSENT context delta. chars/4 undercounts dense code/CJK, so we bias high
|
|
9964
|
+
* to compact slightly early rather than overflow the model window before the
|
|
9965
|
+
* next provider response re-anchors the exact count.
|
|
9966
|
+
*/
|
|
9967
|
+
#compactionDeltaInflation = 1.2;
|
|
9968
|
+
#compactionDeltaTokenCache = new WeakMap<AgentMessage, { len: number; tokens: number }>();
|
|
9969
9969
|
|
|
9970
|
-
/** Cheap content-size signal to invalidate the native token cache on mutation (growth). */
|
|
9971
9970
|
/**
|
|
9972
|
-
* Cheap content-size signal to invalidate the
|
|
9971
|
+
* Cheap content-size signal to invalidate the compaction-delta token cache on mutation. Recursively
|
|
9973
9972
|
* sums string lengths across the whole message (depth-bounded), so it covers every
|
|
9974
9973
|
* provider-visible shape (text/thinking/tool args, toolResult output, tool names, etc.)
|
|
9975
9974
|
* without allocating a serialized copy. A size-preserving in-place edit yields only a
|
|
@@ -9992,19 +9991,22 @@ export class AgentSession {
|
|
|
9992
9991
|
return 0;
|
|
9993
9992
|
}
|
|
9994
9993
|
|
|
9995
|
-
#
|
|
9996
|
-
//
|
|
9997
|
-
//
|
|
9998
|
-
//
|
|
9999
|
-
//
|
|
9994
|
+
#estimateMessageCompactionDeltaTokens(message: AgentMessage): number {
|
|
9995
|
+
// Provider usage anchors the already-sent context (see calculatePromptTokens); this
|
|
9996
|
+
// estimates only the UNSENT delta with the native-free chars/4 heuristic, inflated by
|
|
9997
|
+
// #compactionDeltaInflation so dense input cannot undercount us past the compaction
|
|
9998
|
+
// threshold before the next provider response re-anchors the exact count. Cached per
|
|
9999
|
+
// message object, invalidated by a cheap content-size signal; a rare size-preserving
|
|
10000
|
+
// in-place edit yields only a benign estimate drift, never wrong output.
|
|
10000
10001
|
const len = this.#messageTokenSize(message);
|
|
10001
|
-
const cached = this.#
|
|
10002
|
+
const cached = this.#compactionDeltaTokenCache.get(message);
|
|
10002
10003
|
if (cached && cached.len === len) return cached.tokens;
|
|
10003
|
-
let
|
|
10004
|
+
let heuristic = 0;
|
|
10004
10005
|
for (const llmMessage of convertToLlm([message])) {
|
|
10005
|
-
|
|
10006
|
+
heuristic += estimateMessageTokensHeuristic(llmMessage);
|
|
10006
10007
|
}
|
|
10007
|
-
|
|
10008
|
+
const tokens = Math.ceil(heuristic * this.#compactionDeltaInflation);
|
|
10009
|
+
this.#compactionDeltaTokenCache.set(message, { len, tokens });
|
|
10008
10010
|
return tokens;
|
|
10009
10011
|
}
|
|
10010
10012
|
|
|
@@ -1129,6 +1129,23 @@ function formatTimeAgo(date: Date): string {
|
|
|
1129
1129
|
return date.toLocaleDateString();
|
|
1130
1130
|
}
|
|
1131
1131
|
|
|
1132
|
+
async function movePathAcrossDevicesSafe(source: string, destination: string): Promise<void> {
|
|
1133
|
+
try {
|
|
1134
|
+
await fs.promises.rename(source, destination);
|
|
1135
|
+
return;
|
|
1136
|
+
} catch (error) {
|
|
1137
|
+
if (!hasFsCode(error, "EXDEV")) throw error;
|
|
1138
|
+
}
|
|
1139
|
+
const stat = await fs.promises.stat(source);
|
|
1140
|
+
if (stat.isDirectory()) {
|
|
1141
|
+
await fs.promises.cp(source, destination, { recursive: true, force: false, errorOnExist: true });
|
|
1142
|
+
await fs.promises.rm(source, { recursive: true, force: false });
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
await fs.promises.copyFile(source, destination, fs.constants.COPYFILE_EXCL);
|
|
1146
|
+
await fs.promises.unlink(source);
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1132
1149
|
const MAX_PERSIST_CHARS = 500_000;
|
|
1133
1150
|
const TRUNCATION_NOTICE = "\n\n[Session persistence truncated large content]";
|
|
1134
1151
|
/** Minimum base64 length to externalize to blob store (skip tiny inline images) */
|
|
@@ -2498,14 +2515,14 @@ export class SessionManager {
|
|
|
2498
2515
|
try {
|
|
2499
2516
|
// Guard: session file may not exist yet (no assistant messages persisted)
|
|
2500
2517
|
if (hadSessionFile) {
|
|
2501
|
-
await
|
|
2518
|
+
await movePathAcrossDevicesSafe(oldSessionFile, newSessionFile);
|
|
2502
2519
|
movedSessionFile = true;
|
|
2503
2520
|
}
|
|
2504
2521
|
|
|
2505
2522
|
try {
|
|
2506
2523
|
const stat = await fs.promises.stat(oldArtifactDir);
|
|
2507
2524
|
if (stat.isDirectory()) {
|
|
2508
|
-
await
|
|
2525
|
+
await movePathAcrossDevicesSafe(oldArtifactDir, newArtifactDir);
|
|
2509
2526
|
movedArtifactDir = true;
|
|
2510
2527
|
}
|
|
2511
2528
|
} catch (err) {
|
|
@@ -29,6 +29,14 @@ The Hermes bridge does not choose a model/provider. Generated setup configures `
|
|
|
29
29
|
|
|
30
30
|
Provider-specific commands are examples only, never product defaults.
|
|
31
31
|
|
|
32
|
+
## Visible routed-session fallback
|
|
33
|
+
|
|
34
|
+
If a Hermes/OpenClaw/Clawhip-style operator needs a human-visible, channel-routed SKC pane instead of a pure Coordinator MCP session, use the visible session pattern in [`docs/skc-session-clawhip-routing.md`](../../../../../../docs/skc-session-clawhip-routing.md).
|
|
35
|
+
|
|
36
|
+
Use that pattern only when the router must watch tmux output, send stale-session alerts, or inject follow-up prompts into the same visible pane. The short version is: prepare a dedicated worktree, register a stable tmux session through the host router, start interactive `skc`, wait for TUI readiness, inject the task prompt separately, and verify actual tool/work activity before reporting acceptance.
|
|
37
|
+
|
|
38
|
+
Do not put private channel ids, mention targets, socket names, tokens, or local routing policy into portable setup output. Keep those in the host/operator deployment.
|
|
39
|
+
|
|
32
40
|
## Safety
|
|
33
41
|
|
|
34
42
|
- Mutating tools require bridge startup mutation classes and per-call consent.
|
|
@@ -404,7 +404,7 @@ async function installConfig(spec: CoordinatorSetupSpec, force: boolean): Promis
|
|
|
404
404
|
|
|
405
405
|
async function runSmoke(spec: CoordinatorSetupSpec): Promise<HermesSetupResult["smoke"]> {
|
|
406
406
|
const requiredTools = [...COORDINATOR_MCP_TOOL_NAMES];
|
|
407
|
-
const server = createCoordinatorMcpServer({ env:
|
|
407
|
+
const server = createCoordinatorMcpServer({ env: renderHermesServerBlock(spec).env as NodeJS.ProcessEnv });
|
|
408
408
|
const listed = await server.handleJsonRpc({ jsonrpc: "2.0", id: 1, method: "tools/list", params: {} });
|
|
409
409
|
const listedResult = isRecord(listed.result) ? listed.result : {};
|
|
410
410
|
const tools = Array.isArray(listedResult.tools) ? listedResult.tools : [];
|