@blogic-cz/agent-tools 0.14.46 → 0.14.48
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/README.md +13 -1
- package/package.json +1 -1
- package/src/config/loader.ts +81 -16
- package/src/gh-tool/index.ts +14 -11
- package/src/gh-tool/workflow.ts +60 -1
package/README.md
CHANGED
|
@@ -312,7 +312,19 @@ All settings are optional — audit works out of the box with sensible defaults.
|
|
|
312
312
|
|
|
313
313
|
## Configuration
|
|
314
314
|
|
|
315
|
-
Config is loaded
|
|
315
|
+
Config is loaded by walking up from the current working directory to the nearest regular config file:
|
|
316
|
+
|
|
317
|
+
1. `agent-tools.json`
|
|
318
|
+
2. `agent-tools.json5`
|
|
319
|
+
|
|
320
|
+
That nearest regular config is the base. Local override files are then merged from that directory down to the current working directory:
|
|
321
|
+
|
|
322
|
+
1. `agent-tools.local.json`
|
|
323
|
+
2. `agent-tools.local.json5`
|
|
324
|
+
|
|
325
|
+
Later files override earlier files. Objects are merged deeply; arrays and primitive values are replaced. Missing config = zero-config mode (works for `gh-tool`; others require config).
|
|
326
|
+
|
|
327
|
+
Use `agent-tools.local.json5` for machine-specific ports, paths, and worktree overrides. Keep local files gitignored.
|
|
316
328
|
|
|
317
329
|
### Global Settings
|
|
318
330
|
|
package/package.json
CHANGED
package/src/config/loader.ts
CHANGED
|
@@ -194,8 +194,12 @@ const AgentToolsConfigSchema = Schema.Struct({
|
|
|
194
194
|
github: Schema.optionalKey(Schema.Record(Schema.String, GitHubRepoConfigSchema)),
|
|
195
195
|
});
|
|
196
196
|
|
|
197
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
198
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
199
|
+
}
|
|
200
|
+
|
|
197
201
|
function stripUnknownTopLevelKeys(parsed: unknown): unknown {
|
|
198
|
-
if (
|
|
202
|
+
if (!isRecord(parsed)) {
|
|
199
203
|
return parsed;
|
|
200
204
|
}
|
|
201
205
|
|
|
@@ -223,40 +227,101 @@ export function decodeConfig(
|
|
|
223
227
|
}
|
|
224
228
|
}
|
|
225
229
|
|
|
226
|
-
|
|
230
|
+
const BASE_CONFIG_FILES = ["agent-tools.json", "agent-tools.json5"] as const;
|
|
231
|
+
const LOCAL_CONFIG_FILES = ["agent-tools.local.json", "agent-tools.local.json5"] as const;
|
|
232
|
+
|
|
233
|
+
async function existingFile(filePath: string): Promise<string | undefined> {
|
|
234
|
+
return (await Bun.file(filePath).exists()) ? filePath : undefined;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async function findBaseConfigDirectory(
|
|
238
|
+
startDirectory: string = process.cwd(),
|
|
239
|
+
): Promise<string | undefined> {
|
|
227
240
|
let currentDirectory = startDirectory;
|
|
228
241
|
|
|
229
242
|
while (true) {
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
243
|
+
for (const fileName of BASE_CONFIG_FILES) {
|
|
244
|
+
// eslint-disable-next-line eslint/no-await-in-loop -- sequential directory walk, each iteration may short-circuit
|
|
245
|
+
if (await Bun.file(`${currentDirectory}/${fileName}`).exists()) {
|
|
246
|
+
return currentDirectory;
|
|
247
|
+
}
|
|
234
248
|
}
|
|
235
249
|
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
250
|
+
const parentDirectory = dirname(currentDirectory);
|
|
251
|
+
if (parentDirectory === currentDirectory) {
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
currentDirectory = parentDirectory;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function findConfigFiles(startDirectory: string = process.cwd()): Promise<readonly string[]> {
|
|
259
|
+
const baseDirectory = await findBaseConfigDirectory(startDirectory);
|
|
260
|
+
if (!baseDirectory) {
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const directories: string[] = [];
|
|
265
|
+
let currentDirectory = startDirectory;
|
|
266
|
+
while (true) {
|
|
267
|
+
directories.push(currentDirectory);
|
|
268
|
+
if (currentDirectory === baseDirectory) {
|
|
269
|
+
break;
|
|
240
270
|
}
|
|
241
271
|
|
|
242
272
|
const parentDirectory = dirname(currentDirectory);
|
|
243
273
|
if (parentDirectory === currentDirectory) {
|
|
244
|
-
return
|
|
274
|
+
return [];
|
|
245
275
|
}
|
|
246
276
|
currentDirectory = parentDirectory;
|
|
247
277
|
}
|
|
278
|
+
directories.reverse();
|
|
279
|
+
|
|
280
|
+
const configFiles: string[] = [];
|
|
281
|
+
for (const directory of directories) {
|
|
282
|
+
const fileNames =
|
|
283
|
+
directory === baseDirectory
|
|
284
|
+
? [...BASE_CONFIG_FILES, ...LOCAL_CONFIG_FILES]
|
|
285
|
+
: LOCAL_CONFIG_FILES;
|
|
286
|
+
|
|
287
|
+
for (const fileName of fileNames) {
|
|
288
|
+
// eslint-disable-next-line eslint/no-await-in-loop -- config precedence is directory/file order
|
|
289
|
+
const filePath = await existingFile(`${directory}/${fileName}`);
|
|
290
|
+
if (filePath) {
|
|
291
|
+
configFiles.push(filePath);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return configFiles;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function mergeConfigValue(left: unknown, right: unknown): unknown {
|
|
300
|
+
if (!isRecord(left) || !isRecord(right)) {
|
|
301
|
+
return right;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const merged: Record<string, unknown> = { ...left };
|
|
305
|
+
for (const [key, value] of Object.entries(right)) {
|
|
306
|
+
merged[key] = key in merged ? mergeConfigValue(merged[key], value) : value;
|
|
307
|
+
}
|
|
308
|
+
return merged;
|
|
248
309
|
}
|
|
249
310
|
|
|
250
311
|
export async function loadConfig(): Promise<AgentToolsConfig | undefined> {
|
|
251
|
-
const
|
|
252
|
-
if (
|
|
312
|
+
const configPaths = await findConfigFiles();
|
|
313
|
+
if (configPaths.length === 0) {
|
|
253
314
|
return undefined;
|
|
254
315
|
}
|
|
255
316
|
|
|
256
|
-
|
|
257
|
-
const
|
|
317
|
+
let parsed: unknown = {};
|
|
318
|
+
for (const configPath of configPaths) {
|
|
319
|
+
// eslint-disable-next-line eslint/no-await-in-loop -- config precedence is file order
|
|
320
|
+
const fileContent = await Bun.file(configPath).text();
|
|
321
|
+
parsed = mergeConfigValue(parsed, Bun.JSON5.parse(fileContent));
|
|
322
|
+
}
|
|
258
323
|
|
|
259
|
-
return decodeConfig(parsed,
|
|
324
|
+
return decodeConfig(parsed, configPaths.join(", "));
|
|
260
325
|
}
|
|
261
326
|
|
|
262
327
|
export class ConfigService extends Context.Service<ConfigService, AgentToolsConfig | undefined>()(
|
package/src/gh-tool/index.ts
CHANGED
|
@@ -61,6 +61,7 @@ import {
|
|
|
61
61
|
workflowListCommand,
|
|
62
62
|
workflowLogsCommand,
|
|
63
63
|
workflowRerunCommand,
|
|
64
|
+
workflowRunCommand,
|
|
64
65
|
workflowViewCommand,
|
|
65
66
|
workflowWatchCommand,
|
|
66
67
|
} from "./workflow";
|
|
@@ -123,9 +124,10 @@ const repoCommand = Command.make("repo", {}).pipe(
|
|
|
123
124
|
|
|
124
125
|
const workflowCommand = Command.make("workflow", {}).pipe(
|
|
125
126
|
Command.withDescription(
|
|
126
|
-
"GitHub Actions workflow operations (list
|
|
127
|
+
"GitHub Actions workflow operations (run, list, view, jobs, logs, job-logs, annotations, rerun, cancel, watch)",
|
|
127
128
|
),
|
|
128
129
|
Command.withSubcommands([
|
|
130
|
+
workflowRunCommand,
|
|
129
131
|
workflowListCommand,
|
|
130
132
|
workflowViewCommand,
|
|
131
133
|
workflowJobsCommand,
|
|
@@ -172,16 +174,17 @@ WORKFLOW FOR AI AGENTS:
|
|
|
172
174
|
10. Use 'issue close --issue N --comment "reason"' to close issues
|
|
173
175
|
11. Use 'issue comment --issue N --body "text"' to comment on issues
|
|
174
176
|
12. Use 'repo info' to get repository metadata
|
|
175
|
-
13. Use 'workflow
|
|
176
|
-
14. Use 'workflow
|
|
177
|
-
15. Use 'workflow
|
|
178
|
-
16. Use 'workflow
|
|
179
|
-
17. Use 'workflow
|
|
180
|
-
18. Use 'workflow
|
|
181
|
-
19. Use '
|
|
182
|
-
20. Use 'release
|
|
183
|
-
21. Use 'release
|
|
184
|
-
22. Use '
|
|
177
|
+
13. Use 'workflow run' to dispatch workflow_dispatch workflows
|
|
178
|
+
14. Use 'workflow list' to list recent workflow runs
|
|
179
|
+
15. Use 'workflow view --run N' to inspect a specific run with jobs/steps
|
|
180
|
+
16. Use 'workflow logs --run N' to get logs (failed jobs by default)
|
|
181
|
+
17. Use 'workflow job-logs --run N --job "build-web-app"' to get clean parsed logs for a specific job
|
|
182
|
+
18. Use 'workflow annotations --run N' to list CI annotations (errors, warnings, notices)
|
|
183
|
+
19. Use 'workflow watch --run N' to watch until completion
|
|
184
|
+
20. Use 'release status' to inspect latest release + repository context
|
|
185
|
+
21. Use 'release create --tag vX.Y.Z --generate-notes' to publish a release
|
|
186
|
+
22. Use 'release edit/view/list/delete' to maintain existing releases
|
|
187
|
+
23. Use 'branch rename --old-name X --new-name Y --confirm' to rename a branch`,
|
|
185
188
|
),
|
|
186
189
|
Command.withSubcommands([
|
|
187
190
|
prCommand,
|
package/src/gh-tool/workflow.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, Flag } from "effect/unstable/cli";
|
|
1
|
+
import { Command, Flag, Param } from "effect/unstable/cli";
|
|
2
2
|
import { Console, Effect, Option } from "effect";
|
|
3
3
|
|
|
4
4
|
import { formatOption, logFormatted } from "#shared";
|
|
@@ -213,6 +213,34 @@ const cancelRun = Effect.fn("workflow.cancelRun")(function* (runId: number, repo
|
|
|
213
213
|
};
|
|
214
214
|
});
|
|
215
215
|
|
|
216
|
+
export const dispatchWorkflow = Effect.fn("workflow.dispatchWorkflow")(function* (opts: {
|
|
217
|
+
workflow: string;
|
|
218
|
+
ref: string;
|
|
219
|
+
fields: ReadonlyArray<string>;
|
|
220
|
+
repo: string | null;
|
|
221
|
+
}) {
|
|
222
|
+
const gh = yield* GitHubService;
|
|
223
|
+
const args = ["workflow", "run", opts.workflow, "--ref", opts.ref];
|
|
224
|
+
|
|
225
|
+
if (opts.repo !== null) {
|
|
226
|
+
args.push("--repo", opts.repo);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
for (const field of opts.fields) {
|
|
230
|
+
args.push("-f", field);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
yield* gh.runGh(args);
|
|
234
|
+
|
|
235
|
+
return {
|
|
236
|
+
dispatched: true as const,
|
|
237
|
+
workflow: opts.workflow,
|
|
238
|
+
ref: opts.ref,
|
|
239
|
+
repo: opts.repo,
|
|
240
|
+
fields: opts.fields,
|
|
241
|
+
};
|
|
242
|
+
});
|
|
243
|
+
|
|
216
244
|
// `gh run watch` has no native timeout (observed hanging 36 min). Block for the caller's --timeout,
|
|
217
245
|
// then fall back to a one-shot snapshot so a timeout never returns nothing.
|
|
218
246
|
const DEFAULT_WATCH_RUN_TIMEOUT_SECONDS = CI_CHECK_WATCH_TIMEOUT_MS / 1000;
|
|
@@ -649,6 +677,37 @@ export const workflowCancelCommand = Command.make(
|
|
|
649
677
|
}),
|
|
650
678
|
).pipe(Command.withDescription("Cancel an in-progress workflow run"));
|
|
651
679
|
|
|
680
|
+
export const workflowRunCommand = Command.make(
|
|
681
|
+
"run",
|
|
682
|
+
{
|
|
683
|
+
field: Param.variadic(
|
|
684
|
+
Param.string(Param.flagKind, "field").pipe(
|
|
685
|
+
Param.withAlias("f"),
|
|
686
|
+
Param.withDescription("Workflow input as key=value; may be repeated"),
|
|
687
|
+
),
|
|
688
|
+
),
|
|
689
|
+
format: formatOption,
|
|
690
|
+
ref: Flag.string("ref").pipe(
|
|
691
|
+
Flag.withDescription("Git ref to run the workflow on (branch, tag, or SHA)"),
|
|
692
|
+
),
|
|
693
|
+
repo: repoOption,
|
|
694
|
+
workflow: Flag.string("workflow").pipe(
|
|
695
|
+
Flag.withDescription("Workflow file name (e.g., build.yml) or workflow ID"),
|
|
696
|
+
),
|
|
697
|
+
},
|
|
698
|
+
({ field, format, ref, repo, workflow }) =>
|
|
699
|
+
Effect.gen(function* () {
|
|
700
|
+
const resolvedRepo = yield* resolveRepoArg(repo);
|
|
701
|
+
const result = yield* dispatchWorkflow({
|
|
702
|
+
workflow,
|
|
703
|
+
ref,
|
|
704
|
+
fields: field,
|
|
705
|
+
repo: resolvedRepo,
|
|
706
|
+
});
|
|
707
|
+
yield* logFormatted(result, format);
|
|
708
|
+
}),
|
|
709
|
+
).pipe(Command.withDescription("Dispatch a workflow_dispatch workflow run"));
|
|
710
|
+
|
|
652
711
|
export const workflowWatchCommand = Command.make(
|
|
653
712
|
"watch",
|
|
654
713
|
{
|