@gajae-code/coding-agent 0.2.2 → 0.2.4

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.
Files changed (96) hide show
  1. package/CHANGELOG.md +45 -8600
  2. package/dist/types/cli/setup-cli.d.ts +1 -0
  3. package/dist/types/cli/update-cli.d.ts +3 -0
  4. package/dist/types/commands/deep-interview.d.ts +41 -0
  5. package/dist/types/commands/setup.d.ts +3 -0
  6. package/dist/types/config/settings-schema.d.ts +56 -0
  7. package/dist/types/defaults/gjc-defaults.d.ts +19 -6
  8. package/dist/types/discovery/helpers.d.ts +2 -0
  9. package/dist/types/extensibility/extensions/types.d.ts +6 -0
  10. package/dist/types/gjc-runtime/deep-interview-runtime.d.ts +18 -0
  11. package/dist/types/hooks/skill-state.d.ts +5 -0
  12. package/dist/types/memories/index.d.ts +1 -1
  13. package/dist/types/memory-backend/local-backend.d.ts +3 -3
  14. package/dist/types/modes/components/hook-selector.d.ts +7 -0
  15. package/dist/types/modes/components/settings-selector.d.ts +3 -1
  16. package/dist/types/modes/controllers/selector-controller.d.ts +1 -0
  17. package/dist/types/modes/interactive-mode.d.ts +1 -0
  18. package/dist/types/modes/theme/defaults/index.d.ts +126 -0
  19. package/dist/types/modes/theme/theme.d.ts +5 -0
  20. package/dist/types/modes/types.d.ts +1 -0
  21. package/dist/types/modes/utils/context-usage.d.ts +6 -2
  22. package/dist/types/sdk.d.ts +6 -2
  23. package/dist/types/session/agent-session.d.ts +45 -1
  24. package/dist/types/session/session-manager.d.ts +3 -0
  25. package/dist/types/setup/model-onboarding-guidance.d.ts +1 -0
  26. package/dist/types/setup/provider-onboarding.d.ts +29 -5
  27. package/dist/types/skill-state/active-state.d.ts +26 -1
  28. package/dist/types/skill-state/deep-interview-mutation-guard.d.ts +1 -1
  29. package/dist/types/skill-state/initial-phase.d.ts +12 -0
  30. package/dist/types/task/executor.d.ts +2 -0
  31. package/dist/types/task/types.d.ts +11 -0
  32. package/dist/types/tools/index.d.ts +20 -1
  33. package/dist/types/tools/skill.d.ts +47 -0
  34. package/dist/types/utils/changelog.d.ts +18 -2
  35. package/package.json +7 -7
  36. package/src/cli/setup-cli.ts +26 -12
  37. package/src/cli/update-cli.ts +67 -16
  38. package/src/cli.ts +1 -0
  39. package/src/commands/deep-interview.ts +25 -2
  40. package/src/commands/setup.ts +2 -0
  41. package/src/commands/state.ts +1 -0
  42. package/src/config/settings-schema.ts +63 -0
  43. package/src/defaults/gjc/skills/deep-interview/SKILL.md +58 -5
  44. package/src/defaults/gjc/skills/deep-interview/auto-answer-uncertain.md +37 -0
  45. package/src/defaults/gjc/skills/deep-interview/auto-research-greenfield.md +42 -0
  46. package/src/defaults/gjc/skills/ralplan/SKILL.md +8 -0
  47. package/src/defaults/gjc/skills/team/SKILL.md +10 -0
  48. package/src/defaults/gjc/skills/ultragoal/SKILL.md +19 -6
  49. package/src/defaults/gjc-defaults.ts +68 -16
  50. package/src/discovery/helpers.ts +24 -1
  51. package/src/extensibility/extensions/types.ts +6 -0
  52. package/src/gjc-runtime/deep-interview-runtime.ts +312 -1
  53. package/src/gjc-runtime/state-runtime.ts +175 -5
  54. package/src/goals/tools/goal-tool.ts +5 -1
  55. package/src/hooks/skill-state.ts +8 -6
  56. package/src/internal-urls/docs-index.generated.ts +6 -4
  57. package/src/internal-urls/memory-protocol.ts +3 -2
  58. package/src/main.ts +2 -3
  59. package/src/memories/index.ts +6 -4
  60. package/src/memory-backend/local-backend.ts +14 -6
  61. package/src/modes/components/hook-selector.ts +156 -1
  62. package/src/modes/components/settings-selector.ts +16 -12
  63. package/src/modes/controllers/command-controller.ts +3 -4
  64. package/src/modes/controllers/extension-ui-controller.ts +1 -0
  65. package/src/modes/controllers/selector-controller.ts +69 -9
  66. package/src/modes/interactive-mode.ts +14 -1
  67. package/src/modes/theme/defaults/blue-crab.json +126 -0
  68. package/src/modes/theme/defaults/index.ts +2 -0
  69. package/src/modes/theme/theme.ts +40 -1
  70. package/src/modes/types.ts +1 -0
  71. package/src/modes/utils/context-usage.ts +66 -17
  72. package/src/prompts/agents/architect.md +3 -0
  73. package/src/prompts/agents/executor.md +2 -0
  74. package/src/prompts/agents/frontmatter.md +1 -0
  75. package/src/prompts/memories/unavailable.md +9 -0
  76. package/src/prompts/system/subagent-system-prompt.md +6 -0
  77. package/src/prompts/tools/skill.md +28 -0
  78. package/src/prompts/tools/task.md +3 -0
  79. package/src/sdk.ts +54 -10
  80. package/src/session/agent-session.ts +204 -21
  81. package/src/session/session-manager.ts +9 -1
  82. package/src/setup/model-onboarding-guidance.ts +6 -3
  83. package/src/setup/provider-onboarding.ts +177 -16
  84. package/src/skill-state/active-state.ts +150 -25
  85. package/src/skill-state/deep-interview-mutation-guard.ts +11 -24
  86. package/src/skill-state/initial-phase.ts +17 -0
  87. package/src/slash-commands/builtin-registry.ts +62 -14
  88. package/src/slash-commands/helpers/context-report.ts +123 -13
  89. package/src/task/agents.ts +1 -0
  90. package/src/task/executor.ts +9 -1
  91. package/src/task/index.ts +91 -4
  92. package/src/task/types.ts +6 -0
  93. package/src/tools/ask.ts +2 -0
  94. package/src/tools/index.ts +23 -1
  95. package/src/tools/skill.ts +153 -0
  96. package/src/utils/changelog.ts +67 -44
@@ -1,5 +1,5 @@
1
1
  import type { AgentTelemetryConfig, AgentTool } from "@gajae-code/agent-core";
2
- import type { ToolChoice } from "@gajae-code/ai";
2
+ import type { Model, ToolChoice } from "@gajae-code/ai";
3
3
  import { $env, $flag, logger } from "@gajae-code/utils";
4
4
  import type { PromptTemplate } from "../config/prompt-templates";
5
5
  import type { Settings } from "../config/settings";
@@ -12,10 +12,12 @@ import type { HindsightSessionState } from "../hindsight/state";
12
12
  import { LspTool } from "../lsp";
13
13
  import type { PlanModeState } from "../plan-mode/state";
14
14
  import type { AgentRegistry } from "../registry/agent-registry";
15
+ import type { ForkContextSeed, ForkContextSeedOptions } from "../session/agent-session";
15
16
  import type { ArtifactManager } from "../session/artifacts";
16
17
  import type { ClientBridge } from "../session/client-bridge";
17
18
  import type { CustomMessage } from "../session/messages";
18
19
  import type { ToolChoiceQueue } from "../session/tool-choice-queue";
20
+ import type { SkillActiveEntry } from "../skill-state/active-state";
19
21
  import { TaskTool } from "../task";
20
22
  import type { AgentOutputManager } from "../task/output-manager";
21
23
  import type { DiscoverableTool, DiscoverableToolSearchIndex } from "../tool-discovery/tool-index";
@@ -47,6 +49,7 @@ import { ResolveTool } from "./resolve";
47
49
  import { reportFindingTool } from "./review";
48
50
  import { SearchTool } from "./search";
49
51
  import { SearchToolBm25Tool } from "./search-tool-bm25";
52
+ import { SkillTool } from "./skill";
50
53
  import { loadSshTool } from "./ssh";
51
54
  import { SubagentTool } from "./subagent";
52
55
  import { type TodoPhase, TodoWriteTool } from "./todo-write";
@@ -84,6 +87,7 @@ export * from "./resolve";
84
87
  export * from "./review";
85
88
  export * from "./search";
86
89
  export * from "./search-tool-bm25";
90
+ export * from "./skill";
87
91
  export * from "./ssh";
88
92
  export * from "./subagent";
89
93
  export * from "./todo-write";
@@ -122,6 +126,12 @@ export interface ToolSession {
122
126
  workspaceTree?: WorkspaceTree;
123
127
  /** Pre-loaded skills */
124
128
  skills?: Skill[];
129
+ /** Currently executing skill prompt, when this tool session is inside one. */
130
+ getActiveSkillState?: () => Pick<SkillActiveEntry, "skill" | "session_id"> | undefined;
131
+ /** Get the active skill prompt's current phase so the skill tool can apply
132
+ * its terminal-phase chain guard. Returns the raw phase string or undefined
133
+ * when no active skill (or accessor) is available. */
134
+ getActiveSkillPhase?: () => string | undefined;
125
135
  /** Pre-loaded prompt templates */
126
136
  promptTemplates?: PromptTemplate[];
127
137
  /** Whether LSP integrations are enabled */
@@ -164,6 +174,8 @@ export interface ToolSession {
164
174
  getSessionSpawns: () => string | null;
165
175
  /** Get resolved model string if explicitly set for this session */
166
176
  getModelString?: () => string | undefined;
177
+ /** Current model, when selected. */
178
+ model?: Model;
167
179
  /** Get the current session model string, regardless of how it was chosen */
168
180
  getActiveModelString?: () => string | undefined;
169
181
  /** Auth storage for passing to subagents (avoids re-discovery) */
@@ -246,9 +258,17 @@ export interface ToolSession {
246
258
 
247
259
  /** Queue a hidden message to be injected at the next agent turn. */
248
260
  queueDeferredMessage?(message: CustomMessage): void;
261
+ /** Dispatch a custom message through the active session. Used by the `skill`
262
+ * tool to dispatch another skill prompt same-turn after recording a handoff. */
263
+ sendCustomMessage?(
264
+ message: Pick<CustomMessage, "customType" | "content" | "display" | "details" | "attribution">,
265
+ options?: { triggerTurn?: boolean; deliverAs?: "steer" | "followUp" | "nextTurn" },
266
+ ): Promise<void>;
249
267
  /** Get the active OpenTelemetry config so subagent dispatch can forward
250
268
  * the parent's tracer/hooks with the subagent's own identity stamped. */
251
269
  getTelemetry?: () => AgentTelemetryConfig | undefined;
270
+ /** Build a sanitized fork-context seed for task subagents. */
271
+ buildForkContextSeed?: (options: ForkContextSeedOptions) => Promise<ForkContextSeed>;
252
272
  }
253
273
 
254
274
  export type ToolFactory = (session: ToolSession) => Tool | null | Promise<Tool | null>;
@@ -308,6 +328,7 @@ export const BUILTIN_TOOLS: Record<string, ToolFactory> = {
308
328
  retain: HindsightRetainTool.createIf,
309
329
  recall: HindsightRecallTool.createIf,
310
330
  reflect: HindsightReflectTool.createIf,
331
+ skill: SkillTool.createIf,
311
332
  goal: s => new GoalTool(s),
312
333
  };
313
334
 
@@ -464,6 +485,7 @@ export async function createTools(session: ToolSession, toolNames?: string[]): P
464
485
  // search_tool_bm25 is allowed when either legacy mcp.discoveryMode or new tools.discoveryMode is active.
465
486
  if (name === "search_tool_bm25") return discoveryActive;
466
487
  if (name === "calc") return session.settings.get("calc.enabled");
488
+ if (name === "skill") return session.settings.get("skill.enabled");
467
489
  if (name === "browser") return session.settings.get("browser.enabled");
468
490
  if (name === "checkpoint" || name === "rewind") return session.settings.get("checkpoint.enabled");
469
491
  if (name === "irc") {
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Skill Tool — agent-initiated skill chaining.
3
+ *
4
+ * Lets the agent hand off to another available skill in the current turn. The
5
+ * callee's SKILL.md is dispatched through the same custom-message path used by
6
+ * `/skill:<name>` typing, as a user-attribution message delivered same-turn
7
+ * (without `deliverAs: "nextTurn"`). Before dispatch, the tool calls
8
+ * `gjc state <caller> handoff --to <callee>` in-process via the state-runtime
9
+ * function so caller and callee mode-states plus `skill-active-state.json`
10
+ * transition atomically.
11
+ *
12
+ * Chaining is refused unless the caller's `current_phase` is in
13
+ * `{complete, completed, handoff, failed, cancelled, canceled, inactive}`. The
14
+ * agent declares readiness either by writing `current_phase: "handoff"` to its
15
+ * mode-state or by running the handoff verb directly.
16
+ */
17
+
18
+ import type { AgentTool, AgentToolResult } from "@gajae-code/agent-core";
19
+ import { prompt, untilAborted } from "@gajae-code/utils";
20
+ import * as z from "zod/v4";
21
+ import { buildSkillPromptMessage } from "../extensibility/skills";
22
+ import { runNativeStateCommand } from "../gjc-runtime/state-runtime";
23
+ import skillDescription from "../prompts/tools/skill.md" with { type: "text" };
24
+ import { SKILL_PROMPT_MESSAGE_TYPE } from "../session/messages";
25
+ import type { ToolSession } from ".";
26
+ import { ToolError } from "./tool-errors";
27
+
28
+ const TERMINAL_PHASES = new Set(["complete", "completed", "handoff", "failed", "cancelled", "canceled", "inactive"]);
29
+
30
+ const skillSchema = z.object({
31
+ name: z.string().describe("skill name as it appears in /skill:<name>"),
32
+ args: z.string().describe("argument string passed to the skill").optional(),
33
+ });
34
+
35
+ function normalizeSkillName(name: string | undefined): string {
36
+ return (name ?? "").trim();
37
+ }
38
+
39
+ type SkillToolInput = z.infer<typeof skillSchema>;
40
+
41
+ export interface SkillToolDetails {
42
+ name: string;
43
+ path: string;
44
+ args?: string;
45
+ lineCount: number;
46
+ }
47
+
48
+ export class SkillTool implements AgentTool<typeof skillSchema, SkillToolDetails> {
49
+ readonly name = "skill";
50
+ readonly label = "Skill";
51
+ readonly summary = "Chain into another available skill in the current turn";
52
+ readonly loadMode = "discoverable";
53
+ readonly description: string;
54
+ readonly parameters = skillSchema;
55
+ readonly strict = true;
56
+
57
+ readonly #session: ToolSession;
58
+
59
+ constructor(session: ToolSession) {
60
+ this.#session = session;
61
+ this.description = prompt.render(skillDescription);
62
+ }
63
+
64
+ static createIf(session: ToolSession): SkillTool | null {
65
+ // The tool can only chain when the session can deliver the same-turn
66
+ // custom message. Without `sendCustomMessage` (e.g. minimal tool
67
+ // harnesses in tests) there is nothing useful to do.
68
+ if (!session.sendCustomMessage) return null;
69
+ const skills = session.skills ?? [];
70
+ if (skills.length === 0) return null;
71
+ return new SkillTool(session);
72
+ }
73
+
74
+ async execute(
75
+ _toolCallId: string,
76
+ input: SkillToolInput,
77
+ signal?: AbortSignal,
78
+ ): Promise<AgentToolResult<SkillToolDetails>> {
79
+ return untilAborted(signal, async () => {
80
+ const sendCustomMessage = this.#session.sendCustomMessage;
81
+ if (!sendCustomMessage) {
82
+ throw new ToolError("skill tool: session has no custom-message bridge");
83
+ }
84
+ const skills = this.#session.skills ?? [];
85
+ const requestedName = normalizeSkillName(input.name);
86
+ if (!requestedName) {
87
+ throw new ToolError("skill tool: `name` is required");
88
+ }
89
+ const activeState = this.#session.getActiveSkillState?.();
90
+ const activeSkill = normalizeSkillName(activeState?.skill);
91
+ if (activeSkill && requestedName === activeSkill) {
92
+ throw new ToolError(
93
+ `skill tool: refusing to chain into currently active skill "${requestedName}". Follow the active skill instructions instead of invoking it recursively.`,
94
+ );
95
+ }
96
+
97
+ const skill = skills.find(s => s.name === requestedName);
98
+ if (!skill) {
99
+ const available = skills.map(s => s.name).sort();
100
+ const hint = available.length > 0 ? ` Available: ${available.join(", ")}` : "";
101
+ throw new ToolError(`skill tool: unknown skill "${requestedName}".${hint}`);
102
+ }
103
+
104
+ // Phase guard + atomic handoff. Only runs when transitioning between
105
+ // distinct skills (same-skill recursion was already refused above).
106
+ if (activeSkill) {
107
+ const phase = (this.#session.getActiveSkillPhase?.() ?? "running").trim().toLowerCase();
108
+ if (!TERMINAL_PHASES.has(phase)) {
109
+ throw new ToolError(
110
+ `skill tool: refusing to chain from "${activeSkill}" (phase=${phase}) into "${requestedName}". Finalize the current skill (gjc state ${activeSkill} write --input '{"current_phase":"handoff"}' --json) or run gjc state ${activeSkill} handoff --to ${requestedName} --json directly before chaining.`,
111
+ );
112
+ }
113
+ const cwd = this.#session.cwd;
114
+ const sessionId = activeState?.session_id?.trim();
115
+ const handoffArgs = ["handoff", "--mode", activeSkill, "--to", requestedName, "--json"];
116
+ if (sessionId) {
117
+ handoffArgs.push("--session-id", sessionId);
118
+ }
119
+ const handoff = await runNativeStateCommand(handoffArgs, cwd);
120
+ if (handoff.status !== 0) {
121
+ throw new ToolError(
122
+ `skill tool: handoff failed (status=${handoff.status}): ${(handoff.stderr ?? "").trim() || "no detail"}`,
123
+ );
124
+ }
125
+ }
126
+
127
+ const args = (input.args ?? "").trim();
128
+ const built = await buildSkillPromptMessage(skill, args);
129
+
130
+ await sendCustomMessage(
131
+ {
132
+ customType: SKILL_PROMPT_MESSAGE_TYPE,
133
+ content: built.message,
134
+ display: true,
135
+ details: built.details,
136
+ attribution: "user",
137
+ },
138
+ { triggerTurn: false },
139
+ );
140
+
141
+ const summary = args ? `Handed off to /skill:${skill.name} ${args}.` : `Handed off to /skill:${skill.name}.`;
142
+ return {
143
+ content: [{ type: "text", text: summary }],
144
+ details: {
145
+ name: skill.name,
146
+ path: skill.filePath,
147
+ args: args || undefined,
148
+ lineCount: built.details.lineCount,
149
+ },
150
+ };
151
+ });
152
+ }
153
+ }
@@ -1,4 +1,5 @@
1
1
  import { isEnoent, logger } from "@gajae-code/utils";
2
+ import CHANGELOG_TEXT from "../../CHANGELOG.md" with { type: "text" };
2
3
 
3
4
  export interface ChangelogEntry {
4
5
  major: number;
@@ -8,58 +9,67 @@ export interface ChangelogEntry {
8
9
  }
9
10
 
10
11
  /**
11
- * Parse changelog entries from CHANGELOG.md
12
- * Scans for ## lines and collects content until next ## or EOF
12
+ * Parse changelog entries from a CHANGELOG.md text body.
13
+ * Scans for ## lines and collects content until next ## or EOF.
14
+ * Pure and synchronous so it can be reused by the embedded display path.
13
15
  */
14
- export async function parseChangelog(changelogPath: string): Promise<ChangelogEntry[]> {
15
- try {
16
- const content = await Bun.file(changelogPath).text();
17
- const lines = content.split("\n");
18
- const entries: ChangelogEntry[] = [];
16
+ export function parseChangelogContent(content: string): ChangelogEntry[] {
17
+ const lines = content.split("\n");
18
+ const entries: ChangelogEntry[] = [];
19
19
 
20
- let currentLines: string[] = [];
21
- let currentVersion: { major: number; minor: number; patch: number } | null = null;
20
+ let currentLines: string[] = [];
21
+ let currentVersion: { major: number; minor: number; patch: number } | null = null;
22
22
 
23
- for (const line of lines) {
24
- // Check if this is a version header (## [x.y.z] ...)
25
- if (line.startsWith("## ")) {
26
- // Save previous entry if exists
27
- if (currentVersion && currentLines.length > 0) {
28
- entries.push({
29
- ...currentVersion,
30
- content: currentLines.join("\n").trim(),
31
- });
32
- }
23
+ for (const line of lines) {
24
+ // Check if this is a version header (## [x.y.z] ...)
25
+ if (line.startsWith("## ")) {
26
+ // Save previous entry if exists
27
+ if (currentVersion && currentLines.length > 0) {
28
+ entries.push({
29
+ ...currentVersion,
30
+ content: currentLines.join("\n").trim(),
31
+ });
32
+ }
33
33
 
34
- // Try to parse version from this line
35
- const versionMatch = line.match(/##\s+\[?(\d+)\.(\d+)\.(\d+)\]?/);
36
- if (versionMatch) {
37
- currentVersion = {
38
- major: Number.parseInt(versionMatch[1], 10),
39
- minor: Number.parseInt(versionMatch[2], 10),
40
- patch: Number.parseInt(versionMatch[3], 10),
41
- };
42
- currentLines = [line];
43
- } else {
44
- // Reset if we can't parse version
45
- currentVersion = null;
46
- currentLines = [];
47
- }
48
- } else if (currentVersion) {
49
- // Collect lines for current version
50
- currentLines.push(line);
34
+ // Try to parse version from this line
35
+ const versionMatch = line.match(/##\s+\[?(\d+)\.(\d+)\.(\d+)\]?/);
36
+ if (versionMatch) {
37
+ currentVersion = {
38
+ major: Number.parseInt(versionMatch[1], 10),
39
+ minor: Number.parseInt(versionMatch[2], 10),
40
+ patch: Number.parseInt(versionMatch[3], 10),
41
+ };
42
+ currentLines = [line];
43
+ } else {
44
+ // Reset if we can't parse version
45
+ currentVersion = null;
46
+ currentLines = [];
51
47
  }
48
+ } else if (currentVersion) {
49
+ // Collect lines for current version
50
+ currentLines.push(line);
52
51
  }
52
+ }
53
53
 
54
- // Save last entry
55
- if (currentVersion && currentLines.length > 0) {
56
- entries.push({
57
- ...currentVersion,
58
- content: currentLines.join("\n").trim(),
59
- });
60
- }
54
+ // Save last entry
55
+ if (currentVersion && currentLines.length > 0) {
56
+ entries.push({
57
+ ...currentVersion,
58
+ content: currentLines.join("\n").trim(),
59
+ });
60
+ }
61
+
62
+ return entries;
63
+ }
61
64
 
62
- return entries;
65
+ /**
66
+ * Parse changelog entries from a CHANGELOG.md file on disk.
67
+ * Returns [] on ENOENT; logs and returns [] on other read/parse errors.
68
+ */
69
+ export async function parseChangelog(changelogPath: string): Promise<ChangelogEntry[]> {
70
+ try {
71
+ const content = await Bun.file(changelogPath).text();
72
+ return parseChangelogContent(content);
63
73
  } catch (error) {
64
74
  if (isEnoent(error)) {
65
75
  return [];
@@ -69,6 +79,19 @@ export async function parseChangelog(changelogPath: string): Promise<ChangelogEn
69
79
  }
70
80
  }
71
81
 
82
+ /**
83
+ * Return changelog entries from the CHANGELOG.md that shipped with this binary.
84
+ *
85
+ * The text is embedded at build time via `with { type: "text" }`, so the
86
+ * displayed changelog is deterministic across compiled binaries, source-tree
87
+ * dev runs, and `GJC_PACKAGE_DIR` / `PI_PACKAGE_DIR` overrides (which scope to
88
+ * optional package assets like docs/examples and do not influence the
89
+ * binary-identity changelog).
90
+ */
91
+ export function getDisplayChangelogEntries(): ChangelogEntry[] {
92
+ return parseChangelogContent(CHANGELOG_TEXT);
93
+ }
94
+
72
95
  /**
73
96
  * Compare versions. Returns: -1 if v1 < v2, 0 if v1 === v2, 1 if v1 > v2
74
97
  */