vouchington-tooling 0.58.0 → 0.60.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/README.md +80 -0
- package/dist/agent-issue-labels/ensure-labels.d.mts +1 -1
- package/dist/agent-issue-labels/ensure-labels.mjs +1 -1
- package/dist/browser-session-runner/tail-queue.d.mts +1 -1
- package/dist/browser-session-runner/tail-queue.mjs +1 -1
- package/dist/cli/commands/gitleaks-directory-scan.d.mts +4 -0
- package/dist/cli/commands/gitleaks-directory-scan.mjs +9 -0
- package/dist/cli/commands/hook.d.mts +2 -0
- package/dist/cli/commands/hook.mjs +19 -0
- package/dist/cli/commands/transient-retry.d.mts +13 -0
- package/dist/cli/commands/transient-retry.mjs +68 -0
- package/dist/cli/index.mjs +14 -53
- package/dist/cli/parse-forwarded-commands.d.mts +12 -0
- package/dist/cli/parse-forwarded-commands.mjs +8 -0
- package/dist/cli/parse.d.mts +12 -0
- package/dist/cli/script-paths.d.mts +5 -0
- package/dist/cli/script-paths.mjs +48 -0
- package/dist/cli/usage-text.d.mts +1 -0
- package/dist/cli/usage-text.mjs +170 -0
- package/dist/cli/usage.d.mts +2 -1
- package/dist/cli/usage.mjs +2 -149
- package/dist/command-policy/engine.d.mts +7 -0
- package/dist/command-policy/engine.mjs +58 -0
- package/dist/command-policy/git-patterns.d.mts +20 -0
- package/dist/command-policy/git-patterns.mjs +82 -0
- package/dist/command-policy/git-process.d.mts +4 -0
- package/dist/command-policy/git-process.mjs +54 -0
- package/dist/command-policy/github-checkout-owners.d.mts +22 -0
- package/dist/command-policy/github-checkout-owners.mjs +122 -0
- package/dist/command-policy/github-command-context.d.mts +6 -0
- package/dist/command-policy/github-command-context.mjs +19 -0
- package/dist/command-policy/github-command-cwd.d.mts +8 -0
- package/dist/command-policy/github-command-cwd.mjs +130 -0
- package/dist/command-policy/github-command-position.d.mts +7 -0
- package/dist/command-policy/github-command-position.mjs +12 -0
- package/dist/command-policy/github-configured-base.d.mts +25 -0
- package/dist/command-policy/github-configured-base.mjs +59 -0
- package/dist/command-policy/github-invocation.d.mts +9 -0
- package/dist/command-policy/github-invocation.mjs +80 -0
- package/dist/command-policy/github-merge-authority.d.mts +21 -0
- package/dist/command-policy/github-merge-authority.mjs +86 -0
- package/dist/command-policy/github-option-flags.d.mts +3 -0
- package/dist/command-policy/github-option-flags.mjs +67 -0
- package/dist/command-policy/github-options.d.mts +12 -0
- package/dist/command-policy/github-options.mjs +73 -0
- package/dist/command-policy/github-stack-workflow.d.mts +9 -0
- package/dist/command-policy/github-stack-workflow.mjs +94 -0
- package/dist/command-policy/github-workflow.d.mts +7 -0
- package/dist/command-policy/github-workflow.mjs +50 -0
- package/dist/command-policy/hook/args.d.mts +11 -0
- package/dist/command-policy/hook/args.mjs +49 -0
- package/dist/command-policy/hook/harness.d.mts +26 -0
- package/dist/command-policy/hook/harness.mjs +119 -0
- package/dist/command-policy/hook/policy-module.d.mts +7 -0
- package/dist/command-policy/hook/policy-module.mjs +48 -0
- package/dist/command-policy/hook/post-tool-use.d.mts +9 -0
- package/dist/command-policy/hook/post-tool-use.mjs +51 -0
- package/dist/command-policy/hook/pre-tool-use.d.mts +21 -0
- package/dist/command-policy/hook/pre-tool-use.mjs +45 -0
- package/dist/command-policy/hook/run.d.mts +17 -0
- package/dist/command-policy/hook/run.mjs +69 -0
- package/dist/command-policy/hook/types.d.mts +33 -0
- package/dist/command-policy/hook/types.mjs +5 -0
- package/dist/command-policy/index.d.mts +29 -0
- package/dist/command-policy/index.mjs +23 -0
- package/dist/command-policy/path-references.d.mts +14 -0
- package/dist/command-policy/path-references.mjs +68 -0
- package/dist/command-policy/path-rules.d.mts +11 -0
- package/dist/command-policy/path-rules.mjs +37 -0
- package/dist/command-policy/payload.d.mts +8 -0
- package/dist/command-policy/payload.mjs +54 -0
- package/dist/command-policy/types.d.mts +77 -0
- package/dist/command-policy/types.mjs +1 -0
- package/dist/dead-code/baseline.d.mts +19 -0
- package/dist/dead-code/baseline.mjs +124 -0
- package/dist/dead-code/child-command.d.mts +6 -0
- package/dist/dead-code/child-command.mjs +107 -0
- package/dist/dead-code/cli.d.mts +5 -0
- package/dist/dead-code/cli.mjs +71 -0
- package/dist/dead-code/entry-roots.d.mts +7 -0
- package/dist/dead-code/entry-roots.mjs +43 -0
- package/dist/dead-code/fixture-deadline.test-helpers.d.mts +1 -0
- package/dist/dead-code/fixture-deadline.test-helpers.mjs +9 -0
- package/dist/dead-code/gate.d.mts +29 -0
- package/dist/dead-code/gate.mjs +33 -0
- package/dist/dead-code/gate.test-helpers.d.mts +14 -0
- package/dist/dead-code/gate.test-helpers.mjs +35 -0
- package/dist/dead-code/index.d.mts +9 -0
- package/dist/dead-code/index.mjs +7 -0
- package/dist/dead-code/scan.d.mts +11 -0
- package/dist/dead-code/scan.mjs +37 -0
- package/dist/dead-code/tracked-snapshot.d.mts +2 -0
- package/dist/dead-code/tracked-snapshot.mjs +72 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/markdown/details-scope.d.mts +1 -1
- package/dist/markdown/details-scope.mjs +1 -1
- package/dist/tmux/cli-shared.d.mts +18 -0
- package/dist/tmux/cli-shared.mjs +8 -0
- package/dist/tmux/cli.d.mts +3 -0
- package/dist/tmux/cli.mjs +34 -0
- package/dist/tmux/config.d.mts +24 -0
- package/dist/tmux/config.mjs +91 -0
- package/dist/tmux/fake-tmux.test-helpers.d.mts +46 -0
- package/dist/tmux/fake-tmux.test-helpers.mjs +105 -0
- package/dist/tmux/hook-payload.d.mts +8 -0
- package/dist/tmux/hook-payload.mjs +39 -0
- package/dist/tmux/index.d.mts +9 -0
- package/dist/tmux/index.mjs +7 -0
- package/dist/tmux/launcher.d.mts +11 -0
- package/dist/tmux/launcher.mjs +127 -0
- package/dist/tmux/reminder-post-tool.d.mts +21 -0
- package/dist/tmux/reminder-post-tool.mjs +88 -0
- package/dist/tmux/runner.d.mts +11 -0
- package/dist/tmux/runner.mjs +26 -0
- package/dist/tmux/session-name.d.mts +5 -0
- package/dist/tmux/session-name.mjs +10 -0
- package/dist/tmux/shell-quote.d.mts +9 -0
- package/dist/tmux/shell-quote.mjs +16 -0
- package/dist/tmux/up.d.mts +2 -0
- package/dist/tmux/up.mjs +73 -0
- package/dist/tmux/windows.d.mts +18 -0
- package/dist/tmux/windows.mjs +50 -0
- package/dist/transient-retry/attempts.d.mts +1 -1
- package/dist/transient-retry/attempts.mjs +1 -1
- package/dist/transient-retry/decision-evaluator.d.mts +3 -3
- package/dist/transient-retry/gh-api.d.mts +30 -0
- package/dist/transient-retry/gh-api.mjs +68 -0
- package/dist/transient-retry/github-actions-log.d.mts +7 -0
- package/dist/transient-retry/github-actions-log.mjs +33 -0
- package/dist/transient-retry/index.d.mts +15 -0
- package/dist/transient-retry/index.mjs +8 -0
- package/dist/transient-retry/log-stream.d.mts +12 -0
- package/dist/transient-retry/log-stream.mjs +39 -0
- package/dist/transient-retry/log-window.d.mts +18 -0
- package/dist/transient-retry/log-window.mjs +94 -0
- package/dist/transient-retry/rerun.d.mts +23 -0
- package/dist/transient-retry/rerun.mjs +68 -0
- package/dist/transient-retry/run-context-annotations.d.mts +7 -0
- package/dist/transient-retry/run-context-annotations.mjs +44 -0
- package/dist/transient-retry/run-context-jobs.d.mts +20 -0
- package/dist/transient-retry/run-context-jobs.mjs +54 -0
- package/dist/transient-retry/run-context-logs.d.mts +12 -0
- package/dist/transient-retry/run-context-logs.mjs +86 -0
- package/dist/transient-retry/run-context-rule-attempts.d.mts +14 -0
- package/dist/transient-retry/run-context-rule-attempts.mjs +65 -0
- package/dist/transient-retry/run-context-types.d.mts +49 -0
- package/dist/transient-retry/run-context-types.mjs +3 -0
- package/dist/transient-retry/run-context.d.mts +9 -0
- package/dist/transient-retry/run-context.mjs +25 -0
- package/dist/transient-retry/run-context.test-helpers.d.mts +16 -0
- package/dist/transient-retry/run-context.test-helpers.mjs +56 -0
- package/dist/transient-retry/types.d.mts +8 -7
- package/dist/vitest-diagnostics/vitest-worker-exit-diagnostics-reporter.mjs +1 -1
- package/dist/workflow-secrets-drift/gh.d.mts +1 -1
- package/dist/workflow-secrets-drift/gh.mjs +1 -1
- package/package.json +16 -1
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
- package/scripts/tmux/tmux-agent-reminder.sh +68 -0
- package/scripts/tmux/tmux-name.sh +34 -0
- package/scripts/tmux/tmux-read-title.sh +13 -0
- package/scripts/tmux/tmux-target.sh +130 -0
|
@@ -10,7 +10,7 @@ export interface RetryContext {
|
|
|
10
10
|
targetNames?: ReadonlySet<string>;
|
|
11
11
|
}
|
|
12
12
|
export type RetryDecision = 'rerun' | 'ignore' | 'fresh-plan' | 'reap-lock' | 'dispatch';
|
|
13
|
-
export type RetryTarget = {
|
|
13
|
+
export type RetryTarget<C extends RetryContext = RetryContext> = {
|
|
14
14
|
targetName: string;
|
|
15
15
|
targetFamily?: never;
|
|
16
16
|
resolveTargetName?: never;
|
|
@@ -19,20 +19,21 @@ export type RetryTarget = {
|
|
|
19
19
|
/** Static prefix shared by every dynamically named target in the family. */
|
|
20
20
|
targetFamily: string;
|
|
21
21
|
/** Resolves the exact target for this run, or null when it cannot be determined. */
|
|
22
|
-
resolveTargetName: (context:
|
|
22
|
+
resolveTargetName: (context: C) => string | null;
|
|
23
23
|
};
|
|
24
|
-
interface RetryRuleBase {
|
|
24
|
+
interface RetryRuleBase<C extends RetryContext> {
|
|
25
25
|
/** Stable identifier for logs and telemetry. */
|
|
26
26
|
id: string;
|
|
27
27
|
/** Maximum normalized attempts at which this rule may match. */
|
|
28
28
|
maxAttempts: number;
|
|
29
|
-
match: (context:
|
|
29
|
+
match: (context: C) => boolean | Promise<boolean>;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
/** `C` lets a provider narrow the context its rules read, e.g. to add logs. */
|
|
32
|
+
export type RetryRule<C extends RetryContext = RetryContext> = (RetryRuleBase<C> & {
|
|
32
33
|
decision?: 'rerun';
|
|
33
34
|
/** When omitted, the match is an untargeted provider-level rerun. */
|
|
34
|
-
retryTarget?: RetryTarget
|
|
35
|
-
}) | (RetryRuleBase & {
|
|
35
|
+
retryTarget?: RetryTarget<C>;
|
|
36
|
+
}) | (RetryRuleBase<C> & {
|
|
36
37
|
decision: Exclude<RetryDecision, 'rerun'>;
|
|
37
38
|
retryTarget?: never;
|
|
38
39
|
});
|
|
@@ -13,10 +13,10 @@ const workerExitSignals = [
|
|
|
13
13
|
'Worker exited unexpectedly',
|
|
14
14
|
];
|
|
15
15
|
class VitestWorkerExitDiagnosticsReporter {
|
|
16
|
-
recordDirectory;
|
|
17
16
|
emitted = false;
|
|
18
17
|
recentModuleEvents = [];
|
|
19
18
|
recentStderrLines = [];
|
|
19
|
+
recordDirectory;
|
|
20
20
|
constructor(recordDirectory) {
|
|
21
21
|
this.recordDirectory = recordDirectory;
|
|
22
22
|
// Clear once before forks start. Clearing on watch reruns would unlink the files still held
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type RunTextCommand } from '../gh-cli/
|
|
1
|
+
import { type RunTextCommand } from '../gh-cli/index.mts';
|
|
2
2
|
import type { WorkflowSecretsDependencies } from './types.mts';
|
|
3
3
|
/** Builds the live reads on top of an injectable `gh` runner (argv in, stdout out). */
|
|
4
4
|
export declare function createGhDependencies(run?: RunTextCommand): WorkflowSecretsDependencies;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runGh } from "../gh-cli/
|
|
1
|
+
import { runGh } from "../gh-cli/index.mjs";
|
|
2
2
|
import { outputNames, parseDeploymentBranchPolicy, parseDeploymentBranchRules, parseSecretNames, } from "./gh-parse.mjs";
|
|
3
3
|
/** Builds the live reads on top of an injectable `gh` runner (argv in, stdout out). */
|
|
4
4
|
export function createGhDependencies(run = runGh) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vouchington-tooling",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.60.0",
|
|
4
4
|
"description": "Vouchington CLI and extractable tooling libraries.",
|
|
5
5
|
"homepage": "https://github.com/vouchington/vouchington-tooling/tree/main/packages/vouchington-tooling#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -60,6 +60,11 @@
|
|
|
60
60
|
"import": "./dist/host-storage/index.mjs",
|
|
61
61
|
"default": "./dist/host-storage/index.mjs"
|
|
62
62
|
},
|
|
63
|
+
"./command-policy": {
|
|
64
|
+
"types": "./dist/command-policy/index.d.mts",
|
|
65
|
+
"import": "./dist/command-policy/index.mjs",
|
|
66
|
+
"default": "./dist/command-policy/index.mjs"
|
|
67
|
+
},
|
|
63
68
|
"./shell-parse": {
|
|
64
69
|
"types": "./dist/shell-parse/index.d.mts",
|
|
65
70
|
"import": "./dist/shell-parse/index.mjs",
|
|
@@ -306,6 +311,16 @@
|
|
|
306
311
|
"import": "./dist/dependency-license-policy/index.mjs",
|
|
307
312
|
"default": "./dist/dependency-license-policy/index.mjs"
|
|
308
313
|
},
|
|
314
|
+
"./dead-code": {
|
|
315
|
+
"types": "./dist/dead-code/index.d.mts",
|
|
316
|
+
"import": "./dist/dead-code/index.mjs",
|
|
317
|
+
"default": "./dist/dead-code/index.mjs"
|
|
318
|
+
},
|
|
319
|
+
"./tmux": {
|
|
320
|
+
"types": "./dist/tmux/index.d.mts",
|
|
321
|
+
"import": "./dist/tmux/index.mjs",
|
|
322
|
+
"default": "./dist/tmux/index.mjs"
|
|
323
|
+
},
|
|
309
324
|
"./workflow-secrets-drift": {
|
|
310
325
|
"types": "./dist/workflow-secrets-drift/index.d.mts",
|
|
311
326
|
"import": "./dist/workflow-secrets-drift/index.mjs",
|
|
Binary file
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
# Remind the agent to rename the tmux window at workflow checkpoints.
|
|
5
|
+
# Called by agent hooks; stdout is injected as context.
|
|
6
|
+
#
|
|
7
|
+
# Usage: vouchington tmux agent-reminder <event>
|
|
8
|
+
# event: session-start | user-prompt
|
|
9
|
+
# TMUX_TARGET_BIN: optional tmux binary (default: tmux on PATH).
|
|
10
|
+
# TMUX_TARGET_ROOT: worktree the pane must belong to (default: $PWD).
|
|
11
|
+
# TMUX_NAME_COMMAND: command the reminder tells the agent to run
|
|
12
|
+
# (default: vouchington tmux name).
|
|
13
|
+
#
|
|
14
|
+
# Silently exits 0 when no tmux context is available.
|
|
15
|
+
|
|
16
|
+
EVENT="${1:-}"
|
|
17
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
18
|
+
# shellcheck source=tmux-target.sh
|
|
19
|
+
source "$SCRIPT_DIR/tmux-target.sh"
|
|
20
|
+
tmux_target_socket=''
|
|
21
|
+
tmux_target_pane=''
|
|
22
|
+
TMUX_TARGET_BIN="${TMUX_TARGET_BIN:-tmux}"
|
|
23
|
+
NAME_COMMAND="${TMUX_NAME_COMMAND:-vouchington tmux name}"
|
|
24
|
+
|
|
25
|
+
if tmux_target_resolve "${TMUX_TARGET_ROOT:-$PWD}" "${AGENT_TMUX_SOCKET:-}" "${AGENT_TMUX_PANE:-}" "${AGENT_TMUX_WORKTREE:-}"; then
|
|
26
|
+
:
|
|
27
|
+
else
|
|
28
|
+
# Hook reminders are advisory. The resolver diagnoses invalid bindings and
|
|
29
|
+
# the hook leaves the agent's work alone.
|
|
30
|
+
exit 0
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
# Drain the hook payload so the caller never blocks on an unread pipe.
|
|
34
|
+
cat >/dev/null
|
|
35
|
+
|
|
36
|
+
pane_title() {
|
|
37
|
+
"$TMUX_TARGET_BIN" -S "$tmux_target_socket" display-message -p -t "$tmux_target_pane" '#{pane_title}' 2>/dev/null || true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
POLICY="Run: $NAME_COMMAND <name> (must run unsandboxed: Claude/Codex dangerouslyDisableSandbox; Cursor disable sandbox)
|
|
41
|
+
Checkpoints: (1) topic clear → short-hyphenated-name; (2) plan accepted → refine if scope shifted; (3) PR created → append -pr<N> suffix; (4) git push on PR branch → confirm -pr<N> still set; (5) after compaction → verify name still matches topic; (6) reset-worktree → confirm pane title is empty."
|
|
42
|
+
|
|
43
|
+
json_escape() {
|
|
44
|
+
local value=$1
|
|
45
|
+
value=${value//\\/\\\\}
|
|
46
|
+
value=${value//\"/\\\"}
|
|
47
|
+
value=${value//$'\n'/\\n}
|
|
48
|
+
value=${value//$'\t'/\\t}
|
|
49
|
+
printf '%s' "$value"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Emit structured hook context for events that require JSON stdout.
|
|
53
|
+
emit_json() {
|
|
54
|
+
printf '{"hookSpecificOutput":{"hookEventName":"%s","additionalContext":"%s"}}\n' \
|
|
55
|
+
"$(json_escape "$1")" "$(json_escape "$2")"
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
case "$EVENT" in
|
|
59
|
+
session-start)
|
|
60
|
+
emit_json "SessionStart" "[tmux-window-name] $POLICY"
|
|
61
|
+
;;
|
|
62
|
+
user-prompt)
|
|
63
|
+
TITLE="$(pane_title)"
|
|
64
|
+
if [ -z "$TITLE" ] || printf '%s' "$TITLE" | grep -qE '^(claude|codex|grok|cursor|agent|zsh|bash|fish|reset|sh)$'; then
|
|
65
|
+
printf '[tmux-window-name] Topic is clear — set the window name now. %s\n' "$POLICY"
|
|
66
|
+
fi
|
|
67
|
+
;;
|
|
68
|
+
esac
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
# Name the tmux window and pane that belong to the caller's worktree.
|
|
5
|
+
# The worktree defaults to the git root of $PWD; override with TMUX_TARGET_ROOT.
|
|
6
|
+
# The tmux binary defaults to `tmux`; override with TMUX_TARGET_BIN.
|
|
7
|
+
|
|
8
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
9
|
+
if [ "$#" -eq 1 ] && { [ "$1" = "-h" ] || [ "$1" = "--help" ]; }; then
|
|
10
|
+
echo 'Usage: vouchington tmux name [--socket PATH --pane %ID --worktree PATH] NAME'
|
|
11
|
+
exit 0
|
|
12
|
+
fi
|
|
13
|
+
# shellcheck source=tmux-target.sh
|
|
14
|
+
source "$SCRIPT_DIR/tmux-target.sh"
|
|
15
|
+
tmux_target_socket=''
|
|
16
|
+
tmux_target_pane=''
|
|
17
|
+
TMUX_TARGET_BIN="${TMUX_TARGET_BIN:-tmux}"
|
|
18
|
+
|
|
19
|
+
if tmux_target_parse "${TMUX_TARGET_ROOT:-$PWD}" "$@"; then
|
|
20
|
+
:
|
|
21
|
+
else
|
|
22
|
+
resolve_status=$?
|
|
23
|
+
# An interactive command outside tmux has no target. Invalid, partial, stale,
|
|
24
|
+
# and mismatched bindings retain the resolver's diagnostic.
|
|
25
|
+
if [ "$resolve_status" -eq 3 ]; then exit 0; fi
|
|
26
|
+
exit "$resolve_status"
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
if [ -z "$tmux_target_name" ]; then
|
|
30
|
+
"$TMUX_TARGET_BIN" -S "$tmux_target_socket" set-window-option -t "$tmux_target_pane" automatic-rename on
|
|
31
|
+
else
|
|
32
|
+
"$TMUX_TARGET_BIN" -S "$tmux_target_socket" rename-window -t "$tmux_target_pane" -- "$tmux_target_name"
|
|
33
|
+
fi
|
|
34
|
+
"$TMUX_TARGET_BIN" -S "$tmux_target_socket" select-pane -t "$tmux_target_pane" -T "$tmux_target_name"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
5
|
+
# shellcheck source=tmux-target.sh
|
|
6
|
+
source "$SCRIPT_DIR/tmux-target.sh"
|
|
7
|
+
tmux_target_socket=''
|
|
8
|
+
tmux_target_pane=''
|
|
9
|
+
TMUX_TARGET_BIN="${TMUX_TARGET_BIN:-tmux}"
|
|
10
|
+
|
|
11
|
+
# A title read uses the same pane/worktree check as tmux-name.
|
|
12
|
+
tmux_target_resolve "${TMUX_TARGET_ROOT:-$PWD}" "${AGENT_TMUX_SOCKET:-}" "${AGENT_TMUX_PANE:-}" "${AGENT_TMUX_WORKTREE:-}"
|
|
13
|
+
"$TMUX_TARGET_BIN" -S "$tmux_target_socket" display-message -p -t "$tmux_target_pane" '#{pane_title}'
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Shared by the name helper and launchers. Sourcing this file never changes tmux.
|
|
3
|
+
|
|
4
|
+
tmux_target_error() {
|
|
5
|
+
printf 'tmux target: %s\nPass --socket PATH --pane %%ID --worktree PATH from the task worktree.\n' "$1" >&2
|
|
6
|
+
return 1
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
tmux_target_root() {
|
|
10
|
+
local directory git_root
|
|
11
|
+
directory=$(cd -- "$1" && pwd -P) || return 1
|
|
12
|
+
# Git's inherited repository selectors and runtime config can make -C
|
|
13
|
+
# report a different checkout. Keep normal global/system config (including
|
|
14
|
+
# safe.directory) while dropping exported Git overrides.
|
|
15
|
+
if command -v git >/dev/null 2>&1 && git_root=$(
|
|
16
|
+
env -i PATH="${PATH:-/usr/bin:/bin}" HOME="${HOME:-}" XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-}" \
|
|
17
|
+
git -C "$directory" rev-parse --show-toplevel 2>/dev/null
|
|
18
|
+
); then
|
|
19
|
+
(cd -- "$git_root" && pwd -P)
|
|
20
|
+
else
|
|
21
|
+
printf '%s\n' "$directory"
|
|
22
|
+
fi
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# Return 3 only when there is no tmux context at all, preserving outside-tmux no-op.
|
|
26
|
+
# A partial or untrusted tmux context returns 1 and must never fall back to cwd.
|
|
27
|
+
tmux_target_resolve() {
|
|
28
|
+
local expected_root binding_root pane_path pane_root terminal panes candidate candidate_terminal matches socket_prefix
|
|
29
|
+
local tmux_command=${TMUX_TARGET_BIN:-tmux}
|
|
30
|
+
tmux_target_socket=$2
|
|
31
|
+
tmux_target_pane=$3
|
|
32
|
+
tmux_target_worktree=$4
|
|
33
|
+
expected_root=$(tmux_target_root "$1") || return 1
|
|
34
|
+
if [ -z "$tmux_target_socket$tmux_target_pane$tmux_target_worktree${TMUX:-}${TMUX_PANE:-}" ]; then return 3; fi
|
|
35
|
+
if ! command -v "$tmux_command" >/dev/null 2>&1; then
|
|
36
|
+
tmux_target_error 'tmux is missing; install with brew install tmux or apt-get install tmux'; return 1
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
if [ -n "$tmux_target_socket$tmux_target_pane$tmux_target_worktree" ]; then
|
|
40
|
+
if [ -z "$tmux_target_socket" ] || [ -z "$tmux_target_pane" ] || [ -z "$tmux_target_worktree" ]; then
|
|
41
|
+
tmux_target_error 'incomplete explicit binding'; return 1
|
|
42
|
+
fi
|
|
43
|
+
binding_root=$(tmux_target_root "$tmux_target_worktree") || return 1
|
|
44
|
+
if [ "$binding_root" != "$expected_root" ]; then
|
|
45
|
+
tmux_target_error 'binding belongs to a different worktree'; return 1
|
|
46
|
+
fi
|
|
47
|
+
else
|
|
48
|
+
if [ -z "${TMUX:-}${TMUX_PANE:-}" ]; then return 3; fi
|
|
49
|
+
# tty </dev/tty reports the alias /dev/tty on macOS. Query this shell's
|
|
50
|
+
# controlling terminal instead, including when an agent pipes its stdin.
|
|
51
|
+
terminal=$(ps -p "$$" -o tty= 2>/dev/null | tr -d '[:space:]')
|
|
52
|
+
case $terminal in
|
|
53
|
+
''|*'?'*|'-') tmux_target_error 'no verified controlling terminal or explicit binding'; return 1 ;;
|
|
54
|
+
/dev/*) ;;
|
|
55
|
+
*) terminal=/dev/$terminal ;;
|
|
56
|
+
esac
|
|
57
|
+
case ${TMUX:-} in
|
|
58
|
+
*,*,*) socket_prefix=${TMUX%,*}; tmux_target_socket=${socket_prefix%,*} ;;
|
|
59
|
+
*) tmux_target_error 'missing tmux socket identity'; return 1 ;;
|
|
60
|
+
esac
|
|
61
|
+
panes=$("$tmux_command" -S "$tmux_target_socket" list-panes -a -F $'#{pane_id}\t#{pane_tty}') || {
|
|
62
|
+
tmux_target_error 'unable to list panes on the specified socket'; return 1
|
|
63
|
+
}
|
|
64
|
+
matches=0
|
|
65
|
+
while IFS=$'\t' read -r candidate candidate_terminal; do
|
|
66
|
+
if [ "$candidate_terminal" = "$terminal" ]; then
|
|
67
|
+
tmux_target_pane=$candidate
|
|
68
|
+
matches=$((matches + 1))
|
|
69
|
+
fi
|
|
70
|
+
done <<EOF
|
|
71
|
+
$panes
|
|
72
|
+
EOF
|
|
73
|
+
if [ "$matches" -ne 1 ]; then
|
|
74
|
+
tmux_target_error 'controlling terminal does not identify exactly one pane'; return 1
|
|
75
|
+
fi
|
|
76
|
+
tmux_target_worktree=$expected_root
|
|
77
|
+
fi
|
|
78
|
+
|
|
79
|
+
case $tmux_target_socket in
|
|
80
|
+
/*) ;;
|
|
81
|
+
*) tmux_target_error 'socket must be an absolute path'; return 1 ;;
|
|
82
|
+
esac
|
|
83
|
+
if ! [[ $tmux_target_pane =~ ^%[0-9]+$ ]]; then
|
|
84
|
+
tmux_target_error 'pane must be a literal %ID'; return 1
|
|
85
|
+
fi
|
|
86
|
+
pane_path=$("$tmux_command" -S "$tmux_target_socket" display-message -p -t "$tmux_target_pane" '#{pane_current_path}') || {
|
|
87
|
+
tmux_target_error 'pane is missing or unavailable on the specified socket'; return 1
|
|
88
|
+
}
|
|
89
|
+
if [ -z "$pane_path" ]; then tmux_target_error 'pane has no working directory'; return 1; fi
|
|
90
|
+
pane_root=$(tmux_target_root "$pane_path") || return 1
|
|
91
|
+
if [ "$pane_root" != "$expected_root" ]; then
|
|
92
|
+
tmux_target_error 'pane belongs to a different worktree'; return 1
|
|
93
|
+
fi
|
|
94
|
+
tmux_target_worktree=$expected_root
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# The resolved name is a public output consumed by callers sourcing this library.
|
|
98
|
+
# shellcheck disable=SC2034
|
|
99
|
+
tmux_target_parse() {
|
|
100
|
+
local expected=$1 socket='' pane='' worktree='' has_socket=false has_pane=false has_worktree=false has_name=false
|
|
101
|
+
shift
|
|
102
|
+
tmux_target_name=''
|
|
103
|
+
while [ "$#" -gt 0 ]; do
|
|
104
|
+
case $1 in
|
|
105
|
+
--socket|--pane|--worktree)
|
|
106
|
+
if [ "$#" -lt 2 ] || [ -z "$2" ]; then tmux_target_error "missing value for $1"; return 2; fi
|
|
107
|
+
case $1 in
|
|
108
|
+
--socket) if $has_socket; then tmux_target_error 'duplicate --socket'; return 2; fi; socket=$2; has_socket=true ;;
|
|
109
|
+
--pane) if $has_pane; then tmux_target_error 'duplicate --pane'; return 2; fi; pane=$2; has_pane=true ;;
|
|
110
|
+
--worktree) if $has_worktree; then tmux_target_error 'duplicate --worktree'; return 2; fi; worktree=$2; has_worktree=true ;;
|
|
111
|
+
esac
|
|
112
|
+
shift 2 ;;
|
|
113
|
+
--)
|
|
114
|
+
shift
|
|
115
|
+
if [ "$#" -ne 1 ] || $has_name; then tmux_target_error 'provide exactly one name'; return 2; fi
|
|
116
|
+
tmux_target_name=$1; has_name=true; shift ;;
|
|
117
|
+
-*) tmux_target_error "unknown option: $1"; return 2 ;;
|
|
118
|
+
*)
|
|
119
|
+
if $has_name; then tmux_target_error 'provide exactly one name'; return 2; fi
|
|
120
|
+
tmux_target_name=$1; has_name=true; shift ;;
|
|
121
|
+
esac
|
|
122
|
+
done
|
|
123
|
+
if ! $has_name; then tmux_target_error 'provide exactly one name'; return 2; fi
|
|
124
|
+
if $has_socket || $has_pane || $has_worktree; then
|
|
125
|
+
if ! $has_socket || ! $has_pane || ! $has_worktree; then tmux_target_error 'supply all three target options'; return 2; fi
|
|
126
|
+
else
|
|
127
|
+
socket=${AGENT_TMUX_SOCKET:-}; pane=${AGENT_TMUX_PANE:-}; worktree=${AGENT_TMUX_WORKTREE:-}
|
|
128
|
+
fi
|
|
129
|
+
tmux_target_resolve "$expected" "$socket" "$pane" "$worktree"
|
|
130
|
+
}
|