@oyasmi/pipiclaw 0.9.5 → 0.9.6-beta.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/README.en.md +300 -142
- package/README.md +295 -140
- package/dist/agent/builtin-commands.d.ts +1 -1
- package/dist/agent/builtin-commands.js +1 -1
- package/dist/agent/channel-runner.d.ts +4 -3
- package/dist/agent/channel-runner.js +17 -28
- package/dist/agent/maintenance-context.js +2 -2
- package/dist/agent/prompt/builder.d.ts +1 -1
- package/dist/agent/prompt/builder.js +1 -1
- package/dist/agent/prompt/extension.d.ts +1 -1
- package/dist/agent/prompt/extension.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +12 -5
- package/dist/agent/prompt/resources.d.ts +0 -3
- package/dist/agent/prompt/resources.js +0 -6
- package/dist/agent/prompt/sections.d.ts +2 -2
- package/dist/agent/prompt/sections.js +36 -26
- package/dist/agent/prompt/types.d.ts +3 -2
- package/dist/agent/runner-factory.js +1 -1
- package/dist/agent/session/command-extension.js +3 -1
- package/dist/agent/session/compaction-summary.js +3 -6
- package/dist/agent/session/compaction.d.ts +2 -0
- package/dist/agent/session/compaction.js +22 -14
- package/dist/agent/session/event-guards.d.ts +2 -1
- package/dist/agent/session/event-guards.js +6 -0
- package/dist/agent/session/model-selection.d.ts +2 -1
- package/dist/agent/session/model-selection.js +5 -5
- package/dist/agent/session/session-events.js +31 -4
- package/dist/agent/session/session-host.d.ts +5 -3
- package/dist/agent/session/session-host.js +20 -16
- package/dist/agent/status-render.js +3 -0
- package/dist/agent/stop-watchdog.js +5 -1
- package/dist/agent/turn/task-digest.d.ts +2 -5
- package/dist/agent/turn/task-digest.js +25 -45
- package/dist/agent/turn/turn-context.js +4 -6
- package/dist/agent/turn/turn-error.d.ts +1 -1
- package/dist/agent/turn/turn-error.js +9 -0
- package/dist/agent/turn/turn-pipeline.d.ts +10 -5
- package/dist/agent/turn/turn-pipeline.js +36 -7
- package/dist/agent/turn/turn-prompt.d.ts +2 -0
- package/dist/agent/turn/turn-prompt.js +2 -1
- package/dist/agent/turn/turn-recovery.js +4 -1
- package/dist/agent/turn/turn-state.d.ts +2 -0
- package/dist/agent/turn/turn-state.js +2 -1
- package/dist/agent/types.d.ts +23 -3
- package/dist/agent/types.js +2 -0
- package/dist/app/auth-command.d.ts +25 -0
- package/dist/app/auth-command.js +200 -67
- package/dist/app/home.d.ts +7 -8
- package/dist/app/home.js +143 -56
- package/dist/channel/attachments.d.ts +4 -0
- package/dist/channel/attachments.js +4 -0
- package/dist/channel/channel-context.d.ts +6 -0
- package/dist/channel/config.d.ts +3 -0
- package/dist/channel/config.js +11 -5
- package/dist/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +42 -10
- package/dist/commands/router.js +5 -1
- package/dist/desk/commands.d.ts +44 -5
- package/dist/desk/commands.js +162 -28
- package/dist/desk/paths.d.ts +6 -0
- package/dist/desk/paths.js +21 -1
- package/dist/desk/registry.d.ts +17 -2
- package/dist/desk/registry.js +122 -12
- package/dist/desk/types.d.ts +83 -1
- package/dist/dingtalk/bot.d.ts +1 -1
- package/dist/dingtalk/bot.js +4 -3
- package/dist/dingtalk/config.js +10 -10
- package/dist/dingtalk/delivery.js +15 -8
- package/dist/dingtalk/inbound-media.d.ts +36 -14
- package/dist/dingtalk/inbound-media.js +71 -12
- package/dist/dingtalk/inbound.d.ts +9 -2
- package/dist/dingtalk/inbound.js +17 -2
- package/dist/dingtalk/media.d.ts +4 -10
- package/dist/dingtalk/media.js +58 -32
- package/dist/events/commands.d.ts +2 -0
- package/dist/events/commands.js +13 -8
- package/dist/events/history.d.ts +9 -0
- package/dist/events/history.js +66 -0
- package/dist/events/parse.js +7 -3
- package/dist/events/types.d.ts +3 -0
- package/dist/events/watcher.d.ts +4 -8
- package/dist/events/watcher.js +53 -58
- package/dist/jobs/kill.d.ts +23 -0
- package/dist/jobs/kill.js +65 -0
- package/dist/jobs/manager.d.ts +19 -18
- package/dist/jobs/manager.js +36 -103
- package/dist/main.js +15 -3
- package/dist/memory/boundary-work.d.ts +2 -1
- package/dist/memory/boundary-work.js +1 -1
- package/dist/memory/lifecycle.d.ts +2 -1
- package/dist/memory/lifecycle.js +2 -2
- package/dist/memory/reflect-job.d.ts +2 -1
- package/dist/memory/reflect-job.js +1 -1
- package/dist/memory/reflect.d.ts +2 -1
- package/dist/memory/reflect.js +25 -4
- package/dist/memory/scheduler.d.ts +2 -1
- package/dist/memory/scheduler.js +1 -1
- package/dist/memory/session-corpus.d.ts +1 -1
- package/dist/memory/session-corpus.js +76 -1
- package/dist/memory/session-search.d.ts +2 -1
- package/dist/memory/session-search.js +14 -12
- package/dist/memory/sidecar-worker.d.ts +2 -1
- package/dist/memory/sidecar-worker.js +2 -4
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +19 -9
- package/dist/models/credential-work.d.ts +7 -0
- package/dist/models/credential-work.js +36 -0
- package/dist/models/login-ui.js +4 -4
- package/dist/models/provider-login.js +7 -6
- package/dist/models/requests.d.ts +8 -0
- package/dist/models/requests.js +69 -0
- package/dist/models/runtime.d.ts +3 -1
- package/dist/models/runtime.js +9 -2
- package/dist/playbooks/agent-delegation.md +20 -45
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/delegation-inline.md +25 -0
- package/dist/playbooks/delegation-recovery.md +28 -0
- package/dist/playbooks/event-scheduling.md +18 -37
- package/dist/playbooks/event-sensors.md +26 -0
- package/dist/playbooks/event-task-template.md +22 -0
- package/dist/playbooks/learning-and-skills.md +26 -0
- package/dist/playbooks/memory-operations.md +36 -0
- package/dist/playbooks/outbound-media.md +2 -2
- package/dist/playbooks/runtime-files.md +29 -0
- package/dist/playbooks/runtime-operations.md +25 -0
- package/dist/playbooks/runtime-orientation.md +18 -53
- package/dist/playbooks/task-lead.md +22 -68
- package/dist/playbooks/task-manage.md +38 -0
- package/dist/playbooks/task-recovery.md +24 -0
- package/dist/playbooks/task-verify.md +22 -0
- package/dist/runtime/bootstrap.d.ts +10 -0
- package/dist/runtime/bootstrap.js +93 -29
- package/dist/runtime/daemon-lock.js +3 -3
- package/dist/runtime/desk-runtime.d.ts +40 -7
- package/dist/runtime/desk-runtime.js +330 -44
- package/dist/runtime/durable-dispatch.d.ts +14 -2
- package/dist/runtime/durable-dispatch.js +207 -65
- package/dist/runtime/ingress-busy.js +17 -8
- package/dist/runtime/ingress-commands.js +24 -4
- package/dist/runtime/ingress-deps.d.ts +4 -1
- package/dist/runtime/ingress.js +6 -1
- package/dist/runtime/request-execution.js +7 -6
- package/dist/runtime/shutdown.d.ts +4 -1
- package/dist/runtime/shutdown.js +88 -35
- package/dist/runtime/task-close.d.ts +1 -1
- package/dist/runtime/task-close.js +6 -3
- package/dist/runtime/task-control.d.ts +2 -3
- package/dist/runtime/task-control.js +38 -11
- package/dist/runtime/task-input.js +1 -1
- package/dist/runtime/task-lane-types.d.ts +12 -2
- package/dist/runtime/task-lane-types.js +9 -0
- package/dist/runtime/task-lane.d.ts +2 -0
- package/dist/runtime/task-lane.js +38 -20
- package/dist/runtime/task-step.d.ts +3 -3
- package/dist/runtime/task-step.js +34 -16
- package/dist/runtime/transports.js +6 -5
- package/dist/runtime/turn-run.js +103 -66
- package/dist/security/command-guard.d.ts +1 -1
- package/dist/security/command-guard.js +259 -314
- package/dist/security/path-guard.js +48 -7
- package/dist/security/shell-parse.d.ts +10 -0
- package/dist/security/shell-parse.js +224 -0
- package/dist/security/types.d.ts +2 -0
- package/dist/subagents/commands.d.ts +1 -1
- package/dist/subagents/commands.js +14 -5
- package/dist/subagents/completion-wake.js +6 -0
- package/dist/subagents/detached-discovery.d.ts +1 -1
- package/dist/subagents/discovery.d.ts +18 -199
- package/dist/subagents/discovery.js +35 -289
- package/dist/subagents/dispatch.d.ts +1 -2
- package/dist/subagents/dispatch.js +50 -29
- package/dist/subagents/external/antigravity-cli.d.ts +2 -0
- package/dist/subagents/external/antigravity-cli.js +517 -0
- package/dist/subagents/external/claude-code.js +8 -17
- package/dist/subagents/external/codex-cli.js +8 -18
- package/dist/subagents/external/cursor-cli.js +34 -31
- package/dist/subagents/external/dispatch.d.ts +21 -7
- package/dist/subagents/external/dispatch.js +146 -12
- package/dist/subagents/external/exec.js +3 -0
- package/dist/subagents/external/harness.d.ts +57 -33
- package/dist/subagents/external/harness.js +69 -40
- package/dist/subagents/external/reconciliation.js +1 -0
- package/dist/subagents/external/registry.js +4 -1
- package/dist/subagents/external/role-warnings.d.ts +4 -13
- package/dist/subagents/external/role-warnings.js +4 -28
- package/dist/subagents/external/run.d.ts +1 -2
- package/dist/subagents/external/run.js +16 -26
- package/dist/subagents/external/settlement.d.ts +2 -0
- package/dist/subagents/external/settlement.js +13 -3
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/internal/outcome.d.ts +1 -2
- package/dist/subagents/internal/outcome.js +19 -12
- package/dist/subagents/internal/provider-retry.d.ts +1 -2
- package/dist/subagents/internal/provider-retry.js +2 -4
- package/dist/subagents/internal/run.d.ts +2 -3
- package/dist/subagents/internal/run.js +27 -4
- package/dist/subagents/internal/state.d.ts +2 -5
- package/dist/subagents/internal/state.js +1 -2
- package/dist/subagents/internal/worker.d.ts +1 -2
- package/dist/subagents/internal/worker.js +20 -10
- package/dist/subagents/resolve.d.ts +56 -0
- package/dist/subagents/resolve.js +202 -0
- package/dist/subagents/result.d.ts +6 -4
- package/dist/subagents/result.js +39 -6
- package/dist/subagents/run-record.d.ts +54 -2
- package/dist/subagents/run-record.js +7 -0
- package/dist/subagents/runs.d.ts +6 -31
- package/dist/subagents/runs.js +26 -31
- package/dist/subagents/task-envelope.d.ts +1 -2
- package/dist/subagents/task-envelope.js +13 -4
- package/dist/subagents/task-settlement.js +1 -0
- package/dist/subagents/types.d.ts +105 -6
- package/dist/subagents/types.js +16 -1
- package/dist/subagents/workspace-lease.d.ts +41 -24
- package/dist/subagents/workspace-lease.js +159 -24
- package/dist/subagents/worktree.d.ts +52 -0
- package/dist/subagents/worktree.js +363 -0
- package/dist/tasks/archive.js +4 -0
- package/dist/tasks/brief.d.ts +5 -1
- package/dist/tasks/brief.js +19 -5
- package/dist/tasks/commands.d.ts +6 -1
- package/dist/tasks/commands.js +32 -7
- package/dist/tasks/control.d.ts +11 -0
- package/dist/tasks/delivery.d.ts +2 -0
- package/dist/tasks/delivery.js +141 -21
- package/dist/tasks/loop-log.d.ts +12 -0
- package/dist/tasks/loop-log.js +10 -1
- package/dist/tasks/receipts.d.ts +7 -3
- package/dist/tasks/receipts.js +34 -5
- package/dist/tools/bash.d.ts +3 -0
- package/dist/tools/bash.js +29 -15
- package/dist/tools/contract/presentation.js +7 -5
- package/dist/tools/edit-diff.d.ts +11 -0
- package/dist/tools/edit-diff.js +148 -0
- package/dist/tools/edit-match.d.ts +18 -0
- package/dist/tools/edit-match.js +242 -0
- package/dist/tools/edit.d.ts +10 -2
- package/dist/tools/edit.js +91 -361
- package/dist/tools/event-manage.d.ts +2 -1
- package/dist/tools/event-manage.js +46 -39
- package/dist/tools/file-observations.d.ts +9 -0
- package/dist/tools/file-observations.js +50 -0
- package/dist/tools/glob-match.d.ts +3 -1
- package/dist/tools/glob-match.js +40 -17
- package/dist/tools/glob.d.ts +1 -0
- package/dist/tools/glob.js +39 -19
- package/dist/tools/grep-command.d.ts +13 -0
- package/dist/tools/grep-command.js +77 -0
- package/dist/tools/grep.js +96 -201
- package/dist/tools/index.d.ts +6 -2
- package/dist/tools/index.js +9 -4
- package/dist/tools/job.js +12 -11
- package/dist/tools/read.d.ts +2 -0
- package/dist/tools/read.js +10 -2
- package/dist/tools/registry.d.ts +16 -11
- package/dist/tools/registry.js +32 -12
- package/dist/tools/send-media.js +9 -5
- package/dist/tools/session-search.d.ts +2 -1
- package/dist/tools/session-search.js +15 -5
- package/dist/tools/skill.js +13 -12
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +25 -152
- package/dist/tools/subagent.d.ts +24 -2
- package/dist/tools/subagent.js +24 -18
- package/dist/tools/task-manage/control-tools.js +1 -1
- package/dist/tools/task-manage/factory.d.ts +2 -2
- package/dist/tools/task-manage/factory.js +40 -4
- package/dist/tools/task-manage/lifecycle.d.ts +3 -3
- package/dist/tools/task-manage/lifecycle.js +56 -13
- package/dist/tools/task-manage/schema.d.ts +4 -1
- package/dist/tools/task-manage/schema.js +4 -1
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/types.d.ts +5 -1
- package/dist/tools/write-content.d.ts +7 -1
- package/dist/tools/write-content.js +18 -6
- package/dist/tools/write.d.ts +3 -0
- package/dist/tools/write.js +6 -2
- package/dist/tui/cli.d.ts +6 -6
- package/dist/tui/cli.js +120 -28
- package/dist/tui/client.d.ts +7 -0
- package/dist/tui/client.js +67 -16
- package/dist/tui/frontend.d.ts +2 -0
- package/dist/tui/pitui-frontend.d.ts +4 -0
- package/dist/tui/pitui-frontend.js +27 -0
- package/dist/tui/render.d.ts +1 -0
- package/dist/tui/render.js +5 -0
- package/dist/tui/session.js +6 -0
- package/dist/usage/ledger.d.ts +1 -1
- package/dist/usage/render.js +1 -1
- package/dist/web/client.d.ts +1 -0
- package/dist/web/client.js +11 -0
- package/dist/web/fetch.js +6 -3
- package/dist/webapi/auth.d.ts +0 -3
- package/dist/webapi/auth.js +3 -7
- package/dist/webapi/config.js +17 -14
- package/dist/webapi/key-command.js +41 -41
- package/dist/webapi/response-state.d.ts +7 -1
- package/dist/webapi/response-state.js +166 -3
- package/dist/webapi/routes/websocket.js +24 -1
- package/dist/webapi/server.d.ts +3 -1
- package/dist/webapi/server.js +32 -1
- package/dist/webapi/service.js +8 -0
- package/dist/webapi/transport.d.ts +2 -0
- package/dist/webapi/transport.js +11 -1
- package/examples/sub-agents/README.md +43 -75
- package/examples/sub-agents/agy-main.md +21 -0
- package/examples/sub-agents/claude-high.md +21 -0
- package/examples/sub-agents/claude-main.md +21 -0
- package/examples/sub-agents/codex-flash.md +21 -0
- package/examples/sub-agents/codex-high.md +21 -0
- package/examples/sub-agents/codex-main.md +21 -0
- package/examples/sub-agents/codex-review.md +20 -0
- package/examples/sub-agents/cursor-high.md +20 -0
- package/examples/sub-agents/cursor-main.md +20 -0
- package/examples/sub-agents/glm-flash.md +21 -0
- package/examples/sub-agents/glm-high.md +21 -0
- package/examples/sub-agents/pi-scout.md +20 -0
- package/package.json +11 -12
- package/dist/agent/session/request-tools.d.ts +0 -3
- package/dist/agent/session/request-tools.js +0 -20
- package/dist/models/api-keys.d.ts +0 -11
- package/dist/models/api-keys.js +0 -22
- package/dist/playbooks/memory-and-learning.md +0 -55
- package/examples/sub-agents/agents/claude-high.md +0 -23
- package/examples/sub-agents/agents/claude-main.md +0 -23
- package/examples/sub-agents/agents/codex-flash.md +0 -23
- package/examples/sub-agents/agents/codex-high.md +0 -23
- package/examples/sub-agents/agents/codex-main.md +0 -23
- package/examples/sub-agents/agents/codex-review.md +0 -23
- package/examples/sub-agents/agents/cursor-high.md +0 -22
- package/examples/sub-agents/agents/cursor-main.md +0 -22
- package/examples/sub-agents/agents/glm-flash.md +0 -23
- package/examples/sub-agents/agents/glm-high.md +0 -23
- package/examples/sub-agents/agents/scout.md +0 -30
- package/examples/sub-agents/roles/builder-hard.md +0 -34
- package/examples/sub-agents/roles/builder.md +0 -34
- package/examples/sub-agents/roles/explorer.md +0 -39
- package/examples/sub-agents/roles/git-committer.md +0 -43
- package/examples/sub-agents/roles/planner.md +0 -33
- package/examples/sub-agents/roles/reviewer.md +0 -33
- package/examples/sub-agents/roles/verifier.md +0 -35
- package/examples/sub-agents/roles/worker.md +0 -34
|
@@ -9,38 +9,26 @@ import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
|
9
9
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
10
10
|
import { clipText, errorMessage } from "../shared/text-utils.js";
|
|
11
11
|
const eventDefinitionSchema = Type.Object({
|
|
12
|
-
type: Type.Union([Type.Literal("one-shot"), Type.Literal("periodic")
|
|
13
|
-
|
|
14
|
-
}),
|
|
15
|
-
text: Type.Optional(Type.String({
|
|
16
|
-
description: "Chat message delivered to the channel when the event fires. Give either `text` or `task`, never both.",
|
|
17
|
-
})),
|
|
12
|
+
type: Type.Union([Type.Literal("one-shot"), Type.Literal("periodic")]),
|
|
13
|
+
text: Type.Optional(Type.String({ description: "Reminder message." })),
|
|
18
14
|
task: Type.Optional(Type.Object({
|
|
19
|
-
title: Type.String(
|
|
20
|
-
goal: Type.String(
|
|
21
|
-
|
|
22
|
-
}),
|
|
23
|
-
dod: Type.String({ description: 'Checklist items, e.g. "- [ ] <criterion>"; plain prose is rejected.' }),
|
|
24
|
-
items: Type.Optional(Type.Array(Type.Object({ text: Type.String({ description: "Work item text." }) }), {
|
|
25
|
-
description: "Initial Work Items, numbered W1…Wn in order.",
|
|
26
|
-
})),
|
|
15
|
+
title: Type.String(),
|
|
16
|
+
goal: Type.String(),
|
|
17
|
+
dod: Type.String({ description: "Markdown checklist." }),
|
|
18
|
+
items: Type.Optional(Type.Array(Type.Object({ text: Type.String() }))),
|
|
27
19
|
budget: Type.Optional(Type.Object({
|
|
28
20
|
steps: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
29
|
-
usd: Type.Optional(Type.Number(
|
|
21
|
+
usd: Type.Optional(Type.Number()),
|
|
30
22
|
})),
|
|
31
|
-
}, {
|
|
32
|
-
|
|
33
|
-
})),
|
|
34
|
-
at: Type.Optional(Type.String({ description: "one-shot local time, e.g. 2026-07-27T07:30:00+08:00 (2 min to ~24.8 days out)." })),
|
|
35
|
-
schedule: Type.Optional(Type.String({ description: "periodic 5-field cron, in the host timezone." })),
|
|
23
|
+
}, { description: "Task template. Provide text or task." })),
|
|
24
|
+
at: Type.Optional(Type.String({ description: "Required for one-shot: time with offset, 2 min to ~24.8 days ahead." })),
|
|
25
|
+
schedule: Type.Optional(Type.String({ description: "Required for periodic: five-field cron in host timezone." })),
|
|
36
26
|
preAction: Type.Optional(Type.Object({
|
|
37
27
|
type: Type.Literal("bash"),
|
|
38
|
-
command: Type.String({
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}, { description: "Optional gate/sensor command." })),
|
|
43
|
-
}, { description: "The event to create/update. Channel is bound automatically — do not pass channelId." });
|
|
28
|
+
command: Type.String({ description: "Exit 0 fires; nonzero skips." }),
|
|
29
|
+
timeoutMs: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
30
|
+
})),
|
|
31
|
+
});
|
|
44
32
|
const eventManageSchema = Type.Object({
|
|
45
33
|
action: Type.Union([
|
|
46
34
|
Type.Literal("list"),
|
|
@@ -48,12 +36,8 @@ const eventManageSchema = Type.Object({
|
|
|
48
36
|
Type.Literal("create"),
|
|
49
37
|
Type.Literal("update"),
|
|
50
38
|
Type.Literal("delete"),
|
|
51
|
-
],
|
|
52
|
-
|
|
53
|
-
}),
|
|
54
|
-
name: Type.Optional(Type.String({
|
|
55
|
-
description: "Event name (filename without .json); required for show/create/update/delete, ignored for list.",
|
|
56
|
-
})),
|
|
39
|
+
]),
|
|
40
|
+
name: Type.Optional(Type.String({ description: "Filename stem, required except for list." })),
|
|
57
41
|
definition: Type.Optional(eventDefinitionSchema),
|
|
58
42
|
});
|
|
59
43
|
function parseAction(action) {
|
|
@@ -114,6 +98,12 @@ function validateDefinition(definition, name, options, deliveryChannelId) {
|
|
|
114
98
|
if (definition.type === "periodic" && !definition.schedule?.trim()) {
|
|
115
99
|
throw new RecoverableToolError('A periodic event needs "schedule" (a 5-field cron expression).');
|
|
116
100
|
}
|
|
101
|
+
if (definition.preAction?.timeoutMs !== undefined &&
|
|
102
|
+
definition.preAction.timeout !== undefined &&
|
|
103
|
+
definition.preAction.timeoutMs !== definition.preAction.timeout) {
|
|
104
|
+
throw new RecoverableToolError("Conflicting preAction.timeoutMs and preAction.timeout; pass only preAction.timeoutMs (in milliseconds).");
|
|
105
|
+
}
|
|
106
|
+
const preActionTimeoutMs = definition.preAction?.timeoutMs ?? definition.preAction?.timeout;
|
|
117
107
|
// Assemble the on-disk shape. `channelId` is bound here, never taken from the model; the
|
|
118
108
|
// preAction timeout field is `timeout` (ms) on disk but `timeoutMs` in the schema so the unit
|
|
119
109
|
// is unambiguous (fix plan §3.6).
|
|
@@ -130,7 +120,7 @@ function validateDefinition(definition, name, options, deliveryChannelId) {
|
|
|
130
120
|
preAction: {
|
|
131
121
|
type: "bash",
|
|
132
122
|
command: definition.preAction.command,
|
|
133
|
-
...(
|
|
123
|
+
...(preActionTimeoutMs !== undefined ? { timeout: preActionTimeoutMs } : {}),
|
|
134
124
|
},
|
|
135
125
|
}
|
|
136
126
|
: {}),
|
|
@@ -195,16 +185,27 @@ export async function manageEvent(options, request) {
|
|
|
195
185
|
throw new RecoverableToolError(`Event "${eventName}" does not exist. Use action "list" to see what's here.`);
|
|
196
186
|
}
|
|
197
187
|
const existing = await readEvent(eventPath, eventName);
|
|
188
|
+
const shown = existing.preAction?.timeout !== undefined
|
|
189
|
+
? {
|
|
190
|
+
...existing,
|
|
191
|
+
preAction: {
|
|
192
|
+
type: existing.preAction.type,
|
|
193
|
+
command: existing.preAction.command,
|
|
194
|
+
timeoutMs: existing.preAction.timeout,
|
|
195
|
+
},
|
|
196
|
+
}
|
|
197
|
+
: existing;
|
|
198
198
|
return {
|
|
199
199
|
action: "show",
|
|
200
200
|
name: eventName,
|
|
201
201
|
path: eventPath,
|
|
202
202
|
eventType: existing.type,
|
|
203
203
|
channelId: existing.channelId,
|
|
204
|
-
notice: JSON.stringify(
|
|
204
|
+
notice: JSON.stringify(shown, null, 2),
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
207
|
if (request.action === "delete") {
|
|
208
|
+
await unlink(`${eventPath}.error.txt`).catch(() => undefined);
|
|
208
209
|
if (!existsSync(eventPath)) {
|
|
209
210
|
return {
|
|
210
211
|
action: "delete",
|
|
@@ -261,10 +262,7 @@ export function createEventManageTool(options) {
|
|
|
261
262
|
return {
|
|
262
263
|
name: "event_manage",
|
|
263
264
|
label: "event_manage",
|
|
264
|
-
description: "
|
|
265
|
-
"cadences). A created event wakes this channel; an update keeps the event's original delivery channel. Use list " +
|
|
266
|
-
"to recover event names, and show to read an event's full definition before an update. immediate events are " +
|
|
267
|
-
"rejected.",
|
|
265
|
+
description: "For a standalone text reminder with known time and offset, use event_manage as the first tool call: action=create, definition with type=one-shot, text and at (e.g. 2026-12-01T10:00:00+08:00). Confirm after success. Read event-sensors.md for preAction, event-task-template.md for task, or event-scheduling.md for other periodic or update calls. Show before replacing a definition; preserve delivery.",
|
|
268
266
|
parameters: eventManageSchema,
|
|
269
267
|
execute: async (_toolCallId, args) => {
|
|
270
268
|
const result = await manageEvent(options, {
|
|
@@ -272,7 +270,16 @@ export function createEventManageTool(options) {
|
|
|
272
270
|
name: args.name,
|
|
273
271
|
definition: args.definition,
|
|
274
272
|
});
|
|
275
|
-
|
|
273
|
+
let text = result.notice;
|
|
274
|
+
if (result.action !== "list" && result.action !== "show") {
|
|
275
|
+
const fields = [
|
|
276
|
+
`name=${result.name}`,
|
|
277
|
+
result.eventType && `type=${result.eventType}`,
|
|
278
|
+
result.channelId && `channel=${result.channelId}`,
|
|
279
|
+
result.deleted !== undefined && `deleted=${result.deleted}`,
|
|
280
|
+
].filter(Boolean);
|
|
281
|
+
text += ` (${fields.join(", ")})`;
|
|
282
|
+
}
|
|
276
283
|
return {
|
|
277
284
|
content: [{ type: "text", text }],
|
|
278
285
|
details: { ...result },
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type FileStat, type FileStore } from "../file-store.js";
|
|
2
|
+
export declare function createFileObservations(capacity?: number): {
|
|
3
|
+
record(target: string, stat: FileStat): void;
|
|
4
|
+
describeWriteNote(target: string, path: string, before?: FileStat): string | undefined;
|
|
5
|
+
describeEditNote(target: string, path: string, before: FileStat): string | undefined;
|
|
6
|
+
};
|
|
7
|
+
export type FileObservations = ReturnType<typeof createFileObservations>;
|
|
8
|
+
/** A metadata error after a successful write must not turn it into a failed tool call. */
|
|
9
|
+
export declare function observeCurrentFile(observations: FileObservations | undefined, store: FileStore, target: string): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { fingerprintOf, fingerprintsEqual, } from "../file-store.js";
|
|
2
|
+
export function createFileObservations(capacity = 256) {
|
|
3
|
+
const observed = new Map();
|
|
4
|
+
const previous = (target) => {
|
|
5
|
+
const value = observed.get(target);
|
|
6
|
+
if (value) {
|
|
7
|
+
observed.delete(target);
|
|
8
|
+
observed.set(target, value);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
record(target, stat) {
|
|
14
|
+
if (!stat.isFile)
|
|
15
|
+
return;
|
|
16
|
+
observed.delete(target);
|
|
17
|
+
observed.set(target, fingerprintOf(stat));
|
|
18
|
+
if (observed.size > capacity) {
|
|
19
|
+
const oldest = observed.keys().next().value;
|
|
20
|
+
if (oldest !== undefined)
|
|
21
|
+
observed.delete(oldest);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
describeWriteNote(target, path, before) {
|
|
25
|
+
if (!before?.isFile || before.size === 0)
|
|
26
|
+
return undefined;
|
|
27
|
+
const last = previous(target);
|
|
28
|
+
if (!last) {
|
|
29
|
+
return `Note: Overwrote existing file ${path} (${before.size} bytes) without reading it first in this session; inspect git diff if unintended.`;
|
|
30
|
+
}
|
|
31
|
+
if (!fingerprintsEqual(last, fingerprintOf(before))) {
|
|
32
|
+
return `Note: ${path} had been modified externally since you last read or wrote it; verify no concurrent changes were lost.`;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
describeEditNote(target, path, before) {
|
|
36
|
+
const last = previous(target);
|
|
37
|
+
if (last && !fingerprintsEqual(last, fingerprintOf(before))) {
|
|
38
|
+
return `Note: ${path} was modified since your last read; review surrounding context if needed.`;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** A metadata error after a successful write must not turn it into a failed tool call. */
|
|
44
|
+
export async function observeCurrentFile(observations, store, target) {
|
|
45
|
+
if (!observations)
|
|
46
|
+
return;
|
|
47
|
+
const stat = await store.stat(target).catch(() => undefined);
|
|
48
|
+
if (stat)
|
|
49
|
+
observations.record(target, stat);
|
|
50
|
+
}
|
|
@@ -29,4 +29,6 @@ export interface GlobMatcher {
|
|
|
29
29
|
/** True when `path` — a `/`-joined path relative to the walk root — matches the pattern. */
|
|
30
30
|
test(path: string): boolean;
|
|
31
31
|
}
|
|
32
|
-
export declare function compileGlobPattern(pattern: string
|
|
32
|
+
export declare function compileGlobPattern(pattern: string, options?: {
|
|
33
|
+
characterClasses?: boolean;
|
|
34
|
+
}): GlobMatcher;
|
package/dist/tools/glob-match.js
CHANGED
|
@@ -35,14 +35,15 @@ const GLOBSTAR = Symbol("globstar");
|
|
|
35
35
|
const STAR = Symbol("star");
|
|
36
36
|
/** `?` inside a segment: exactly one character. */
|
|
37
37
|
const ANY = Symbol("any");
|
|
38
|
-
export function compileGlobPattern(pattern) {
|
|
38
|
+
export function compileGlobPattern(pattern, options = {}) {
|
|
39
39
|
if (pattern.length > MAX_PATTERN_LENGTH) {
|
|
40
40
|
throw new Error(`pattern is longer than ${MAX_PATTERN_LENGTH} characters`);
|
|
41
41
|
}
|
|
42
42
|
// The anchoring decision is made on the pattern as written, before expansion: `{src/a,b}`
|
|
43
43
|
// carries a separator and is therefore path-anchored for *both* of its alternatives.
|
|
44
44
|
const matchBasenameOnly = !pattern.includes("/");
|
|
45
|
-
const
|
|
45
|
+
const characterClasses = options.characterClasses === true;
|
|
46
|
+
const variants = expandBraces(pattern, characterClasses).map((variant) => compileVariant(variant, characterClasses));
|
|
46
47
|
return {
|
|
47
48
|
test(path) {
|
|
48
49
|
const segments = matchBasenameOnly ? [path.slice(path.lastIndexOf("/") + 1)] : path.split("/");
|
|
@@ -57,13 +58,13 @@ export function compileGlobPattern(pattern) {
|
|
|
57
58
|
* and a comma inside a nested group are read the way the writer meant. An unmatched `{` stays a
|
|
58
59
|
* literal character, as it did before.
|
|
59
60
|
*/
|
|
60
|
-
function expandBraces(pattern) {
|
|
61
|
-
const open = findBraceGroup(pattern);
|
|
61
|
+
function expandBraces(pattern, characterClasses) {
|
|
62
|
+
const open = findBraceGroup(pattern, characterClasses);
|
|
62
63
|
if (!open)
|
|
63
64
|
return [pattern];
|
|
64
65
|
const results = [];
|
|
65
66
|
for (const alternative of open.alternatives) {
|
|
66
|
-
for (const expanded of expandBraces(`${open.prefix}${alternative}${open.suffix}
|
|
67
|
+
for (const expanded of expandBraces(`${open.prefix}${alternative}${open.suffix}`, characterClasses)) {
|
|
67
68
|
results.push(expanded);
|
|
68
69
|
if (results.length > MAX_BRACE_VARIANTS) {
|
|
69
70
|
throw new Error(`brace expansion produces more than ${MAX_BRACE_VARIANTS} patterns`);
|
|
@@ -72,19 +73,32 @@ function expandBraces(pattern) {
|
|
|
72
73
|
}
|
|
73
74
|
return results;
|
|
74
75
|
}
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
function classEnd(pattern, start, characterClasses) {
|
|
77
|
+
return characterClasses && pattern[start] === "[" ? pattern.indexOf("]", start + 1) : -1;
|
|
78
|
+
}
|
|
79
|
+
function findBraceGroup(pattern, characterClasses) {
|
|
80
|
+
let start = -1;
|
|
79
81
|
let depth = 0;
|
|
80
82
|
const alternatives = [];
|
|
81
83
|
let current = "";
|
|
82
|
-
for (let i =
|
|
84
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
85
|
+
const end = classEnd(pattern, i, characterClasses);
|
|
86
|
+
if (end > i) {
|
|
87
|
+
if (depth > 0)
|
|
88
|
+
current += pattern.slice(i, end + 1);
|
|
89
|
+
i = end;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
83
92
|
const char = pattern[i];
|
|
84
93
|
if (char === "{") {
|
|
85
94
|
depth++;
|
|
86
|
-
if (depth === 1)
|
|
87
|
-
|
|
95
|
+
if (depth === 1) {
|
|
96
|
+
start = i;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (depth === 0) {
|
|
101
|
+
continue;
|
|
88
102
|
}
|
|
89
103
|
else if (char === "}") {
|
|
90
104
|
depth--;
|
|
@@ -102,15 +116,24 @@ function findBraceGroup(pattern) {
|
|
|
102
116
|
}
|
|
103
117
|
return undefined; // unbalanced `{` — leave it as a literal
|
|
104
118
|
}
|
|
105
|
-
function compileVariant(pattern) {
|
|
119
|
+
function compileVariant(pattern, characterClasses) {
|
|
106
120
|
const rawSegments = pattern.split("/");
|
|
107
|
-
const segments = rawSegments.map((segment) => segment === "**" ? GLOBSTAR : compileSegment(segment));
|
|
121
|
+
const segments = rawSegments.map((segment) => segment === "**" ? GLOBSTAR : compileSegment(segment, characterClasses));
|
|
108
122
|
const trailingGlobstar = segments.length > 1 && segments[segments.length - 1] === GLOBSTAR;
|
|
109
123
|
return { segments, trailingGlobstar };
|
|
110
124
|
}
|
|
111
|
-
function compileSegment(segment) {
|
|
125
|
+
function compileSegment(segment, characterClasses) {
|
|
112
126
|
const tokens = [];
|
|
113
|
-
for (
|
|
127
|
+
for (let i = 0; i < segment.length; i++) {
|
|
128
|
+
const char = segment[i];
|
|
129
|
+
const end = classEnd(segment, i, characterClasses);
|
|
130
|
+
if (end >= 0) {
|
|
131
|
+
const body = segment.slice(i + 1, end).replace(/^!/, "^");
|
|
132
|
+
// Compile only one character class. The wildcard matcher handles the surrounding stars.
|
|
133
|
+
tokens.push(new RegExp(`[${body}]`));
|
|
134
|
+
i = end;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
114
137
|
if (char === "*") {
|
|
115
138
|
// Adjacent stars are the same star. A `**` that is not a whole segment (`a**b`) has
|
|
116
139
|
// always meant single-segment `*`, and collapsing keeps that without a second token.
|
|
@@ -180,7 +203,7 @@ function matchSegment(tokens, text) {
|
|
|
180
203
|
tokenIndex++;
|
|
181
204
|
continue;
|
|
182
205
|
}
|
|
183
|
-
if (token === ANY ||
|
|
206
|
+
if (token === ANY || token === text[textIndex] || (token instanceof RegExp && token.test(text[textIndex]))) {
|
|
184
207
|
tokenIndex++;
|
|
185
208
|
textIndex++;
|
|
186
209
|
continue;
|
package/dist/tools/glob.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.j
|
|
|
5
5
|
declare const globSchema: Type.TObject<{
|
|
6
6
|
pattern: Type.TString;
|
|
7
7
|
path: Type.TOptional<Type.TString>;
|
|
8
|
+
skip: Type.TOptional<Type.TInteger>;
|
|
8
9
|
}>;
|
|
9
10
|
export interface GlobToolOptions {
|
|
10
11
|
securityConfig?: SecurityConfig;
|
package/dist/tools/glob.js
CHANGED
|
@@ -18,6 +18,7 @@ import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
|
|
|
18
18
|
const MAX_SCAN_ENTRIES = 50_000;
|
|
19
19
|
/** Matched files are only `stat`-ed (for mtime ordering) up to this many; beyond it, scan order stands. */
|
|
20
20
|
const MAX_STAT_FOR_SORT = 2_000;
|
|
21
|
+
const STAT_CONCURRENCY = 32;
|
|
21
22
|
/** Paths shown inline; matching `grep`'s FILE_PAGE_LIMIT order of magnitude for a discovery tool. */
|
|
22
23
|
const GLOB_MAX_RESULTS = 100;
|
|
23
24
|
const globSchema = Type.Object({
|
|
@@ -26,6 +27,7 @@ const globSchema = Type.Object({
|
|
|
26
27
|
'matches the basename at any depth, so "*" and "*.ts" both search the whole tree; include a "/" to anchor the depth.',
|
|
27
28
|
}),
|
|
28
29
|
path: Type.Optional(Type.String({ description: "Directory to search in. Defaults to the current working directory." })),
|
|
30
|
+
skip: Type.Optional(Type.Integer({ minimum: 0, description: "Result offset for paging." })),
|
|
29
31
|
});
|
|
30
32
|
/** Turn a path relative to the search root into an address `read` accepts unchanged. */
|
|
31
33
|
function toReadableAddress(target, rel, securityContext) {
|
|
@@ -48,12 +50,9 @@ export function createGlobTool(fileStore, options = {}) {
|
|
|
48
50
|
return {
|
|
49
51
|
name: "glob",
|
|
50
52
|
label: "glob",
|
|
51
|
-
description:
|
|
52
|
-
"including hidden files; VCS/build directories (node_modules, .git, dist, ...) are excluded. Prefer this " +
|
|
53
|
-
"over `bash find`/`ls -R` for path discovery — it is bounded and sorted by modification time (newest first) " +
|
|
54
|
-
`when few enough files match; up to ${GLOB_MAX_RESULTS} paths come back inline.`,
|
|
53
|
+
description: `Find paths, including hidden files. Skips common VCS/build directories. Returns up to ${GLOB_MAX_RESULTS} files, newest first when possible. Use skip to page.`,
|
|
55
54
|
parameters: globSchema,
|
|
56
|
-
execute: async (_toolCallId, { pattern, path }, signal) => {
|
|
55
|
+
execute: async (_toolCallId, { pattern, path, skip }, signal) => {
|
|
57
56
|
if (!pattern.trim()) {
|
|
58
57
|
throw new RecoverableToolError("Pattern must not be empty.");
|
|
59
58
|
}
|
|
@@ -117,11 +116,16 @@ export function createGlobTool(fileStore, options = {}) {
|
|
|
117
116
|
let ordered;
|
|
118
117
|
if (sortableByMtime) {
|
|
119
118
|
const withMtime = [];
|
|
120
|
-
for (
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
for (let start = 0; start < matched.length; start += STAT_CONCURRENCY) {
|
|
120
|
+
signal?.throwIfAborted();
|
|
121
|
+
const batch = await Promise.all(matched.slice(start, start + STAT_CONCURRENCY).map(async (relativePath) => {
|
|
122
|
+
const stat = await fileStore.stat(join(target, ...relativePath.split("/")));
|
|
123
|
+
return { relativePath, mtimeMs: stat?.mtimeMs ?? 0 };
|
|
124
|
+
}));
|
|
125
|
+
withMtime.push(...batch);
|
|
123
126
|
}
|
|
124
|
-
|
|
127
|
+
signal?.throwIfAborted();
|
|
128
|
+
withMtime.sort((a, b) => b.mtimeMs - a.mtimeMs || a.relativePath.localeCompare(b.relativePath));
|
|
125
129
|
ordered = withMtime.map((entry) => entry.relativePath);
|
|
126
130
|
}
|
|
127
131
|
else {
|
|
@@ -131,14 +135,32 @@ export function createGlobTool(fileStore, options = {}) {
|
|
|
131
135
|
// `target` alone is ambiguous (read resolves relative paths against the cwd, not
|
|
132
136
|
// the search root), so emit a cwd-relative path when the hit is inside it and
|
|
133
137
|
// an absolute path otherwise.
|
|
134
|
-
const
|
|
138
|
+
const startOffset = Math.max(0, skip ?? 0);
|
|
139
|
+
const page = ordered
|
|
140
|
+
.slice(startOffset, startOffset + GLOB_MAX_RESULTS)
|
|
141
|
+
.map((rel) => toReadableAddress(target, rel, securityContext));
|
|
135
142
|
const footerParts = [];
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
143
|
+
const truncation = truncateHead(page.join("\n"));
|
|
144
|
+
let shownCount = page.length;
|
|
145
|
+
if (truncation.truncated) {
|
|
146
|
+
let chars = 0;
|
|
147
|
+
for (const [index, path] of page.entries()) {
|
|
148
|
+
chars += path.length + 1;
|
|
149
|
+
if (chars - 1 > truncation.content.length) {
|
|
150
|
+
shownCount = index;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const end = startOffset + shownCount;
|
|
156
|
+
if (page.length === 0) {
|
|
157
|
+
footerParts.push(`skip=${startOffset} is past the ${ordered.length} matches. Use skip=0 to start again.`);
|
|
158
|
+
}
|
|
159
|
+
else if (end < ordered.length) {
|
|
160
|
+
footerParts.push(`Showing ${startOffset + 1}-${end} of ${ordered.length} matches. Use skip=${end} for the next page, or narrow the pattern or path.`);
|
|
139
161
|
}
|
|
140
|
-
|
|
141
|
-
footerParts.push(
|
|
162
|
+
if (!sortableByMtime) {
|
|
163
|
+
footerParts.push("Results are in scan order (too many to sort by modification time).");
|
|
142
164
|
}
|
|
143
165
|
if (walk.truncated) {
|
|
144
166
|
footerParts.push(`Scan stopped after ${MAX_SCAN_ENTRIES.toLocaleString()} files; results may be incomplete. Narrow path to search a smaller subtree.`);
|
|
@@ -146,9 +168,7 @@ export function createGlobTool(fileStore, options = {}) {
|
|
|
146
168
|
if (readDenyExcluded > 0) {
|
|
147
169
|
footerParts.push(`${readDenyExcluded} matching path(s) excluded by the read policy.`);
|
|
148
170
|
}
|
|
149
|
-
|
|
150
|
-
const truncation = truncateHead(body);
|
|
151
|
-
let outputText = truncation.content;
|
|
171
|
+
let outputText = page.slice(0, shownCount).join("\n");
|
|
152
172
|
if (footerParts.length > 0) {
|
|
153
173
|
outputText += `\n\n[${footerParts.join(" ")}]`;
|
|
154
174
|
}
|
|
@@ -159,7 +179,7 @@ export function createGlobTool(fileStore, options = {}) {
|
|
|
159
179
|
content: [{ type: "text", text: outputText }],
|
|
160
180
|
details: {
|
|
161
181
|
matchCount: ordered.length,
|
|
162
|
-
shownCount
|
|
182
|
+
shownCount,
|
|
163
183
|
scanTruncated: walk.truncated,
|
|
164
184
|
...(readDenyExcluded > 0 ? { readDenyExcluded } : {}),
|
|
165
185
|
},
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Executor } from "../executor.js";
|
|
2
|
+
export declare function isRgAvailable(executor: Executor): Promise<boolean>;
|
|
3
|
+
interface SearchCommandOptions {
|
|
4
|
+
mode: "content" | "files" | "count";
|
|
5
|
+
pattern: string;
|
|
6
|
+
target: string;
|
|
7
|
+
glob?: string;
|
|
8
|
+
literal?: boolean;
|
|
9
|
+
caseSensitive?: boolean;
|
|
10
|
+
readDeny: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare function buildSearchCommand(useRg: boolean, options: SearchCommandOptions): string;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { shellEscape } from "../shared/os.js";
|
|
3
|
+
import { IGNORED_DIR_SEGMENTS } from "./ignore-dirs.js";
|
|
4
|
+
const rgAvailability = new WeakMap();
|
|
5
|
+
export function isRgAvailable(executor) {
|
|
6
|
+
let available = rgAvailability.get(executor);
|
|
7
|
+
if (!available) {
|
|
8
|
+
available = Promise.resolve()
|
|
9
|
+
.then(() => executor.exec("command -v rg", { timeout: 2 }))
|
|
10
|
+
.then((result) => result.code === 0, () => false);
|
|
11
|
+
rgAvailability.set(executor, available);
|
|
12
|
+
}
|
|
13
|
+
return available;
|
|
14
|
+
}
|
|
15
|
+
function denyBasenames(entries) {
|
|
16
|
+
const basenames = new Set();
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
// A literal basename pushdown can overexclude, so the complete policy still runs on returned paths.
|
|
19
|
+
if (/[*?[\]{}]/.test(entry))
|
|
20
|
+
continue;
|
|
21
|
+
const name = basename(entry.replace(/\/+$/, ""));
|
|
22
|
+
if (name && name !== "." && name !== "..")
|
|
23
|
+
basenames.add(name);
|
|
24
|
+
}
|
|
25
|
+
return basenames;
|
|
26
|
+
}
|
|
27
|
+
function rgFlags(options, denied) {
|
|
28
|
+
const flags = ["--no-config", "--null", "--no-messages", "--hidden", "--color=never"];
|
|
29
|
+
if (options.mode === "files")
|
|
30
|
+
flags.push("--files-with-matches");
|
|
31
|
+
else if (options.mode === "count")
|
|
32
|
+
flags.push("--count", "--with-filename");
|
|
33
|
+
else
|
|
34
|
+
flags.push("--line-number", "--with-filename", "--no-heading", "-B1", "-A3");
|
|
35
|
+
flags.push(options.caseSensitive === false ? "-i" : "-s");
|
|
36
|
+
if (options.literal)
|
|
37
|
+
flags.push("-F");
|
|
38
|
+
for (const segment of new Set([...IGNORED_DIR_SEGMENTS, ...denied])) {
|
|
39
|
+
// Escape a literal backslash before using it in a ripgrep glob.
|
|
40
|
+
const name = segment.replaceAll("\\", "\\\\");
|
|
41
|
+
flags.push("--glob", shellEscape(`!**/${name}/**`));
|
|
42
|
+
if (denied.has(segment))
|
|
43
|
+
flags.push("--glob", shellEscape(`!**/${name}`));
|
|
44
|
+
}
|
|
45
|
+
if (options.glob && !/[:/\\[\]{}]/.test(options.glob)) {
|
|
46
|
+
// An include --glob overrides .gitignore. A file type filter keeps the ignore rules in effect.
|
|
47
|
+
// Complex basename patterns are checked by the common output filter.
|
|
48
|
+
flags.push("--type-add", shellEscape(`pipiclawbasename:${options.glob}`), "--type", "pipiclawbasename");
|
|
49
|
+
}
|
|
50
|
+
return flags;
|
|
51
|
+
}
|
|
52
|
+
function grepFlags(options, denied) {
|
|
53
|
+
const flags = ["--null", "-I", options.literal ? "-F" : "-E"];
|
|
54
|
+
if (options.mode === "files")
|
|
55
|
+
flags.push("-rlH");
|
|
56
|
+
else
|
|
57
|
+
flags.push("-rnH");
|
|
58
|
+
if (options.mode === "content")
|
|
59
|
+
flags.push("-B1", "-A3");
|
|
60
|
+
// BSD grep's -c does not NUL-terminate its filenames. Count numbered matching lines instead.
|
|
61
|
+
if (options.caseSensitive === false)
|
|
62
|
+
flags.push("-i");
|
|
63
|
+
for (const segment of IGNORED_DIR_SEGMENTS)
|
|
64
|
+
flags.push(`--exclude-dir=${segment}`);
|
|
65
|
+
for (const base of denied) {
|
|
66
|
+
flags.push(`--exclude-dir=${shellEscape(base)}`, `--exclude=${shellEscape(base)}`);
|
|
67
|
+
}
|
|
68
|
+
// grep --include does not expand braces. The common basename filter handles those patterns.
|
|
69
|
+
if (options.glob && !/[{}]/.test(options.glob))
|
|
70
|
+
flags.push(`--include=${shellEscape(options.glob)}`);
|
|
71
|
+
return flags;
|
|
72
|
+
}
|
|
73
|
+
export function buildSearchCommand(useRg, options) {
|
|
74
|
+
const denied = denyBasenames(options.readDeny);
|
|
75
|
+
const flags = useRg ? rgFlags(options, denied) : grepFlags(options, denied);
|
|
76
|
+
return `${useRg ? "rg" : "grep"} ${flags.join(" ")} -- ${shellEscape(options.pattern)} ${shellEscape(options.target)}`;
|
|
77
|
+
}
|