@ethlete/agent-rules 0.1.0-next.40 → 0.1.0-next.41
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @ethlete/agent-rules
|
|
2
2
|
|
|
3
|
+
## 0.1.0-next.41
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- `agent-sessions restart --process` starts the agent program itself when the stored command is a `run` of the script, `run` inside the pane of its own session starts the agent in place, and `run --dry-run` shows the caller `CLAUDE_CONFIG_DIR`.
|
|
8
|
+
- `agent-sessions` gives the builder flags to a `claude` that follows `env` and env assignments, as in a stored `env CLAUDE_CONFIG_DIR=... claude`.
|
|
9
|
+
|
|
3
10
|
## 0.1.0-next.40
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -127,8 +127,9 @@ const ensuredClaudeTmpDir = () => {
|
|
|
127
127
|
};
|
|
128
128
|
const tempDirEnv = () => `CLAUDE_CODE_TMPDIR=${quote(ensuredClaudeTmpDir())} `;
|
|
129
129
|
const withTempDir = (command) => (/(^|\s)CLAUDE_CODE_TMPDIR=/.test(command) ? command : `${tempDirEnv()}${command}`);
|
|
130
|
+
const programOf = (words) => words.find((word) => word !== 'env' && !ENV_WORD.test(word) && !word.startsWith('-'));
|
|
130
131
|
const withRole = (words) =>
|
|
131
|
-
role === 'builder' && basename(words
|
|
132
|
+
role === 'builder' && basename(programOf(words) ?? '') === 'claude' ? [...words, ...builderFlags()] : words;
|
|
132
133
|
const roleEnvOf = (agentRole) =>
|
|
133
134
|
agentRole
|
|
134
135
|
? { ETHLETE_AGENT_ROLE: agentRole, ...(agentRole === 'builder' ? { CLAUDE_CODE_SILENT_TURN_REMINDER: '0' } : {}) }
|
|
@@ -178,6 +179,10 @@ const createRunSession = (session, shellCommand, baseCommand) => {
|
|
|
178
179
|
process.exitCode = 1;
|
|
179
180
|
}
|
|
180
181
|
};
|
|
182
|
+
const ownSession = () =>
|
|
183
|
+
process.env.TMUX_PANE
|
|
184
|
+
? tmux('display-message', '-p', '-t', process.env.TMUX_PANE, '#{session_name}').stdout.trim() || null
|
|
185
|
+
: null;
|
|
181
186
|
const ONE_SHOT_FLAGS = new Set(['-p', '--print', '-v', '--version', '-h', '--help']);
|
|
182
187
|
const hasTerminal = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
183
188
|
const runsInSession = (agentArgs) => !agentArgs.some((arg) => ONE_SHOT_FLAGS.has(arg));
|
|
@@ -209,6 +214,10 @@ const configMismatch = (words) => {
|
|
|
209
214
|
const given = configDirOf(words);
|
|
210
215
|
return given !== undefined && resolve(given) !== callerConfigDir();
|
|
211
216
|
};
|
|
217
|
+
const callerConfigWords = (words) =>
|
|
218
|
+
process.env.CLAUDE_CONFIG_DIR && configDirOf(words) === undefined
|
|
219
|
+
? [`${CONFIG_WORD}${quote(process.env.CLAUDE_CONFIG_DIR)}`]
|
|
220
|
+
: [];
|
|
212
221
|
const unquoteWord = (word) => word.replace(/'([^']*)'|\\(.)/g, (_, quoted, escaped) => quoted ?? escaped);
|
|
213
222
|
const hasAgentBinary = (words) => {
|
|
214
223
|
let index = 0;
|
|
@@ -221,7 +230,31 @@ const hasAgentBinary = (words) => {
|
|
|
221
230
|
index++;
|
|
222
231
|
return index < words.length;
|
|
223
232
|
};
|
|
233
|
+
const quoteShellWord = (word) =>
|
|
234
|
+
ENV_WORD.test(word) ? word.replace(/^([^=]+=)(.*)$/s, (_, key, value) => `${key}${quote(value)}`) : quote(word);
|
|
235
|
+
const unwrappedRun = (command) => {
|
|
236
|
+
const tokens = [...command.matchAll(SHELL_WORD)].map(([word]) => word);
|
|
237
|
+
const words = tokens.map(unquoteWord);
|
|
238
|
+
const at = words.findIndex((word, index) => basename(word) === 'agent-sessions.mjs' && words[index + 1] === 'run');
|
|
239
|
+
if (at < 0) return null;
|
|
240
|
+
let rest = words.slice(at + 3);
|
|
241
|
+
let runRole = null;
|
|
242
|
+
while (rest[0]?.startsWith('--')) {
|
|
243
|
+
if (rest[0] === '--role') runRole = rest[1];
|
|
244
|
+
rest = rest.slice(rest[0] === '--role' ? 2 : 1);
|
|
245
|
+
}
|
|
246
|
+
const end = rest.findIndex((word) => /[;&|]$/.test(word));
|
|
247
|
+
const inner = end < 0 ? rest : [...rest.slice(0, end), rest[end].replace(/[;&|]+$/, '')];
|
|
248
|
+
const program = inner.findIndex((word) => !ENV_WORD.test(word));
|
|
249
|
+
if (program < 0 || !hasAgentBinary(inner)) return null;
|
|
250
|
+
const kept = [...inner.slice(0, program), ...withoutPrompt(inner.slice(program))];
|
|
251
|
+
const env = tokens.slice(0, at).filter((word) => ENV_WORD.test(word));
|
|
252
|
+
const unwrapped = [...env, ...kept.map(quoteShellWord)].join(' ');
|
|
253
|
+
return runRole ? commandWithRole(unwrapped, runRole) : unwrapped;
|
|
254
|
+
};
|
|
224
255
|
const healedCommand = (command, agent) => {
|
|
256
|
+
const unwrapped = unwrappedRun(command);
|
|
257
|
+
if (unwrapped) return unwrapped;
|
|
225
258
|
const words = [...command.matchAll(SHELL_WORD)].map(([word]) => unquoteWord(word));
|
|
226
259
|
if (hasAgentBinary(words)) return command;
|
|
227
260
|
const binary = agent.match(/^(claude|codex)/)?.[1];
|
|
@@ -348,7 +381,7 @@ const commandWithRole = (command, agentRole) => {
|
|
|
348
381
|
!(word === BUILDER_PROMPT && words[index - 1] === '--append-system-prompt') &&
|
|
349
382
|
!/^(--strict-mcp-config|--mcp-config=.*|--disallowedTools=.*)$/.test(word),
|
|
350
383
|
);
|
|
351
|
-
const rule = agentRole === 'builder' && basename(kept
|
|
384
|
+
const rule = agentRole === 'builder' && basename(programOf(kept) ?? '') === 'claude' ? builderFlags() : [];
|
|
352
385
|
return [
|
|
353
386
|
...env.filter((word) => !/^(ETHLETE_AGENT_ROLE|CLAUDE_CODE_SILENT_TURN_REMINDER)=/.test(word)),
|
|
354
387
|
...roleEnvWords(agentRole),
|
|
@@ -654,8 +687,28 @@ if (command === 'send' && sender) {
|
|
|
654
687
|
);
|
|
655
688
|
process.exitCode = 1;
|
|
656
689
|
} else if (command === 'run' && sender && words.length && dryRun) {
|
|
657
|
-
process.stdout.write(
|
|
658
|
-
|
|
690
|
+
process.stdout.write(
|
|
691
|
+
`${withTempDir([...callerConfigWords(words), ...roleEnvWords(role), ...withRole(words).map(quote)].join(' '))}\n`,
|
|
692
|
+
);
|
|
693
|
+
} else if (
|
|
694
|
+
command === 'run' &&
|
|
695
|
+
sender &&
|
|
696
|
+
words.length &&
|
|
697
|
+
(!runsInSession(words.slice(1)) || (process.env.TMUX && [sessionFor(sender), sender].includes(ownSession())))
|
|
698
|
+
) {
|
|
699
|
+
if (runsInSession(words.slice(1))) {
|
|
700
|
+
const own = `=${ownSession()}:`;
|
|
701
|
+
tmux(
|
|
702
|
+
'set-option',
|
|
703
|
+
'-t',
|
|
704
|
+
own,
|
|
705
|
+
COMMAND_OPTION,
|
|
706
|
+
withTempDir(
|
|
707
|
+
[...callerConfigWords(words), ...roleEnvWords(role), ...withRole(withoutPrompt(words)).map(quote)].join(' '),
|
|
708
|
+
),
|
|
709
|
+
);
|
|
710
|
+
if (role) tmux('set-option', '-t', own, ROLE_OPTION, role);
|
|
711
|
+
}
|
|
659
712
|
const [program, ...programArgs] = withRole(words);
|
|
660
713
|
process.exitCode =
|
|
661
714
|
spawnSync(program, programArgs, {
|
|
@@ -669,14 +722,7 @@ if (command === 'send' && sender) {
|
|
|
669
722
|
} else if (command === 'run' && sender && words.length) {
|
|
670
723
|
ensureDispatch();
|
|
671
724
|
const session = freeSessionFor(sender);
|
|
672
|
-
const roleEnv = [
|
|
673
|
-
...(process.env.CLAUDE_CONFIG_DIR && configDirOf(words) === undefined
|
|
674
|
-
? [`${CONFIG_WORD}${quote(process.env.CLAUDE_CONFIG_DIR)}`]
|
|
675
|
-
: []),
|
|
676
|
-
...roleEnvWords(role),
|
|
677
|
-
]
|
|
678
|
-
.map((word) => `${word} `)
|
|
679
|
-
.join('');
|
|
725
|
+
const roleEnv = [...callerConfigWords(words), ...roleEnvWords(role)].map((word) => `${word} `).join('');
|
|
680
726
|
const shellCommand = withTempDir(`${roleEnv}${withRole(words).map(quote).join(' ')}`);
|
|
681
727
|
const baseCommand = withTempDir(`${roleEnv}${withRole(withoutPrompt(words)).map(quote).join(' ')}`);
|
|
682
728
|
if (process.env.TMUX) {
|
|
@@ -844,7 +890,7 @@ if (command === 'send' && sender) {
|
|
|
844
890
|
}
|
|
845
891
|
if (stored !== recorded) {
|
|
846
892
|
tmux('set-option', '-t', pane, COMMAND_OPTION, stored);
|
|
847
|
-
restartLog(`${session} stored command
|
|
893
|
+
restartLog(`${session} stored command could not restart, healed to: ${stored}`);
|
|
848
894
|
}
|
|
849
895
|
const base = withTempDir(restartRole ? commandWithRole(stored, restartRole) : stored);
|
|
850
896
|
if (restartRole) tmux('set-option', '-t', pane, ROLE_OPTION, restartRole);
|