@abhishek944/pi-firstmate 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +187 -2
- package/config.example.json +6 -0
- package/dist/config.d.ts +32 -0
- package/dist/config.js +97 -0
- package/dist/herdr-banner.d.ts +42 -0
- package/dist/herdr-banner.js +265 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +779 -0
- package/dist/skill-allowlist.d.ts +25 -0
- package/dist/skill-allowlist.js +34 -0
- package/dist/tool-gate.d.ts +30 -0
- package/dist/tool-gate.js +108 -0
- package/dist/worker.d.ts +34 -0
- package/dist/worker.js +82 -0
- package/herdr/firstmate-banner/README.md +5 -0
- package/herdr/firstmate-banner/main.js +161 -0
- package/herdr/firstmate-banner/mod.json +1 -0
- package/package.json +64 -4
- package/skills/close/SKILL.md +61 -0
- package/skills/firstmate/SKILL.md +133 -0
- package/src/config.ts +118 -0
- package/src/herdr-banner.ts +269 -0
- package/src/index.ts +886 -0
- package/src/skill-allowlist.ts +50 -0
- package/src/tool-gate.ts +128 -0
- package/src/worker.ts +101 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exact-name filtering for First Mate's model-facing skill advertisement.
|
|
3
|
+
*
|
|
4
|
+
* Pi discovers skills from user, project, package and explicit locations, then
|
|
5
|
+
* advertises each discovered skill's name, description and path in the system
|
|
6
|
+
* prompt. This module only narrows that per-run advertisement for the
|
|
7
|
+
* `pi-firstmate.coordinatorSkills` setting. It never loads, unloads, reorders or
|
|
8
|
+
* mutates skills, and Pi keeps its own complete list for `/skill:<name>`
|
|
9
|
+
* expansion, so explicit skill commands and already loaded instructions are
|
|
10
|
+
* unaffected.
|
|
11
|
+
*/
|
|
12
|
+
export interface NamedSkill {
|
|
13
|
+
name: string;
|
|
14
|
+
}
|
|
15
|
+
export interface SkillAllowlistResult<T extends NamedSkill> {
|
|
16
|
+
/** Skills that stay advertised, in Pi's discovery order. */
|
|
17
|
+
skills: T[];
|
|
18
|
+
/** Configured names no discovered skill provides, in configured order. */
|
|
19
|
+
unknown: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Apply exact names to a discovered skill list. Matching is exact (no globs,
|
|
23
|
+
* case folding or whitespace trimming), and neither input is mutated.
|
|
24
|
+
*/
|
|
25
|
+
export declare function applySkillAllowlist<T extends NamedSkill>(skills: readonly T[], names: readonly string[]): SkillAllowlistResult<T>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exact-name filtering for First Mate's model-facing skill advertisement.
|
|
3
|
+
*
|
|
4
|
+
* Pi discovers skills from user, project, package and explicit locations, then
|
|
5
|
+
* advertises each discovered skill's name, description and path in the system
|
|
6
|
+
* prompt. This module only narrows that per-run advertisement for the
|
|
7
|
+
* `pi-firstmate.coordinatorSkills` setting. It never loads, unloads, reorders or
|
|
8
|
+
* mutates skills, and Pi keeps its own complete list for `/skill:<name>`
|
|
9
|
+
* expansion, so explicit skill commands and already loaded instructions are
|
|
10
|
+
* unaffected.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Apply exact names to a discovered skill list. Matching is exact (no globs,
|
|
14
|
+
* case folding or whitespace trimming), and neither input is mutated.
|
|
15
|
+
*/
|
|
16
|
+
export function applySkillAllowlist(skills, names) {
|
|
17
|
+
const allowed = new Set(names);
|
|
18
|
+
const advertised = [];
|
|
19
|
+
const discovered = new Set();
|
|
20
|
+
for (const skill of skills) {
|
|
21
|
+
discovered.add(skill.name);
|
|
22
|
+
if (allowed.has(skill.name))
|
|
23
|
+
advertised.push(skill);
|
|
24
|
+
}
|
|
25
|
+
const unknown = [];
|
|
26
|
+
const reported = new Set();
|
|
27
|
+
for (const name of names) {
|
|
28
|
+
if (discovered.has(name) || reported.has(name))
|
|
29
|
+
continue;
|
|
30
|
+
reported.add(name);
|
|
31
|
+
unknown.push(name);
|
|
32
|
+
}
|
|
33
|
+
return { skills: advertised, unknown };
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coordinator tool gating for First Mate.
|
|
3
|
+
*
|
|
4
|
+
* While coordinator mode is effective, only the four inspection tools and tools
|
|
5
|
+
* registered by the approved orchestration packages stay available. Other
|
|
6
|
+
* active tools are removed from the model-facing set, and every call, including
|
|
7
|
+
* a nested call issued through `ctx.executeTool()`, is checked again at Pi's
|
|
8
|
+
* `tool_call` boundary.
|
|
9
|
+
*
|
|
10
|
+
* This is tool-call enforcement, not an OS sandbox. An allowed tool can still
|
|
11
|
+
* perform whatever its own implementation exposes, so permission, trust and
|
|
12
|
+
* authorization boundaries remain in force.
|
|
13
|
+
*/
|
|
14
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
15
|
+
/** Installed packages whose tools stay available to a coordinator. */
|
|
16
|
+
export declare const APPROVED_PACKAGES: Set<string>;
|
|
17
|
+
export declare const COORDINATOR_TOOLS_DESCRIPTION = "read, grep, find, ls and installed pi-tasks, pi-loop-monitor, pi-decisions, pi-herdr and coordinator-only pi-schedulers tools";
|
|
18
|
+
type ToolHost = Pick<ExtensionAPI, "getActiveTools" | "getAllTools" | "setActiveTools">;
|
|
19
|
+
export interface ToolGate {
|
|
20
|
+
/** Actual installed registrations that must never enter the ordinary-tool baseline. */
|
|
21
|
+
coordinatorOnlyNames(): Set<string>;
|
|
22
|
+
/** Whether coordinator mode may call this tool. */
|
|
23
|
+
permits(toolName: string): boolean;
|
|
24
|
+
/** Hide every active tool outside the allowlist and return the hidden names. */
|
|
25
|
+
hide(): string[];
|
|
26
|
+
/** Actionable explanation for a rejected direct or nested call. */
|
|
27
|
+
reason(toolName: string): string;
|
|
28
|
+
}
|
|
29
|
+
export declare function createToolGate(pi: ToolHost): ToolGate;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coordinator tool gating for First Mate.
|
|
3
|
+
*
|
|
4
|
+
* While coordinator mode is effective, only the four inspection tools and tools
|
|
5
|
+
* registered by the approved orchestration packages stay available. Other
|
|
6
|
+
* active tools are removed from the model-facing set, and every call, including
|
|
7
|
+
* a nested call issued through `ctx.executeTool()`, is checked again at Pi's
|
|
8
|
+
* `tool_call` boundary.
|
|
9
|
+
*
|
|
10
|
+
* This is tool-call enforcement, not an OS sandbox. An allowed tool can still
|
|
11
|
+
* perform whatever its own implementation exposes, so permission, trust and
|
|
12
|
+
* authorization boundaries remain in force.
|
|
13
|
+
*/
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
import { dirname, join } from "node:path";
|
|
16
|
+
const INSPECTION_TOOLS = new Set(["read", "grep", "find", "ls"]);
|
|
17
|
+
/** Installed packages whose tools stay available to a coordinator. */
|
|
18
|
+
export const APPROVED_PACKAGES = new Set([
|
|
19
|
+
"@abhishek944/pi-tasks",
|
|
20
|
+
"@abhishek944/pi-loop-monitor",
|
|
21
|
+
"@abhishek944/pi-decisions",
|
|
22
|
+
"@abhishek944/pi-herdr",
|
|
23
|
+
"@abhishek944/pi-schedulers",
|
|
24
|
+
]);
|
|
25
|
+
const COORDINATOR_ONLY_PACKAGES = new Set(["@abhishek944/pi-schedulers"]);
|
|
26
|
+
export const COORDINATOR_TOOLS_DESCRIPTION = "read, grep, find, ls and installed pi-tasks, pi-loop-monitor, pi-decisions, pi-herdr and coordinator-only pi-schedulers tools";
|
|
27
|
+
function isRecord(value) {
|
|
28
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29
|
+
}
|
|
30
|
+
function sourceBaseDir(sourceInfo) {
|
|
31
|
+
if (sourceInfo.baseDir !== undefined)
|
|
32
|
+
return sourceInfo.baseDir;
|
|
33
|
+
if (sourceInfo.path.startsWith("builtin:") || sourceInfo.path.startsWith("<"))
|
|
34
|
+
return undefined;
|
|
35
|
+
return dirname(sourceInfo.path);
|
|
36
|
+
}
|
|
37
|
+
export function createToolGate(pi) {
|
|
38
|
+
const sourcePackages = new Map();
|
|
39
|
+
// Package identity comes from the registration's installed package root, not
|
|
40
|
+
// from a tool name list or self-declared annotations. The extension entry can
|
|
41
|
+
// live in `dist/` (explicit extension paths) or the package root (discovered
|
|
42
|
+
// packages), so walk to the nearest manifest. A missing or unreadable manifest
|
|
43
|
+
// stays unapproved so new or unexpected tools fail closed.
|
|
44
|
+
function sourcePackage(sourceInfo) {
|
|
45
|
+
const baseDir = sourceBaseDir(sourceInfo);
|
|
46
|
+
if (baseDir === undefined)
|
|
47
|
+
return null;
|
|
48
|
+
const cached = sourcePackages.get(baseDir);
|
|
49
|
+
if (cached !== undefined)
|
|
50
|
+
return cached;
|
|
51
|
+
let packageName = null;
|
|
52
|
+
let directory = baseDir;
|
|
53
|
+
while (true) {
|
|
54
|
+
try {
|
|
55
|
+
const manifest = JSON.parse(readFileSync(join(directory, "package.json"), "utf8"));
|
|
56
|
+
packageName = isRecord(manifest) && typeof manifest.name === "string" ? manifest.name : null;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
const parent = dirname(directory);
|
|
61
|
+
if (parent === directory)
|
|
62
|
+
break;
|
|
63
|
+
directory = parent;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
sourcePackages.set(baseDir, packageName);
|
|
67
|
+
return packageName;
|
|
68
|
+
}
|
|
69
|
+
// Rebuild from the live registry so tools registered after session start are
|
|
70
|
+
// classified from their actual installation instead of a stale snapshot.
|
|
71
|
+
function allowedNames() {
|
|
72
|
+
const allowed = new Set(INSPECTION_TOOLS);
|
|
73
|
+
for (const tool of pi.getAllTools()) {
|
|
74
|
+
if (APPROVED_PACKAGES.has(sourcePackage(tool.sourceInfo) ?? ""))
|
|
75
|
+
allowed.add(tool.name);
|
|
76
|
+
}
|
|
77
|
+
return allowed;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
coordinatorOnlyNames() {
|
|
81
|
+
return new Set(pi.getAllTools()
|
|
82
|
+
.filter((tool) => COORDINATOR_ONLY_PACKAGES.has(sourcePackage(tool.sourceInfo) ?? ""))
|
|
83
|
+
.map((tool) => tool.name));
|
|
84
|
+
},
|
|
85
|
+
permits(toolName) {
|
|
86
|
+
if (INSPECTION_TOOLS.has(toolName))
|
|
87
|
+
return true;
|
|
88
|
+
try {
|
|
89
|
+
return allowedNames().has(toolName);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
hide() {
|
|
96
|
+
const allowed = allowedNames();
|
|
97
|
+
const active = pi.getActiveTools();
|
|
98
|
+
const kept = active.filter((name) => allowed.has(name));
|
|
99
|
+
const hidden = active.filter((name) => !allowed.has(name));
|
|
100
|
+
if (hidden.length > 0)
|
|
101
|
+
pi.setActiveTools(kept);
|
|
102
|
+
return hidden;
|
|
103
|
+
},
|
|
104
|
+
reason(toolName) {
|
|
105
|
+
return `First Mate coordinator mode blocks ${JSON.stringify(toolName)}. Only ${COORDINATOR_TOOLS_DESCRIPTION} are available in this coordinator session, including for nested tool calls. This is an intentional coordinator restriction, not a missing permission: do not ask to enable the tool. Check that an installed delegation backend is ready and delegate the work through its orchestration tools, or run /firstmate off before doing it locally.`;
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow, local Core worker classification for First Mate.
|
|
3
|
+
*
|
|
4
|
+
* `HC_TERMINAL_ID` is present in every Core-hosted Pi process, including the
|
|
5
|
+
* primary coordinator, so it is only a precondition. A worker is verified from
|
|
6
|
+
* the labels that pi-herdr AgentCreate writes: `pi.task` and `pi.session`.
|
|
7
|
+
* Partial labels or a failed lookup are reported as unknown instead of guessed.
|
|
8
|
+
*/
|
|
9
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
10
|
+
export type WorkerClassification = {
|
|
11
|
+
kind: "explicit-worker";
|
|
12
|
+
} | {
|
|
13
|
+
kind: "not-core";
|
|
14
|
+
} | {
|
|
15
|
+
kind: "primary";
|
|
16
|
+
terminalId: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "worker";
|
|
19
|
+
terminalId: string;
|
|
20
|
+
task: string;
|
|
21
|
+
parentSessionId: string;
|
|
22
|
+
parent?: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "unknown";
|
|
25
|
+
terminalId: string;
|
|
26
|
+
message: string;
|
|
27
|
+
};
|
|
28
|
+
type CoreExec = Pick<ExtensionAPI, "exec">;
|
|
29
|
+
/**
|
|
30
|
+
* Classify the current process as a primary Core session, a verified task
|
|
31
|
+
* worker, a non-Core session, or unknown when the Core lookup cannot be trusted.
|
|
32
|
+
*/
|
|
33
|
+
export declare function classifyCoreWorker(pi: CoreExec, env?: NodeJS.ProcessEnv): Promise<WorkerClassification>;
|
|
34
|
+
export {};
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrow, local Core worker classification for First Mate.
|
|
3
|
+
*
|
|
4
|
+
* `HC_TERMINAL_ID` is present in every Core-hosted Pi process, including the
|
|
5
|
+
* primary coordinator, so it is only a precondition. A worker is verified from
|
|
6
|
+
* the labels that pi-herdr AgentCreate writes: `pi.task` and `pi.session`.
|
|
7
|
+
* Partial labels or a failed lookup are reported as unknown instead of guessed.
|
|
8
|
+
*/
|
|
9
|
+
function isRecord(value) {
|
|
10
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
|
+
}
|
|
12
|
+
function readLabel(labels, key) {
|
|
13
|
+
const value = labels[key];
|
|
14
|
+
if (typeof value !== "string")
|
|
15
|
+
return undefined;
|
|
16
|
+
const trimmed = value.trim();
|
|
17
|
+
return trimmed === "" ? undefined : trimmed;
|
|
18
|
+
}
|
|
19
|
+
function firstLine(value) {
|
|
20
|
+
const line = value.split("\n", 1)[0]?.trim() ?? "";
|
|
21
|
+
return line === "" ? "no diagnostic output" : line;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Classify the current process as a primary Core session, a verified task
|
|
25
|
+
* worker, a non-Core session, or unknown when the Core lookup cannot be trusted.
|
|
26
|
+
*/
|
|
27
|
+
export async function classifyCoreWorker(pi, env = process.env) {
|
|
28
|
+
const terminalId = env.HC_TERMINAL_ID?.trim();
|
|
29
|
+
if (!terminalId)
|
|
30
|
+
return { kind: "not-core" };
|
|
31
|
+
let result;
|
|
32
|
+
try {
|
|
33
|
+
result = await pi.exec("hc", ["get", terminalId, "--json"]);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
37
|
+
return { kind: "unknown", terminalId, message: `hc get ${terminalId} failed: ${firstLine(message)}` };
|
|
38
|
+
}
|
|
39
|
+
if (result.code !== 0) {
|
|
40
|
+
const detail = result.stderr.trim() === "" ? result.stdout.trim() : result.stderr.trim();
|
|
41
|
+
const suffix = detail === ""
|
|
42
|
+
? "; no diagnostic output (is hc installed and this terminal live?)"
|
|
43
|
+
: `: ${firstLine(detail)}`;
|
|
44
|
+
return {
|
|
45
|
+
kind: "unknown",
|
|
46
|
+
terminalId,
|
|
47
|
+
message: `hc get ${terminalId} exited with code ${result.code}${suffix}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
let parsed;
|
|
51
|
+
try {
|
|
52
|
+
parsed = JSON.parse(result.stdout);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return { kind: "unknown", terminalId, message: `hc get ${terminalId} returned invalid JSON` };
|
|
56
|
+
}
|
|
57
|
+
if (!isRecord(parsed)) {
|
|
58
|
+
return { kind: "unknown", terminalId, message: `hc get ${terminalId} returned unexpected JSON` };
|
|
59
|
+
}
|
|
60
|
+
if (typeof parsed.address === "string" && parsed.address !== terminalId) {
|
|
61
|
+
return {
|
|
62
|
+
kind: "unknown",
|
|
63
|
+
terminalId,
|
|
64
|
+
message: `hc get ${terminalId} returned terminal ${parsed.address}`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const labels = isRecord(parsed.labels) ? parsed.labels : {};
|
|
68
|
+
const task = readLabel(labels, "pi.task");
|
|
69
|
+
const parentSessionId = readLabel(labels, "pi.session");
|
|
70
|
+
if (task === undefined && parentSessionId === undefined)
|
|
71
|
+
return { kind: "primary", terminalId };
|
|
72
|
+
if (task === undefined || parentSessionId === undefined) {
|
|
73
|
+
const missing = task === undefined ? "pi.task" : "pi.session";
|
|
74
|
+
return {
|
|
75
|
+
kind: "unknown",
|
|
76
|
+
terminalId,
|
|
77
|
+
message: `Core terminal ${terminalId} has a partial pi-herdr label set (missing ${missing})`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const parent = typeof parsed.parent === "string" && parsed.parent.trim() !== "" ? parsed.parent : undefined;
|
|
81
|
+
return { kind: "worker", terminalId, task, parentSessionId, ...(parent ? { parent } : {}) };
|
|
82
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# firstmate-banner
|
|
2
|
+
|
|
3
|
+
Installed and updated by the pi-firstmate Pi extension. It draws the amber First Mate strip above the shown tab's panes and stays 0 px whenever that tab has no live First Mate session, so it adds no space to ordinary work. The strip reminds the session to read the installed First Mate skill while coordinator mode is on.
|
|
4
|
+
|
|
5
|
+
Do not hand-edit this folder: a package update replaces only files whose content changed and keeps the previous copy under `~/.config/herdr-app/data/firstmate-banner/backups/`. To stop the banner, set `pi-firstmate.banner` to `false` and reload Pi, or delete the `firstmate-banner` block from the personal layout that uses it.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// First Mate's native banner strip.
|
|
2
|
+
//
|
|
3
|
+
// The pi-firstmate extension installs this mod and inserts a `firstmate-banner`
|
|
4
|
+
// block above the active-tab block of the shown personal layout. That block is
|
|
5
|
+
// always present (never `hidden`, so this copy stays alive to follow tab
|
|
6
|
+
// changes) and is 0 px while First Mate is off. This mod reads the extension's
|
|
7
|
+
// per-session state, shows the strip only when the ACTIVE TAB contains a live
|
|
8
|
+
// First Mate session, and resizes its own layout node to 30 px / 0 px.
|
|
9
|
+
import { View, div } from "gpui-kit";
|
|
10
|
+
import { h_flex } from "gpui-base";
|
|
11
|
+
import * as fs from "fs/promises";
|
|
12
|
+
import { agents, appHome, layout, panes, run, spaces, terminals, watchFolder } from "herdr";
|
|
13
|
+
|
|
14
|
+
const MOD = "firstmate-banner";
|
|
15
|
+
const NODE = "firstmate-banner";
|
|
16
|
+
const HEIGHT = 30;
|
|
17
|
+
const SESSION = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
18
|
+
const TERMINAL = /^(?:[A-Za-z0-9][A-Za-z0-9._-]*\/)?t[0-9a-z]+$/;
|
|
19
|
+
|
|
20
|
+
// Warm amber that stays readable in both light and dark themes. Ink on amber
|
|
21
|
+
// is about 7:1.
|
|
22
|
+
const AMBER = "#d99a16";
|
|
23
|
+
const AMBER_BORDER = "#b87e0a";
|
|
24
|
+
const AMBER_CHIP_TEXT = "#ffe6a3";
|
|
25
|
+
const INK = "#241a02";
|
|
26
|
+
|
|
27
|
+
const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
28
|
+
|
|
29
|
+
function find(node, id) {
|
|
30
|
+
if (record(node) && node.id === id) return node;
|
|
31
|
+
for (const child of record(node) && Array.isArray(node.children) ? node.children : []) {
|
|
32
|
+
const found = find(child, id);
|
|
33
|
+
if (found) return found;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The extension writes only these fields. Anything else is ignored rather than
|
|
39
|
+
// trusted, so a damaged or foreign file cannot make the banner appear.
|
|
40
|
+
function isState(value) {
|
|
41
|
+
return (
|
|
42
|
+
record(value) &&
|
|
43
|
+
value.version === 1 &&
|
|
44
|
+
typeof value.sessionId === "string" &&
|
|
45
|
+
SESSION.test(value.sessionId) &&
|
|
46
|
+
typeof value.terminal === "string" &&
|
|
47
|
+
TERMINAL.test(value.terminal) &&
|
|
48
|
+
typeof value.effective === "boolean" &&
|
|
49
|
+
Number.isSafeInteger(value.updatedAt) &&
|
|
50
|
+
value.updatedAt > 0
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default class FirstMateBanner extends View {
|
|
55
|
+
init(_props, cx) {
|
|
56
|
+
this.directory = `${appHome()}/data/${MOD}`;
|
|
57
|
+
this.sessions = new Map();
|
|
58
|
+
this.closed = false;
|
|
59
|
+
cx.spawn(async (cx) => {
|
|
60
|
+
try {
|
|
61
|
+
await fs.mkdir(this.directory, { recursive: true });
|
|
62
|
+
} catch {
|
|
63
|
+
// The extension creates this folder too; a read-only home just means no
|
|
64
|
+
// sessions are known and the strip stays collapsed.
|
|
65
|
+
}
|
|
66
|
+
for (;;) {
|
|
67
|
+
await this.reload();
|
|
68
|
+
if (this.closed) return;
|
|
69
|
+
cx.notify();
|
|
70
|
+
try {
|
|
71
|
+
await watchFolder(this.directory);
|
|
72
|
+
} catch {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (this.closed) return;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async close() {
|
|
81
|
+
this.closed = true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async reload() {
|
|
85
|
+
const sessions = new Map();
|
|
86
|
+
let names = [];
|
|
87
|
+
try {
|
|
88
|
+
names = await fs.readdir(this.directory);
|
|
89
|
+
} catch {
|
|
90
|
+
this.sessions = sessions;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
for (const name of names) {
|
|
94
|
+
if (!name.endsWith(".json") || name.startsWith(".")) continue;
|
|
95
|
+
try {
|
|
96
|
+
const value = JSON.parse(await fs.readFile(`${this.directory}/${name}`, "utf8"));
|
|
97
|
+
if (!isState(value)) continue;
|
|
98
|
+
// One terminal runs one Pi session; the newest state wins after a
|
|
99
|
+
// replacement session starts in the same terminal.
|
|
100
|
+
const previous = sessions.get(value.terminal);
|
|
101
|
+
if (!previous || previous.updatedAt <= value.updatedAt) sessions.set(value.terminal, value);
|
|
102
|
+
} catch {
|
|
103
|
+
// Ignore a half-written or foreign file; the next change reloads.
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
this.sessions = sessions;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Visibility is per shown tab, not per window and not per focused pane.
|
|
110
|
+
// Live checks keep a state file left by a crashed Pi process from winning.
|
|
111
|
+
match() {
|
|
112
|
+
const space = spaces().find((item) => item.active);
|
|
113
|
+
const tab = space?.tabs.find((item) => item.active);
|
|
114
|
+
if (!tab) return null;
|
|
115
|
+
const live = new Set(terminals().filter((item) => record(item) && item.state === "live").map((item) => item.address));
|
|
116
|
+
const running = new Set(agents().map((item) => item.address));
|
|
117
|
+
const own = panes()
|
|
118
|
+
.filter((pane) => pane.tab === tab.id && typeof pane.terminal === "string")
|
|
119
|
+
.filter((pane) => {
|
|
120
|
+
const state = this.sessions.get(pane.terminal);
|
|
121
|
+
return state?.effective === true && live.has(pane.terminal) && running.has(pane.terminal);
|
|
122
|
+
})
|
|
123
|
+
.map((pane) => pane.terminal);
|
|
124
|
+
if (own.length === 0) return null;
|
|
125
|
+
const focused = panes().find((pane) => pane.tab === tab.id && pane.focused)?.terminal;
|
|
126
|
+
return typeof focused === "string" && own.includes(focused) ? focused : own[0];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
render() {
|
|
130
|
+
const terminal = this.match();
|
|
131
|
+
const node = find(layout(), NODE);
|
|
132
|
+
const size = node && record(node.size) && typeof node.size.px === "number" ? node.size.px : HEIGHT;
|
|
133
|
+
const want = terminal === null ? 0 : HEIGHT;
|
|
134
|
+
// layout() reports the applied click state, so this settles after one call
|
|
135
|
+
// per change instead of resizing on every render.
|
|
136
|
+
if (node && size !== want) run("layout.resize", { id: NODE, px: want });
|
|
137
|
+
if (terminal === null) return div();
|
|
138
|
+
return h_flex()
|
|
139
|
+
.id(NODE)
|
|
140
|
+
.size_full()
|
|
141
|
+
.min_w(0)
|
|
142
|
+
.px(12)
|
|
143
|
+
.gap(10)
|
|
144
|
+
.items_center()
|
|
145
|
+
.bg(AMBER)
|
|
146
|
+
.border_b(1)
|
|
147
|
+
.border_color(AMBER_BORDER)
|
|
148
|
+
.accessibility_label("First Mate coordinator mode is on for this session; read the installed First Mate skill")
|
|
149
|
+
.child(
|
|
150
|
+
h_flex()
|
|
151
|
+
.h(18)
|
|
152
|
+
.px(7)
|
|
153
|
+
.flex_none()
|
|
154
|
+
.rounded(4)
|
|
155
|
+
.items_center()
|
|
156
|
+
.bg(INK)
|
|
157
|
+
.child(div().text_size(10.5).font_semibold().text_color(AMBER_CHIP_TEXT).child("FIRST MATE")),
|
|
158
|
+
)
|
|
159
|
+
.child(div().flex_none().text_size(12.5).font_semibold().text_color(INK).child("Coordinator mode · read the First Mate skill"));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "place": "none" }
|
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abhishek944/pi-firstmate",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Configurable coordinator-first mode and bundled First Mate skill for Pi.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22.19.0"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"pi-package",
|
|
12
|
+
"pi",
|
|
13
|
+
"pi-extension",
|
|
14
|
+
"coordinator",
|
|
15
|
+
"agents"
|
|
16
|
+
],
|
|
17
|
+
"files": [
|
|
18
|
+
"src/",
|
|
19
|
+
"dist/",
|
|
20
|
+
"herdr/",
|
|
21
|
+
"skills/firstmate/",
|
|
22
|
+
"skills/close/",
|
|
23
|
+
"config.example.json",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
40
|
+
"build": "npm run clean && tsc",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"lint": "biome check src/"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@biomejs/biome": "^2.6.4",
|
|
46
|
+
"@types/node": "^26.6.6",
|
|
47
|
+
"@earendil-works/pi-coding-agent": "1.4.0",
|
|
48
|
+
"typescript": "^7.0.2"
|
|
49
|
+
},
|
|
50
|
+
"pi": {
|
|
51
|
+
"extensions": [
|
|
52
|
+
"./dist/index.js"
|
|
53
|
+
],
|
|
54
|
+
"skills": [
|
|
55
|
+
"./skills"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "https://github.com/abhishek944/astack.git",
|
|
61
|
+
"directory": "packages/pi-firstmate"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: close
|
|
3
|
+
description: "Record a worker close retrospective before final handoff: evidence-based skill, codebase, documentation and speed findings written to improvements.md in the canonical session/work/task artifact directory. Changes nothing and creates no follow-up work."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Close retrospective
|
|
8
|
+
|
|
9
|
+
Run this when the coordinator asks for it, normally by sending `/close` after it has verified your result and decided you need nothing further. A close request that arrives after your assignment report supersedes an earlier assignment line that withheld the retrospective. It records what this session learned so later runs are faster and cleaner. It changes nothing.
|
|
10
|
+
|
|
11
|
+
## Record location
|
|
12
|
+
|
|
13
|
+
Resolve the record path before writing anything:
|
|
14
|
+
|
|
15
|
+
1. With an exact `parentTaskDir` from your assignment, append your own IDs:
|
|
16
|
+
`<parentTaskDir>/<yourSessionId>/<yourWorkId>/<yourTaskId>/improvements.md`
|
|
17
|
+
2. In a root session, from the repository root:
|
|
18
|
+
`var/<yourSessionId>/<yourWorkId>/<yourTaskId>/improvements.md`
|
|
19
|
+
3. If no work or task record exists:
|
|
20
|
+
`var/<yourSessionId>/improvements.md`
|
|
21
|
+
|
|
22
|
+
The record is a single `improvements.md` file sitting directly in the canonical task directory, with no `improvements/` subdirectory and no session-named filename. The session directory already identifies the session, so the filename stays fixed. Leave an existing `improvements/<sessionId>.md` record from an earlier run where it is; do not move or copy it into the new location.
|
|
23
|
+
|
|
24
|
+
Append your own session, work and task IDs; never write beside `parentTaskDir` itself or into a sibling directory that only looks close. When this session has several tasks, use the task that owns the assignment being closed, not a neighboring one.
|
|
25
|
+
|
|
26
|
+
Read your own session ID from your shell (`printf '%s\n' "$PI_SESSION_ID"`) and your Work and Task IDs from the real tracking tools. Never invent IDs, never reuse the parent's IDs, and never write outside the repository's `var/` directory. If your identity or tracking is unavailable, report that blocker instead of writing.
|
|
27
|
+
|
|
28
|
+
## What to record
|
|
29
|
+
|
|
30
|
+
Read the existing file first and merge into it. Keep one entry per distinct finding, add new evidence to the existing entry, correct or remove entries that later evidence disproved, and preserve unrelated entries. Repeated runs must not duplicate findings.
|
|
31
|
+
|
|
32
|
+
Record only findings this session produced evidence for:
|
|
33
|
+
|
|
34
|
+
- **Skill improvements** — instruction gaps, or workflow patterns in a skill, prompt, template or assignment that caused a wrong turn, an unnecessary step or a repeated explanation. Name the skill or instruction file.
|
|
35
|
+
- **Codebase improvements** — workflow, tooling, build, check-command or maintainability changes in this repository that would make future runs faster or less error-prone, each stating the step or time it removes. This section records process cost; ordinary product defects belong in your assignment result, not here.
|
|
36
|
+
- **Documentation improvements** — repository documentation, architecture notes or flow docs that were missing, wrong or expensive to read. Name the document and the fact it should state.
|
|
37
|
+
- **Speed opportunities** — the slow step, what it cost, and the change that would remove it. Cite a measured cost only when it is attributable to that step, such as a command's elapsed time or a recorded retry; otherwise describe the observed wasted step or round trip and write `not measured`. Never estimate a number. Say whether the cause is skill-level, documentation or codebase-level, and name the file the change would land in.
|
|
38
|
+
|
|
39
|
+
Each entry:
|
|
40
|
+
|
|
41
|
+
```md
|
|
42
|
+
### <short subject>
|
|
43
|
+
- Evidence: <repo-relative or taskDir-relative path written without `...`, command, task ID, observed delay or failure>
|
|
44
|
+
- Benefit: <what improves for future runs>
|
|
45
|
+
- Next step: <smallest concrete change; no code>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Order entries by impact within each section, and let a measured time saving outrank a cosmetic defect. When a finding is both an instruction gap and a removed step or round trip, file it under Speed opportunities and name the owning file in its Next step. Write `No evidence-based findings.` for an empty section instead of padding it. Do not restate the assignment, do not list routine steps as findings, and do not turn general opinion into an improvement.
|
|
49
|
+
|
|
50
|
+
Record the session outcome at the top as `Completed`, `Blocked` or `Interrupted`, with the one-line evidence and the per-section counts. Blocked or partial work must not be described as complete.
|
|
51
|
+
|
|
52
|
+
## What not to record
|
|
53
|
+
|
|
54
|
+
- No secrets, tokens, credentials, raw logs, full transcripts or personal data. Reference a command or path instead of pasting its output.
|
|
55
|
+
- No edits to skills, code, configuration or settings, and no commits, branches, pushes or deployments.
|
|
56
|
+
- No follow-up tasks, Todos, agents or scheduled work for these findings.
|
|
57
|
+
- No terminal, session or monitor cleanup. The coordinator verifies this record and then closes the worker.
|
|
58
|
+
|
|
59
|
+
## Final handoff
|
|
60
|
+
|
|
61
|
+
Report the record path, the outcome line, the per-section counts, and the single highest-impact finding. Keep it short; the coordinator reads the file for detail.
|