matthewwong525/WongStack / .agents/plugins/daily/skills/schedule
schedule
UnverifiedSchedule scripts or future sessions; save, approve and manage app schedules.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 1.2 KB |
| references/native.md | markdown | 445 B |
| references/paseo.md | markdown | 426 B |
| references/registration.md | markdown | 920 B |
| references/run.md | markdown | 477 B |
| scripts/lib/hosts.mjs | script | 5.3 KB |
| scripts/lib/paseo-store.mjs | script | 7.0 KB |
| scripts/lib/records.mjs | script | 10.4 KB |
| scripts/lib/start-run.mjs | script | 6.1 KB |
| scripts/lib/version.mjs | script | 1.1 KB |
| scripts/paseo-presets.json | config | 1.5 KB |
| scripts/presets.mjs | script | 5.4 KB |
| scripts/schedule.mjs | script | 5.4 KB |
| scripts/tidy.mjs | script | 20.5 KB |
| scripts/workspace.mjsexecutable | script | 15.1 KB |
scripts/workspace.mjs
View on GitHub#!/usr/bin/env node
// Opens one new Paseo workspace with its own agent, for one part of a request; the brief file is its first message.
// It branches from the fetched default branch, never the caller's, and has no parent. USAGE below lists the flags.
import { execFile } from 'node:child_process';
import { readFileSync } from 'node:fs';
import { promisify } from 'node:util';
import { isMain } from '../../../scripts/lib/cli.mjs';
import { primaryRoot, PrimaryRootError } from '../../../scripts/lib/primary-root.mjs';
import { slot, slotResult } from '../../../scripts/lib/slot.mjs';
import { EXIT, PaseoError, findPaseo, git, paseo, parseCommand, runPaseo, withJson } from '../../../scripts/lib/paseo.mjs';
const USAGE = `usage: workspace.mjs open --title <part> --brief <file>
[--checkout <branch> [--reviewed <commit>]] [--agent claude|codex] [--label key=value] [--dry-run]`;
const VALUE_FLAGS = ['title', 'brief', 'checkout', 'reviewed', 'agent', 'label'];
// A tag a script puts on the chats it opens, so it can find them again.
const LABEL = /^[a-z][a-z0-9-]{0,39}=[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/;
export const MODES = { claude: 'bypassPermissions', codex: 'full-access' };
const PARENT_VARS = ['PASEO_AGENT_ID', 'PASEO_WORKSPACE_ID'];
// The review fetches the branch, so it gets longer than a part's usual time limit.
const CHECKOUT_MS = 60e3;
export const PLACEHOLDERS = new Set(['main', 'master', 'default', 'hello', 'hello world', 'test', 'testing', 'untitled',
'new workspace', 'workspace', 'scratch', 'temp', 'tmp', 'wip']);
const SLUG = /^(?=.*[A-Za-z0-9])(?=.*[-_])[A-Za-z0-9._-]+$/;
// Thinking below this floor becomes `medium`; `auto` and empty mean unset, so the model's own default applies.
const BELOW_FLOOR = new Set(['none', 'off', 'minimal', 'low']);
const UNSET = new Set(['', 'auto']);
/** The level a chat opened for the person starts at: never below medium, and an unset level the model would run
* at medium or more stays unset, so a model whose default is high keeps it. */
export function floorThinking(level, modelDefault) {
const asked = String(level ?? '').trim().toLowerCase();
if (BELOW_FLOOR.has(asked)) return 'medium';
if (!UNSET.has(asked)) return String(level).trim();
const fallback = String(modelDefault ?? '').trim().toLowerCase();
return !fallback || UNSET.has(fallback) || BELOW_FLOOR.has(fallback) ? 'medium' : null;
}
/** The level the model runs at when none is passed, from `paseo provider models` through `call`; null when unread.
* No model named means Paseo's default, which it lists first. */
export async function modelDefault(call, { provider, model }) {
try {
const models = await call(['provider', 'models', provider]);
const found = Array.isArray(models) ? (model ? models.find(each => each.id === model) : models[0]) : null;
return found?.defaultThinkingOptionId ?? null;
} catch {
return null;
}
}
/** The floored level for these settings; it reads the model's default only when no level is set. */
export async function flooredThinking(call, settings) {
const unset = UNSET.has(String(settings.thinking ?? '').trim().toLowerCase());
return floorThinking(settings.thinking, unset ? await modelDefault(call, settings) : null);
}
/** The workspace's name in plain words: a slug becomes words; a placeholder, which no conversion fixes, is exit 2. */
export function workspaceTitle(raw) {
const trimmed = String(raw ?? '').trim();
if (!trimmed) throw new PaseoError(EXIT.input, 'Pass --title <part>: the new workspace\'s name.');
if (PLACEHOLDERS.has(trimmed.toLowerCase().replace(/[-_\s]+/g, ' ').trim())) {
throw new PaseoError(EXIT.input, `"${trimmed}" says nothing about the work: pass a --title of a few words that name it.`);
}
if (!SLUG.test(trimmed)) return trimmed;
const words = trimmed.split(/[-_]+/).filter(Boolean).join(' ');
return words.charAt(0).toUpperCase() + words.slice(1);
}
/** The new agent's settings: the caller's, from `paseo inspect`, else the --agent defaults. */
export function agentSettings(inspected, agent) {
if (inspected) {
if (!inspected.Provider || !inspected.Mode) {
throw new PaseoError(EXIT.client, "Paseo's inspect output has changed: Provider or Mode is missing.");
}
return {
provider: inspected.Provider,
model: inspected.Model || null,
thinking: inspected.Thinking || null,
mode: inspected.Mode,
};
}
const mode = MODES[agent];
if (!mode) {
throw new PaseoError(EXIT.input, 'Not run from a Paseo agent: pass --agent claude or --agent codex.');
}
return { provider: agent, model: null, thinking: null, mode };
}
/** The `paseo run` arguments, without --json. `--` ends the options, so a brief of any shape is the prompt. */
export function runArgs({ primary, title, brief, settings, base, checkout, label }) {
const args = ['run', '-d', '--new-workspace', 'worktree'];
if (checkout) args.push('--worktree-mode', 'checkout-branch', '--branch', checkout);
else args.push('--worktree-mode', 'branch-off', '--base', base);
args.push('--cwd', primary, '--title', title, '--provider', settings.provider);
if (settings.model) args.push('--model', settings.model);
if (settings.thinking) args.push('--thinking', settings.thinking);
if (label) args.push('--label', label);
args.push('--mode', settings.mode, '--', brief);
return args;
}
/** The `paseo workspace rename` arguments, without the trailing --json. The title is one element. */
export function renameArgs(workspaceId, title) {
return ['workspace', 'rename', workspaceId, title];
}
/** The environment for `paseo run`: this one, minus the variables that make a sub-agent. */
export function childEnv(env) {
const out = { ...env };
for (const name of PARENT_VARS) delete out[name];
return out;
}
/** Reads Paseo's stderr: `Created workspace <id> - <name> (<branch>)`, then an optional setup note. */
export function parseCreated(stderr) {
const lines = String(stderr ?? '').split('\n').map(l => l.trim());
const at = lines.findIndex(l => l.startsWith('Created workspace '));
if (at < 0) return null;
const m = /^Created workspace (\S+) - (.+?)(?: \(([^()]+)\))?$/.exec(lines[at]);
if (!m) return null;
const next = lines[at + 1];
return {
workspaceId: m[1],
workspaceName: m[2],
branch: m[3] ?? null,
setupSkippedReason: next && !next.startsWith('Tip:') ? next : null,
};
}
/** Steps to open the same workspace by hand, for when the script cannot. */
function appSteps({ primary, title, briefFile, settings, base, checkout, commit }) {
return [
'Open it in the Paseo app instead:',
`- New workspace: worktree of ${primary}`,
checkout ? `- Check out branch: ${checkout}${commit ? ` (it starts at ${commit.slice(0, 12)})` : ''}` : `- New branch from: ${base}`,
`- Title: ${title}`,
settings ? `- Agent: ${settings.provider}${settings.model ? `/${settings.model}` : ''}, mode ${settings.mode}` : '- Agent: the same as this chat',
`- First message: the text of ${briefFile}`,
].join('\n');
}
function primaryWorktree(cwd) {
try {
return primaryRoot(cwd).primary;
} catch (error) {
if (error instanceof PrimaryRootError) throw new PaseoError(EXIT.input, error.message);
throw error;
}
}
async function hasRef(cwd, ref) {
try { git(cwd, 'rev-parse', '--verify', '--quiet', ref); return true; } catch { return false; }
}
/** `main`, unless it exists neither locally nor on origin; then the forge's default branch. */
export async function defaultBranch(cwd) {
if (await hasRef(cwd, 'refs/heads/main') || await hasRef(cwd, 'refs/remotes/origin/main')) return 'main';
try {
const { stdout } = await promisify(execFile)('gh',
['repo', 'view', '--json', 'defaultBranchRef', '--jq', '.defaultBranchRef.name'], { cwd, encoding: 'utf8' });
if (stdout.trim()) return stdout.trim();
} catch { /* reported below */ }
throw new PaseoError(EXIT.input, 'No `main` branch here or on origin, and `gh` could not name the default branch.');
}
/** The step that fixes a failed fetch, from the profile's `person().help`, such as a sign-in that ran out. */
async function signInStep(cwd) {
const help = (await slot('person', [cwd]))?.help;
return help ? ` ${help}` : '';
}
/** Fetches the default branch (unless a dry run) and returns the ref to branch from, preferring origin's copy. A
* `timeout` in ms stops a fetch that hangs, so a long-running caller such as the helper never waits on it. */
export async function freshBase(cwd, branch, { fetch, timeout = 0 }) {
let warning = null;
if (fetch) {
try {
await promisify(execFile)('git', ['-C', cwd, 'fetch', '--quiet', 'origin', branch], { encoding: 'utf8', timeout });
} catch (error) {
const why = error.killed ? `no answer in ${timeout / 1000} s` : String(error.stderr || error.message).trim();
warning = `Could not fetch origin/${branch}, so the workspace starts from the last fetched copy: ${why}${await signInStep(cwd)}`;
}
}
if (await hasRef(cwd, `refs/remotes/origin/${branch}`)) return { base: `origin/${branch}`, warning };
return { base: branch, warning };
}
// The profile's `checkout` reviews a --checkout branch: `{commit}` to open at, or `{refused, extra}` (exit 2). With no
// profile or no part, the branch opens as it is; a part that fails refuses, so nothing opens unreviewed.
async function reviewedCheckout(primary, branch, reviewed, { dryRun }) {
const { error, value } = await slotResult('checkout', [branch, primary, { reviewed, dryRun }], { ms: CHECKOUT_MS });
if (error) {
const why = String(error?.message ?? error).split('\n')[0];
throw new PaseoError(EXIT.input, `The review check for "${branch}" failed, so the workspace does not open: ${why}`);
}
if (value?.refused) throw new PaseoError(EXIT.input, value.refused, value.extra ?? {});
return value?.commit ?? null;
}
/** The new worktree's HEAD, checked against the commit it was opened for; a mismatch is exit 5. */
function checkLanded(cwd, commit, opened) {
let head = null;
try { head = cwd ? git(cwd, 'rev-parse', 'HEAD') : null; } catch { /* reported below */ }
if (head === commit) return;
throw new PaseoError(EXIT.client, `The new workspace ${cwd ? `starts at ${head ?? 'an unreadable commit'}` : 'has no folder in Paseo\'s output'}, not the reviewed ${commit}. Close it before anything runs there.`, { opened });
}
/** Names the opened workspace after its part; any refusal keeps Paseo's name, with a warning. */
export async function nameWorkspace(bin, created, title, env) {
if (!created) {
return { name: null, warning: "Paseo did not print the workspace line, so the workspace kept Paseo's name; find it by its agent's title." };
}
try {
const { data } = await runPaseo(bin, renameArgs(created.workspaceId, title), { env: childEnv(env) });
return { name: data?.title || title, warning: null };
} catch (error) {
return { name: created.workspaceName, warning: `The workspace kept Paseo's name, "${created.workspaceName}": ${error.message}` };
}
}
function readBrief(file) {
if (!file) throw new PaseoError(EXIT.input, 'Pass --brief <file>: the new agent\'s first message.');
let text;
try { text = readFileSync(file, 'utf8').trim(); } catch (error) {
throw new PaseoError(EXIT.input, `Cannot read the brief ${file}: ${error.code ?? error.message}.`);
}
if (!text) throw new PaseoError(EXIT.input, `The brief ${file} is empty.`);
return text;
}
export async function openWorkspace(flags, env = process.env, { cwd = process.cwd() } = {}) {
const title = workspaceTitle(flags.title);
if (flags.label && !LABEL.test(flags.label)) throw new PaseoError(EXIT.input, 'Use a safe key=value label.');
const brief = readBrief(flags.brief);
const primary = primaryWorktree(cwd);
const ctx = { primary, title, briefFile: flags.brief, checkout: flags.checkout, commit: null, label: flags.label, settings: null, base: null };
if (flags.reviewed !== undefined && !ctx.checkout) throw new PaseoError(EXIT.input, '--reviewed goes with --checkout <branch>.');
if (ctx.checkout) ctx.commit = await reviewedCheckout(primary, ctx.checkout, flags.reviewed ?? null, { dryRun: flags.dryRun });
try {
const bin = findPaseo(env, 'WORKSPACE_PASEO_BIN');
const caller = env.PASEO_AGENT_ID?.trim();
ctx.settings = agentSettings(caller ? await paseo(bin, ['inspect', caller]) : null, flags.agent);
ctx.settings.thinking = await flooredThinking(args => paseo(bin, args, { env: childEnv(env) }), ctx.settings);
let warning = null;
if (!ctx.checkout) {
({ base: ctx.base, warning } = await freshBase(primary, await defaultBranch(primary), { fetch: !flags.dryRun }));
}
const args = runArgs({ ...ctx, brief });
if (flags.dryRun) {
return {
ok: true, dryRun: true, command: ['paseo', ...withJson(args)], ...(ctx.commit ? { commit: ctx.commit } : {}),
rename: ['paseo', ...renameArgs('<workspaceId>', title), '--json'], removedEnv: PARENT_VARS,
};
}
const { data, stderr } = await runPaseo(bin, args, { env: childEnv(env) });
if (!data?.agentId) {
throw new PaseoError(EXIT.client, `Paseo's run output has changed: no agentId in ${JSON.stringify(data)}.`);
}
const created = parseCreated(stderr);
if (ctx.commit) checkLanded(data.cwd, ctx.commit, { agentId: data.agentId, workspaceId: created?.workspaceId ?? null, cwd: data.cwd ?? null });
const named = await nameWorkspace(bin, created, title, env);
const warnings = [warning, named.warning].filter(Boolean);
return {
ok: true,
agentId: data.agentId,
title: data.title ?? title,
cwd: data.cwd ?? null,
workspaceId: created?.workspaceId ?? null,
workspaceName: named.name,
branch: created?.branch ?? ctx.checkout ?? null,
...(ctx.checkout ? { checkout: ctx.checkout, commit: ctx.commit } : { base: ctx.base }),
provider: ctx.settings.provider,
model: ctx.settings.model,
thinking: ctx.settings.thinking,
mode: ctx.settings.mode,
...(created?.setupSkippedReason ? { setupSkippedReason: created.setupSkippedReason } : {}),
...(warnings.length ? { warning: warnings.join('\n') } : {}),
};
} catch (error) {
if (error instanceof PaseoError && error.code !== EXIT.input && !error.extra.opened) error.extra.fallback = { app: appSteps(ctx) };
throw error;
}
}
async function main(argv = process.argv.slice(2), env = process.env) {
if (argv.length === 0 || argv.includes('--help')) { process.stdout.write(`${USAGE}\n`); return EXIT.ok; }
try {
const { command, flags } = parseCommand(argv, { values: VALUE_FLAGS, booleans: { '--dry-run': 'dryRun' }, unknown: arg => `Unknown argument ${arg}.` });
if (command !== 'open') throw new PaseoError(EXIT.input, `Unknown command "${command}". Use open.`);
process.stdout.write(`${JSON.stringify(await openWorkspace(flags, env), null, 2)}\n`);
return EXIT.ok;
} catch (error) {
const code = error instanceof PaseoError ? error.code : 1;
process.stdout.write(`${JSON.stringify({ ok: false, code, error: error.message, ...error.extra }, null, 2)}\n`);
return code;
}
}
// No top-level await: the profile imports this file through step-title.mjs, and an await would deadlock that import.
if (isMain(import.meta.url)) main().then(code => { process.exitCode = code; });
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |