apiario 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/balance.d.ts +35 -0
- package/dist/balance.d.ts.map +1 -0
- package/dist/balance.js +52 -0
- package/dist/balance.js.map +1 -0
- package/dist/cli.js +175 -6
- package/dist/cli.js.map +1 -1
- package/dist/extensions/localization.d.ts +3 -2
- package/dist/extensions/localization.d.ts.map +1 -1
- package/dist/extensions/localization.js +29 -4
- package/dist/extensions/localization.js.map +1 -1
- package/dist/extensions/subagent/agents.d.ts +39 -0
- package/dist/extensions/subagent/agents.d.ts.map +1 -0
- package/dist/extensions/subagent/agents.js +239 -0
- package/dist/extensions/subagent/agents.js.map +1 -0
- package/dist/extensions/subagent/display.d.ts +18 -0
- package/dist/extensions/subagent/display.d.ts.map +1 -0
- package/dist/extensions/subagent/display.js +442 -0
- package/dist/extensions/subagent/display.js.map +1 -0
- package/dist/extensions/subagent/index.d.ts +15 -0
- package/dist/extensions/subagent/index.d.ts.map +1 -0
- package/dist/extensions/subagent/index.js +349 -0
- package/dist/extensions/subagent/index.js.map +1 -0
- package/dist/extensions/subagent/spawn.d.ts +48 -0
- package/dist/extensions/subagent/spawn.d.ts.map +1 -0
- package/dist/extensions/subagent/spawn.js +326 -0
- package/dist/extensions/subagent/spawn.js.map +1 -0
- package/package.json +7 -6
- package/skills/git-worktree/SKILL.md +203 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spawn do child process (npx apiario --mode json)
|
|
3
|
+
*
|
|
4
|
+
* Lida com:
|
|
5
|
+
* - Spawn do processo filho
|
|
6
|
+
* - Streaming de saída JSON-line
|
|
7
|
+
* - Coleta de resultados (mensagens, uso)
|
|
8
|
+
* - Abort (Ctrl+C) — mata o child
|
|
9
|
+
*/
|
|
10
|
+
import { spawn } from "node:child_process";
|
|
11
|
+
import * as fs from "node:fs";
|
|
12
|
+
import * as os from "node:os";
|
|
13
|
+
import * as path from "node:path";
|
|
14
|
+
import { withFileMutationQueue } from "@earendil-works/pi-coding-agent";
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Constantes
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
const PER_TASK_OUTPUT_CAP = 50 * 1024; // 50 KB por task visível ao modelo pai
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Helpers de output
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
function getFinalOutput(messages) {
|
|
23
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
24
|
+
const msg = messages[i];
|
|
25
|
+
if (msg.role === "assistant") {
|
|
26
|
+
for (const part of msg.content) {
|
|
27
|
+
if (part.type === "text")
|
|
28
|
+
return part.text;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
export function isFailedResult(result) {
|
|
35
|
+
return (result.exitCode !== 0 ||
|
|
36
|
+
result.stopReason === "error" ||
|
|
37
|
+
result.stopReason === "aborted");
|
|
38
|
+
}
|
|
39
|
+
export function getResultOutput(result) {
|
|
40
|
+
if (isFailedResult(result)) {
|
|
41
|
+
return (result.errorMessage ||
|
|
42
|
+
result.stderr ||
|
|
43
|
+
getFinalOutput(result.messages) ||
|
|
44
|
+
"(sem saída)");
|
|
45
|
+
}
|
|
46
|
+
return getFinalOutput(result.messages) || "(sem saída)";
|
|
47
|
+
}
|
|
48
|
+
export function truncateParallelOutput(output) {
|
|
49
|
+
const byteLength = Buffer.byteLength(output, "utf8");
|
|
50
|
+
if (byteLength <= PER_TASK_OUTPUT_CAP)
|
|
51
|
+
return output;
|
|
52
|
+
let truncated = output.slice(0, PER_TASK_OUTPUT_CAP);
|
|
53
|
+
while (Buffer.byteLength(truncated, "utf8") > PER_TASK_OUTPUT_CAP) {
|
|
54
|
+
truncated = truncated.slice(0, -1);
|
|
55
|
+
}
|
|
56
|
+
return `${truncated}\n\n[Saída truncada: ${byteLength - Buffer.byteLength(truncated, "utf8")} bytes omitidos. Conteúdo completo preservado nos detalhes da ferramenta.]`;
|
|
57
|
+
}
|
|
58
|
+
export function formatTokens(count) {
|
|
59
|
+
if (count < 1000)
|
|
60
|
+
return count.toString();
|
|
61
|
+
if (count < 10000)
|
|
62
|
+
return `${(count / 1000).toFixed(1)}k`;
|
|
63
|
+
if (count < 1000000)
|
|
64
|
+
return `${Math.round(count / 1000)}k`;
|
|
65
|
+
return `${(count / 1000000).toFixed(1)}M`;
|
|
66
|
+
}
|
|
67
|
+
export function formatUsageStats(usage, model) {
|
|
68
|
+
const parts = [];
|
|
69
|
+
if (usage.turns)
|
|
70
|
+
parts.push(`${usage.turns} turno${usage.turns > 1 ? "s" : ""}`);
|
|
71
|
+
if (usage.input)
|
|
72
|
+
parts.push(`↑${formatTokens(usage.input)}`);
|
|
73
|
+
if (usage.output)
|
|
74
|
+
parts.push(`↓${formatTokens(usage.output)}`);
|
|
75
|
+
if (usage.cacheRead)
|
|
76
|
+
parts.push(`R${formatTokens(usage.cacheRead)}`);
|
|
77
|
+
if (usage.cacheWrite)
|
|
78
|
+
parts.push(`W${formatTokens(usage.cacheWrite)}`);
|
|
79
|
+
if (usage.cost)
|
|
80
|
+
parts.push(`R$ ${usage.cost.toFixed(4)}`);
|
|
81
|
+
if (usage.contextTokens && usage.contextTokens > 0) {
|
|
82
|
+
parts.push(`ctx:${formatTokens(usage.contextTokens)}`);
|
|
83
|
+
}
|
|
84
|
+
if (model)
|
|
85
|
+
parts.push(model);
|
|
86
|
+
return parts.join(" ");
|
|
87
|
+
}
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
// Descoberta do binário apiario
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
function getApiarioInvocation(args) {
|
|
92
|
+
const currentScript = process.argv[1];
|
|
93
|
+
if (currentScript && fs.existsSync(currentScript)) {
|
|
94
|
+
return { command: process.execPath, args: [currentScript, ...args] };
|
|
95
|
+
}
|
|
96
|
+
// Fallback: tenta npx apiario
|
|
97
|
+
return { command: "npx", args: ["apiario", ...args] };
|
|
98
|
+
}
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// Helpers de sistema de arquivos
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
async function writePromptToTempFile(agentName, prompt) {
|
|
103
|
+
const tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "apiario-subagent-"));
|
|
104
|
+
const safeName = agentName.replace(/[^\w.-]+/g, "_");
|
|
105
|
+
const filePath = path.join(tmpDir, `prompt-${safeName}.md`);
|
|
106
|
+
await withFileMutationQueue(filePath, async () => {
|
|
107
|
+
await fs.promises.writeFile(filePath, prompt, {
|
|
108
|
+
encoding: "utf-8",
|
|
109
|
+
mode: 0o600,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
return { dir: tmpDir, filePath };
|
|
113
|
+
}
|
|
114
|
+
function cleanupTemp(dir, file) {
|
|
115
|
+
if (file) {
|
|
116
|
+
try {
|
|
117
|
+
fs.unlinkSync(file);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
/* ignora */
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (dir) {
|
|
124
|
+
try {
|
|
125
|
+
fs.rmdirSync(dir);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
/* ignora */
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
// Spawn do subagent
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
export async function runSingleAgent(defaultCwd, agents, agentName, task, cwd, step, signal, onUpdate, makeDetails) {
|
|
136
|
+
const agent = agents.find((a) => a.name === agentName);
|
|
137
|
+
if (!agent) {
|
|
138
|
+
const available = agents.map((a) => `"${a.name}"`).join(", ") || "nenhum";
|
|
139
|
+
return {
|
|
140
|
+
agent: agentName,
|
|
141
|
+
agentSource: "unknown",
|
|
142
|
+
task,
|
|
143
|
+
exitCode: 1,
|
|
144
|
+
messages: [],
|
|
145
|
+
stderr: `Agente desconhecido: "${agentName}". Agentes disponíveis: ${available}.`,
|
|
146
|
+
usage: {
|
|
147
|
+
input: 0,
|
|
148
|
+
output: 0,
|
|
149
|
+
cacheRead: 0,
|
|
150
|
+
cacheWrite: 0,
|
|
151
|
+
cost: 0,
|
|
152
|
+
contextTokens: 0,
|
|
153
|
+
turns: 0,
|
|
154
|
+
},
|
|
155
|
+
step,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const childArgs = ["--mode", "json", "--no-session"];
|
|
159
|
+
if (agent.model)
|
|
160
|
+
childArgs.push("--model", agent.model);
|
|
161
|
+
if (agent.tools && agent.tools.length > 0) {
|
|
162
|
+
childArgs.push("--tools", agent.tools.join(","));
|
|
163
|
+
}
|
|
164
|
+
let tmpDir = null;
|
|
165
|
+
let tmpPath = null;
|
|
166
|
+
const currentResult = {
|
|
167
|
+
agent: agentName,
|
|
168
|
+
agentSource: agent.source,
|
|
169
|
+
task,
|
|
170
|
+
exitCode: 0,
|
|
171
|
+
messages: [],
|
|
172
|
+
stderr: "",
|
|
173
|
+
usage: {
|
|
174
|
+
input: 0,
|
|
175
|
+
output: 0,
|
|
176
|
+
cacheRead: 0,
|
|
177
|
+
cacheWrite: 0,
|
|
178
|
+
cost: 0,
|
|
179
|
+
contextTokens: 0,
|
|
180
|
+
turns: 0,
|
|
181
|
+
},
|
|
182
|
+
model: agent.model,
|
|
183
|
+
step,
|
|
184
|
+
};
|
|
185
|
+
const emitUpdate = () => {
|
|
186
|
+
if (onUpdate) {
|
|
187
|
+
onUpdate({
|
|
188
|
+
content: [
|
|
189
|
+
{
|
|
190
|
+
type: "text",
|
|
191
|
+
text: getFinalOutput(currentResult.messages) || "(executando...)",
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
details: makeDetails([currentResult]),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
try {
|
|
199
|
+
if (agent.systemPrompt.trim()) {
|
|
200
|
+
const tmp = await writePromptToTempFile(agent.name, agent.systemPrompt);
|
|
201
|
+
tmpDir = tmp.dir;
|
|
202
|
+
tmpPath = tmp.filePath;
|
|
203
|
+
childArgs.push("--append-system-prompt", tmpPath);
|
|
204
|
+
}
|
|
205
|
+
// Passa a task como argumento posicional (mensagem inicial)
|
|
206
|
+
childArgs.push(task);
|
|
207
|
+
let wasAborted = false;
|
|
208
|
+
const exitCode = await new Promise((resolve) => {
|
|
209
|
+
const invocation = getApiarioInvocation(childArgs);
|
|
210
|
+
const proc = spawn(invocation.command, invocation.args, {
|
|
211
|
+
cwd: cwd ?? defaultCwd,
|
|
212
|
+
shell: false,
|
|
213
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
214
|
+
});
|
|
215
|
+
let buffer = "";
|
|
216
|
+
const processLine = (line) => {
|
|
217
|
+
if (!line.trim())
|
|
218
|
+
return;
|
|
219
|
+
let event;
|
|
220
|
+
try {
|
|
221
|
+
event = JSON.parse(line);
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (event.type === "message_end" && event.message) {
|
|
227
|
+
const msg = event.message;
|
|
228
|
+
currentResult.messages.push(msg);
|
|
229
|
+
if (msg.role === "assistant") {
|
|
230
|
+
currentResult.usage.turns++;
|
|
231
|
+
const usage = msg.usage;
|
|
232
|
+
if (usage) {
|
|
233
|
+
currentResult.usage.input += usage.input || 0;
|
|
234
|
+
currentResult.usage.output += usage.output || 0;
|
|
235
|
+
currentResult.usage.cacheRead += usage.cacheRead || 0;
|
|
236
|
+
currentResult.usage.cacheWrite += usage.cacheWrite || 0;
|
|
237
|
+
currentResult.usage.cost += usage.cost?.total || 0;
|
|
238
|
+
currentResult.usage.contextTokens = usage.totalTokens || 0;
|
|
239
|
+
}
|
|
240
|
+
if (!currentResult.model && msg.model)
|
|
241
|
+
currentResult.model = msg.model;
|
|
242
|
+
if (msg.stopReason)
|
|
243
|
+
currentResult.stopReason = msg.stopReason;
|
|
244
|
+
if (msg.errorMessage)
|
|
245
|
+
currentResult.errorMessage = msg.errorMessage;
|
|
246
|
+
}
|
|
247
|
+
emitUpdate();
|
|
248
|
+
}
|
|
249
|
+
if (event.type === "tool_execution_end" && event.toolCallId) {
|
|
250
|
+
currentResult.messages.push({
|
|
251
|
+
role: "assistant",
|
|
252
|
+
content: [
|
|
253
|
+
{
|
|
254
|
+
type: "toolCall",
|
|
255
|
+
id: event.toolCallId,
|
|
256
|
+
name: event.toolName,
|
|
257
|
+
arguments: event.args,
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
});
|
|
261
|
+
emitUpdate();
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
proc.stdout.on("data", (data) => {
|
|
265
|
+
buffer += data.toString();
|
|
266
|
+
const lines = buffer.split("\n");
|
|
267
|
+
buffer = lines.pop() || "";
|
|
268
|
+
for (const line of lines)
|
|
269
|
+
processLine(line);
|
|
270
|
+
});
|
|
271
|
+
proc.stderr.on("data", (data) => {
|
|
272
|
+
currentResult.stderr += data.toString();
|
|
273
|
+
});
|
|
274
|
+
proc.on("close", (code) => {
|
|
275
|
+
if (buffer.trim())
|
|
276
|
+
processLine(buffer);
|
|
277
|
+
resolve(code ?? 0);
|
|
278
|
+
});
|
|
279
|
+
proc.on("error", () => {
|
|
280
|
+
resolve(1);
|
|
281
|
+
});
|
|
282
|
+
if (signal) {
|
|
283
|
+
const killProc = () => {
|
|
284
|
+
wasAborted = true;
|
|
285
|
+
proc.kill("SIGTERM");
|
|
286
|
+
setTimeout(() => {
|
|
287
|
+
if (!proc.killed)
|
|
288
|
+
proc.kill("SIGKILL");
|
|
289
|
+
}, 5000);
|
|
290
|
+
};
|
|
291
|
+
if (signal.aborted)
|
|
292
|
+
killProc();
|
|
293
|
+
else
|
|
294
|
+
signal.addEventListener("abort", killProc, { once: true });
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
currentResult.exitCode = exitCode;
|
|
298
|
+
if (wasAborted)
|
|
299
|
+
throw new Error("Subagent interrompido pelo usuário");
|
|
300
|
+
return currentResult;
|
|
301
|
+
}
|
|
302
|
+
finally {
|
|
303
|
+
cleanupTemp(tmpDir, tmpPath);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// ---------------------------------------------------------------------------
|
|
307
|
+
// Concorrência limitada
|
|
308
|
+
// ---------------------------------------------------------------------------
|
|
309
|
+
export async function mapWithConcurrencyLimit(items, concurrency, fn) {
|
|
310
|
+
if (items.length === 0)
|
|
311
|
+
return [];
|
|
312
|
+
const limit = Math.max(1, Math.min(concurrency, items.length));
|
|
313
|
+
const results = new Array(items.length);
|
|
314
|
+
let nextIndex = 0;
|
|
315
|
+
const workers = new Array(limit).fill(null).map(async () => {
|
|
316
|
+
while (true) {
|
|
317
|
+
const current = nextIndex++;
|
|
318
|
+
if (current >= items.length)
|
|
319
|
+
return;
|
|
320
|
+
results[current] = await fn(items[current], current);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
await Promise.all(workers);
|
|
324
|
+
return results;
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=spawn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.js","sourceRoot":"","sources":["../../../src/extensions/subagent/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAwCxE,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E,MAAM,mBAAmB,GAAG,EAAE,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AC;QACxD,OAAO,aAAa,CAAC;IACvB,CAAC;YAAS,CAAC;QACT,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAY,EACZ,WAAmB,EACnB,EAA+C;IAE/C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/D,MAAM,OAAO,GAAW,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChD,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;QACzD,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC;YAC5B,IAAI,OAAO,IAAI,KAAK,CAAC,MAAM;gBAAE,OAAO;YACpC,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;QACvD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3B,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apiario",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "CLI Harness — pi.dev TUI wrapper for Apiário Dev API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"apiario": "
|
|
7
|
+
"apiario": "dist/cli.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"dev": "tsc --watch"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@earendil-works/pi-ai": "^0.79.
|
|
16
|
-
"@earendil-works/pi-coding-agent": "^0.79.
|
|
17
|
-
"@earendil-works/pi-tui": "^0.79.
|
|
15
|
+
"@earendil-works/pi-ai": "^0.79.6",
|
|
16
|
+
"@earendil-works/pi-coding-agent": "^0.79.6",
|
|
17
|
+
"@earendil-works/pi-tui": "^0.79.6",
|
|
18
18
|
"typebox": "1.1.38"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"node": ">=20.6.0"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"dist"
|
|
27
|
+
"dist",
|
|
28
|
+
"skills"
|
|
28
29
|
]
|
|
29
30
|
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: git-worktree
|
|
3
|
+
description: Isola todas as alterações de código em um git worktree separado, protegendo a branch atual de mudanças durante a implementação de features ou correções
|
|
4
|
+
compatibility: Requer git >= 2.5 (git worktree add) e permissão de escrita no sistema de arquivos
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Git Worktree
|
|
8
|
+
|
|
9
|
+
## Visão Geral
|
|
10
|
+
|
|
11
|
+
Garante que o trabalho aconteça em um workspace isolado. Prefere ferramentas nativas de worktree da plataforma. Usa `git worktree` manual como fallback apenas quando não há ferramenta nativa disponível.
|
|
12
|
+
|
|
13
|
+
**Princípio central:** Detecte isolamento existente primeiro. Use ferramentas nativas. Depois fallback para git. Nunca lute contra o harness.
|
|
14
|
+
|
|
15
|
+
**Anuncie no início:** "Estou usando a skill git-worktree para configurar um workspace isolado."
|
|
16
|
+
|
|
17
|
+
## Passo 0: Detectar Isolamento Existente
|
|
18
|
+
|
|
19
|
+
**Antes de criar qualquer coisa, verifique se você já está em um workspace isolado.**
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
|
|
23
|
+
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
|
|
24
|
+
BRANCH=$(git branch --show-current)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Proteção contra submodules:** `GIT_DIR != GIT_COMMON` também é verdadeiro dentro de submodules. Antes de concluir "já estou em um worktree", verifique se não está em um submodule:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Se retornar um caminho, você está em um submodule — trate como repositório normal
|
|
31
|
+
git rev-parse --show-superproject-working-tree 2>/dev/null
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Se `GIT_DIR != GIT_COMMON` (e não for submodule):** Você já está em um worktree vinculado. Pule para o Passo 2 (Configuração do Projeto). NÃO crie outro worktree.
|
|
35
|
+
|
|
36
|
+
Reporte o estado da branch:
|
|
37
|
+
- Em uma branch: "Já estou em workspace isolado em `<caminho>` na branch `<nome>`."
|
|
38
|
+
- HEAD detached: "Já estou em workspace isolado em `<caminho>` (HEAD detached, gerenciado externamente). Criação de branch necessária no final."
|
|
39
|
+
|
|
40
|
+
**Se `GIT_DIR == GIT_COMMON` (ou em submodule):** Você está em um checkout normal do repositório.
|
|
41
|
+
|
|
42
|
+
O usuário já indicou sua preferência de worktree nas instruções? Se não, peça consentimento antes de criar um worktree:
|
|
43
|
+
|
|
44
|
+
> "Gostaria que eu configurasse um worktree isolado? Isso protege sua branch atual de alterações."
|
|
45
|
+
|
|
46
|
+
Respeite qualquer preferência já declarada sem perguntar novamente. Se o usuário recusar, trabalhe no diretório atual e pule para o Passo 2.
|
|
47
|
+
|
|
48
|
+
## Passo 1: Criar Workspace Isolado
|
|
49
|
+
|
|
50
|
+
**Você tem dois mecanismos. Tente nesta ordem.**
|
|
51
|
+
|
|
52
|
+
### 1a. Ferramentas Nativas de Worktree (preferido)
|
|
53
|
+
|
|
54
|
+
O usuário pediu um workspace isolado (consentimento do Passo 0). Você já tem uma forma de criar worktree? Pode ser uma ferramenta com nome `EnterWorktree`, `WorktreeCreate`, um comando `/worktree` ou uma flag `--worktree`. Se tiver, use e pule para o Passo 2.
|
|
55
|
+
|
|
56
|
+
Ferramentas nativas cuidam da colocação do diretório, criação da branch e limpeza automaticamente. Usar `git worktree add` quando você tem uma ferramenta nativa cria estado fantasma que seu harness não consegue ver ou gerenciar.
|
|
57
|
+
|
|
58
|
+
Só prossiga para o Passo 1b se não tiver ferramenta nativa de worktree disponível.
|
|
59
|
+
|
|
60
|
+
### 1b. Git Worktree Fallback
|
|
61
|
+
|
|
62
|
+
**Use apenas se o Passo 1a não se aplicar** — você não tem ferramenta nativa de worktree disponível. Crie um worktree manualmente usando git.
|
|
63
|
+
|
|
64
|
+
#### Seleção de Diretório
|
|
65
|
+
|
|
66
|
+
Siga esta ordem de prioridade. Preferência explícita do usuário sempre vence estado observado do filesystem.
|
|
67
|
+
|
|
68
|
+
1. **Verifique suas instruções para uma preferência de diretório de worktree declarada.** Se o usuário já especificou uma, use sem perguntar.
|
|
69
|
+
|
|
70
|
+
2. **Verifique se existe um diretório de worktree local do projeto:**
|
|
71
|
+
```bash
|
|
72
|
+
ls -d .worktrees 2>/dev/null # Preferido (oculto)
|
|
73
|
+
ls -d worktrees 2>/dev/null # Alternativa
|
|
74
|
+
```
|
|
75
|
+
Se encontrado, use. Se ambos existirem, `.worktrees` vence.
|
|
76
|
+
|
|
77
|
+
3. **Se não houver outra orientação disponível**, use `.worktrees/` na raiz do projeto como padrão.
|
|
78
|
+
|
|
79
|
+
#### Verificação de Segurança (apenas diretórios locais do projeto)
|
|
80
|
+
|
|
81
|
+
**DEVE verificar se o diretório está no .gitignore antes de criar worktree:**
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Se NÃO estiver ignorado:** Adicione ao .gitignore, faça commit da mudança, então prossiga.
|
|
88
|
+
|
|
89
|
+
**Por que é crítico:** Previne que conteúdo do worktree seja acidentalmente commitado ao repositório.
|
|
90
|
+
|
|
91
|
+
#### Criar o Worktree
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Determine o caminho baseado na localização escolhida
|
|
95
|
+
caminho="$LOCALIZACAO/$NOME_DA_BRANCH"
|
|
96
|
+
|
|
97
|
+
git worktree add "$caminho" -b "$NOME_DA_BRANCH"
|
|
98
|
+
cd "$caminho"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Sandbox fallback:** Se `git worktree add` falhar com erro de permissão (negação do sandbox), informe que o sandbox bloqueou a criação do worktree e que você está trabalhando no diretório atual. Então execute setup e testes de baseline no lugar.
|
|
102
|
+
|
|
103
|
+
## Passo 2: Configuração do Projeto
|
|
104
|
+
|
|
105
|
+
Auto-detecte e execute o setup apropriado:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Node.js
|
|
109
|
+
if [ -f package.json ]; then npm install; fi
|
|
110
|
+
|
|
111
|
+
# Rust
|
|
112
|
+
if [ -f Cargo.toml ]; then cargo build; fi
|
|
113
|
+
|
|
114
|
+
# Python
|
|
115
|
+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
|
116
|
+
if [ -f pyproject.toml ]; then poetry install; fi
|
|
117
|
+
|
|
118
|
+
# Go
|
|
119
|
+
if [ -f go.mod ]; then go mod download; fi
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Passo 3: Verificar Baseline Limpo
|
|
123
|
+
|
|
124
|
+
Execute testes para garantir que o workspace começa limpo:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Use o comando apropriado para o projeto
|
|
128
|
+
npm test / cargo test / pytest / go test ./...
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Se os testes falharem:** Reporte as falhas, pergunte se deve prosseguir ou investigar.
|
|
132
|
+
|
|
133
|
+
**Se os testes passarem:** Reporte pronto.
|
|
134
|
+
|
|
135
|
+
### Relatório
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
Worktree pronto em <caminho-completo>
|
|
139
|
+
Testes passando (<N> testes, 0 falhas)
|
|
140
|
+
Pronto para implementar <nome-da-feature>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Tabela de Referência Rápida
|
|
144
|
+
|
|
145
|
+
| Situação | Ação |
|
|
146
|
+
|----------|------|
|
|
147
|
+
| Já em worktree vinculado | Pule criação (Passo 0) |
|
|
148
|
+
| Em submodule | Trate como repositório normal (guarda do Passo 0) |
|
|
149
|
+
| Ferramenta nativa de worktree disponível | Use (Passo 1a) |
|
|
150
|
+
| Sem ferramenta nativa | Fallback git worktree (Passo 1b) |
|
|
151
|
+
| `.worktrees/` existe | Use (verifique se ignorado) |
|
|
152
|
+
| `worktrees/` existe | Use (verifique se ignorado) |
|
|
153
|
+
| Ambos existem | Use `.worktrees/` |
|
|
154
|
+
| Nenhum existe | Verifique instruções, depois padrão `.worktrees/` |
|
|
155
|
+
| Diretório não ignorado | Adicione ao .gitignore + commit |
|
|
156
|
+
| Erro de permissão ao criar | Sandbox fallback, trabalhe no lugar |
|
|
157
|
+
| Testes falham no baseline | Reporte falhas + pergunte |
|
|
158
|
+
| Sem package.json/Cargo.toml | Pule instalação de dependências |
|
|
159
|
+
|
|
160
|
+
## Erros Comuns
|
|
161
|
+
|
|
162
|
+
### Lutando contra o harness
|
|
163
|
+
|
|
164
|
+
- **Problema:** Usar `git worktree add` quando a plataforma já oferece isolamento
|
|
165
|
+
- **Correção:** Passo 0 detecta isolamento existente. Passo 1a delega para ferramentas nativas.
|
|
166
|
+
|
|
167
|
+
### Pulando detecção
|
|
168
|
+
|
|
169
|
+
- **Problema:** Criar worktree aninhado dentro de um worktree existente
|
|
170
|
+
- **Correção:** Sempre execute o Passo 0 antes de criar qualquer coisa
|
|
171
|
+
|
|
172
|
+
### Pulando verificação de ignorado
|
|
173
|
+
|
|
174
|
+
- **Problema:** Conteúdo do worktree fica rastreado, poluindo git status
|
|
175
|
+
- **Correção:** Sempre use `git check-ignore` antes de criar worktree local do projeto
|
|
176
|
+
|
|
177
|
+
### Assumindo localização do diretório
|
|
178
|
+
|
|
179
|
+
- **Problema:** Cria inconsistência, viola convenções do projeto
|
|
180
|
+
- **Correção:** Siga prioridade: instruções explícitas > diretório local existente do projeto > padrão
|
|
181
|
+
|
|
182
|
+
### Prosseguindo com testes falhando
|
|
183
|
+
|
|
184
|
+
- **Problema:** Não é possível distinguir novos bugs de problemas pré-existentes
|
|
185
|
+
- **Correção:** Reporte falhas, obtenha permissão explícita para prosseguir
|
|
186
|
+
|
|
187
|
+
## Bandeiras Vermelhas
|
|
188
|
+
|
|
189
|
+
**Nunca:**
|
|
190
|
+
- Crie worktree quando o Passo 0 detecta isolamento existente
|
|
191
|
+
- Use `git worktree add` quando você tem ferramenta nativa de worktree (ex.: `EnterWorktree`). Este é o erro #1 — se você tem, use-a.
|
|
192
|
+
- Pule o Passo 1a indo direto para comandos git do Passo 1b
|
|
193
|
+
- Crie worktree sem verificar se o diretório está ignorado (local do projeto)
|
|
194
|
+
- Pule verificação de baseline de testes
|
|
195
|
+
- Prossiga com testes falhando sem perguntar
|
|
196
|
+
|
|
197
|
+
**Sempre:**
|
|
198
|
+
- Execute detecção do Passo 0 primeiro
|
|
199
|
+
- Prefira ferramentas nativas sobre fallback git
|
|
200
|
+
- Siga prioridade de diretório: instruções explícitas > diretório local existente do projeto > padrão
|
|
201
|
+
- Verifique se o diretório está ignorado para diretórios locais do projeto
|
|
202
|
+
- Auto-detecte e execute setup do projeto
|
|
203
|
+
- Verifique baseline limpo de testes
|