Startwork

From indigoai-us/hq-core · View interactive version

Startwork is an AI agent skill from the GitHub repository indigoai-us/hq-core. Resolve current HQ context and surface useful next work options.

How to use this skill

Skill file

Start Work Session

Lightweight session entry point. Resolves context fast, presents smart options, gets you working.

Fast path: exact company slug (check first)

One command does the whole company half of this skill:

bash core/scripts/startwork-context.sh orient --company "{co}" --mode Company

It does the Work Mesh trusted bind for this session (company and mode, with the company's hard-policy digest), checks that the bind landed, and prints the <startwork-context> block, including a Board line read from the work mesh cache, plus a Last thread: line that only names a thread of {co}. It needs the caller's own session id: the harness env, or --session-id <id> when the host does not export one. It never binds through workspace/sessions/.current. Exit 3 means {co} is not an exact manifest slug, and nothing was bound. Exit 4 means the bind did not land; stop and report it.

A. A <startwork-prefetch company="{co}"> block is already in the prompt context and {co} is the first word of the argument. The prompt hook already ran orient for {co}. It fires only for an exact slug, and only when the remaining args are not a slash command, a bare skill name, a bounded action (§1.0b), or a second company, and never when the session is already bound to a different company (that switch goes through the normal process). Do not run orient again.

B. No prefetch block, the first word looks like a company slug, and §1.0/§1.0b do not apply. Run orient with that word as your first tool call, before §0.5. On exit 3, continue with the normal process below.

After A or B, the trusted bind, §0.5, §1 resolution, §1.2, §2.4, Company Mode steps 1–3 and the handoff read are done. Do not run resolve-company.sh, startwork-context.sh resolve or block, hq-session.sh set company_slug or set mode, or work-mesh-live-bind-trusted.sh, and do not read handoff.json or the Board cache files. Then:

  1. No remaining args → go straight to §3 Present Options in Company mode. Show the block verbatim, its Board line included. Only run Company Mode step 4 when the block's Integrations line reads "not cached". Take the Worker route from the block's Workers line and skip the §2.5 policy counts; the digest already surfaced the company's hard rules.
  2. Remaining args → treat them as the focus inside {co}: a {co} project name continues in Project Mode from step 3, anything else is Task Mode starting at step 2. If they resolve to a project or repo owned by a different company, stop and ask which company the user means.
  3. If the host saved the prompt-hook output to a file and showed only a preview (the policy trigger hook adds the bound company's policies to the same output), read that file once with one tool call. It holds the full block; do not re-run the scripts.

Without an exact slug, run the normal process below.

When to Use

Beginning of every session. Replaces ad-hoc orientation.

Work Mesh Live — trusted bind (do this first)

Before any other tool call that touches project work, bind the session per

.claude/skills/_shared/work-mesh-live-bind.md (US-011):

hq core work-mesh-bind-trusted \
  --company "{co}" --project "{project}" --task "{task}"

Omit --task when unknown. This writes workspace/sessions/<sid>/meta.yaml

and reconciles with observation.trustedContext (no --trusted CLI flag).

When a company is resolved, startwork-context.sh orient (fast path and

§1.2) runs this same bind for you. Do not run both.

Process

0.5 Default-company fallback

When the argument does not itself select a company, resolve context before entering an unbound path:

hq core resolve-company --prompt "{the user's full input}"

Use its company when source is prompt, session, or device_default; an existing session company always wins over the device default. none (including disabled or needsChoice default state) must open the structured company/personal picker, never silently proceed unbound.

1. Resolve Argument

1.0 Slash-command short-circuit (HARD RULE — check FIRST):

If the argument contains a slash-command token (whitespace-delimited substring matching /<name> for any <name> that is a valid slash command in .claude/commands/), abort the normal classification flow and route to that command. Specifically:

This rule supersedes the classification table below. The reason it exists: prior failure where /startwork {company} vyg /deep-plan apps/... was treated as free-text task description, causing the agent to enter Claude Code's built-in plan mode and start implementing instead of running the deep-plan questionnaire. Policy: core/policies/deep-plan-skill-routing.md.

1.0b Bounded-action short-circuit (HARD RULE — check SECOND, after the slash-command rule, before mode resolution):

If the argument names a bounded action owned by a dedicated skill in the table below, abort the normal classification flow, route to that skill with the raw remaining args, and STOP. Do NOT enter Company Mode. Do NOT read companies/manifest.yaml, do NOT run the qmd/grep project scan, do NOT run git, do NOT build the Worker Packet, and do NOT perform §2.4 session metadata, §2.5 policies, §2.6 worker routing, or any background maintenance. The target skill performs its own tenancy-safe company resolution.

Bounded-action routing table (closed list — route only on these):

| Argument names… | Route to |

|---|---|

| open / read / check / send a DM, "DM {person}", inbox, message thread | /dm |

| meeting notes, transcript, recap, "what was discussed" | /meeting-notes |

| signals, decisions, risks, commitments, wins | /signals |

| action items (read-only "what are my action items") | /signals (company skills may own the mutable tracker) |

| find / search / "where is X" | /search |

| goals, OKRs, key results | /goals |

| "who am I", session identity, login state | /hq-whoami |

This rule exists because a bounded read-only request ("open Izzy's latest project DM") was observed expanding into full company orientation, duplicate policy ingestion, a background maintenance agent, and an unrequested session handoff. Runtimes that follow skill text literally (Codex) must find the fast path in the text itself.

1.1 Mode resolution (only if no short-circuit fired):

Determine mode from the user's argument (first match wins):

1.2 Bind a resolved company before gathering mode context

As soon as normal mode resolution or the default-company fallback identifies a

company, bind it on this session before running project scans, qmd, worker

selection, or any repository command. Use the one orient call from the fast

path, with the resolved mode (and the project in Project mode). It is the only

bind call: it does the trusted bind, records the mode, and prints the

capability block with the Board line and the last-thread line.

bash core/scripts/startwork-context.sh orient --company "{co}" --mode "{Company|Project|Repo|Task|Resume}" [--project "{name}"]

Session metadata writes require the caller’s harness session identity. If the host does not supply it, pass the exact --session-id shown by the scope hook; never select a write target from workspace/sessions/.current or the most recent session.

Skip this step when the fast path already ran orient for {co}.

For Project or Repo mode, first resolve the project's owning company or the

repo's company mapping when it is not already known, then run this bind before

any Git command or project scan. A bounded-action short-circuit does not enter

this flow, and an unresolved or personal-only context has no company to bind.

When a task id becomes available later, §2.4 adds it to the session.

2. Gather Context

Entry-Gate Mode (no arg)

Do NOT eager-load context. A naked /startwork must ask the user where to go before reading the thread file, running the qmd/grep project scan, or reading any prd.json. Only the cheap reads in step 1 are permitted before the gate.

  1. Prefetch cross-device state (fail-soft). Before reading handoff.json, pull the session continuity pointer from the personal vault so a /handoff run on another machine is visible on this one. The workspace tree is otherwise machine-local; only workspace/threads/handoff.json plus the referenced thread file are carved into the personal vault (hq-cloud-sync computeContinuityPointerPaths). Without this pull a fresh session on a second device sees stale state.

```bash

bash core/scripts/handoff-sync-prefetch.sh

```

The helper is fail-soft: missing-CLI, offline, logged-out, or lock-held hosts return within the timeout and leave the local pointer untouched. Treat its output as advisory — never block the entry gate on its exit status.

Cheap peek. If workspace/threads/handoff.json now exists, read it (small, allowed by context-diet) and extract only the last-session one-liner (its summary / conversation_summary field) + referenced branch. Do NOT read the thread file it points to yet. If handoff.json is absent, skip — no last-session option.

Also glob workspace/gates/pending/*.json (cheap, no file reads yet). If any exist, a paused workflow is waiting on human answers — note the count for the gate below. Spec: core/knowledge/public/hq-core/workflow-gates-spec.md.

  1. Ask the user (AskUserQuestion), one question, then wait. Present these options:

Do not present numbered markdown for this gate — use the structured picker. This is the whole point of the gate: no qmd search "prd.json", no thread-file read, no per-project prd.json reads happen until the user has chosen.

  1. After the pick, load only what that path needs:

Once the chosen path has enough context to name the work, name or rename this

session with set_session_title according to

core/policies/hq-session-title-grammar.md. When resuming, carry forward the

useful work subject from the predecessor summary; otherwise use the resolved

target. Add company, product, or mode when it adds information. Rename again

only when the subject changes, and preserve a title the user manually renamed.

If the first-turn title hook already named this session for the same subject,

keep that title and make no title call.

Company Mode (arg = company slug)
  1. The orient call (fast path or §1.2) already printed the capability block: no network, about 3 KB. It carries the company's repos, knowledge and source folders, the cached list of usable integrations with the flag for each, the five most recently touched projects with local open-story counts, the Board line, the company's workers, and the path of the skill intent index. Do not grep the manifest, run the qmd/grep project scan, read core/workers/registry.yaml, or run git over the first manifest repo by hand; the block replaces those reads (HP-12 traced every one of them as a lookup startwork should have answered).
  2. The Last thread: line from orient is the handoff check, already filtered to this company. Do not read workspace/threads/handoff.json yourself.
  3. Board status comes from the work mesh, never local prd.passes. For each matching project, load the live Board from cache / Desktop live read: orient already did the cache read, and the block's Board (work mesh cache): line has the queued / in progress / review / done counts and the next queued story for each listed project, from this company's cache only. Do not read the cache files one by one. A project marked no board has no cache entry. If the Board block is absent, use local prd only for project description and acceptance; never as live Board columns. The Projects line's open counts are local too.

Summarize the company totals from the Board line.

  1. If the block's Integrations line reads "not cached", run bash core/scripts/usable-integrations.sh show --company {co} once. That is the only network call startwork may make, and it is skipped when the cache is fresh
  2. Git state only for a repo the user named (or the via: repo resolution in §1.1): git -C {repo} branch --show-current and git -C {repo} log --oneline -3
  3. For that same repo, run bash core/scripts/startwork-context.sh edit-target --repo "{repo}" and show its lines in the orientation block (see "Edit target" below).
Project Mode (arg = project name)

Board status comes from the work mesh, never local prd.passes. If ground/check and the project-view cache both fail, then and only then use local prd for description — still not as live Board columns.

  1. Resolve the project dir (personal/projects/{name} or companies/{co}/projects/{name}); when the path is under companies/{co}, bind that company now. Read prd.json only for name, description, branchName, and acceptance text — not story status.
  2. Extract metadata.repoPath — identify company by matching against manifest repos if the project path did not identify it (bash core/scripts/startwork-context.sh resolve --arg "{repo basename}"). Bind the resolved company before continuing.

2b. Once {co} is known, bind and render in one call: bash core/scripts/startwork-context.sh orient --company "{co}" --mode Project --project "{name}" (this is the §1.2 bind; do not run it twice). The block's last line carries the project goal and branch; the rest is the company context from Company Mode step 1. When the fast path already bound {co} and only the project is new, run bash core/scripts/startwork-context.sh block --company "{co}" --project "{name}" and record the project with §2.4.

  1. If repoPath exists: git -C {repoPath} branch --show-current and git -C {repoPath} status --short, then bash core/scripts/startwork-context.sh edit-target --repo "{repoPath}" for the orientation block's "Edit target" lines
  2. If company {co} is resolved, load the live Board from cache / Desktop live read (presence is automatic via hq daemon). Prefer ~/.hq/work-mesh/cache/projects/{companyUid}/{projectId}.json when present. Do not call deleted hq mesh session ground|check|watch.

Include active mesh thread owners/blockers in the orientation block when available. Session presence is automatic — do not mint cards during orientation.

  1. Read session journals (spec: core/knowledge/public/hq-core/journal-spec.md). If {project_dir}/journal/ exists:
Task Mode (arg = free-text task description)
  1. Resolve company/repo from cwd or recent handoff context (read workspace/threads/handoff.json if exists)
  1. Classify task using inline pattern table:
  1. Map to worker pipeline (same sequences as /prd command Step 5)
  2. If company resolved, check company-specific workers in manifest — prefer over generic
Repo Mode (arg = repo directory name)
  1. Resolve full path: check repos/private/{arg} then repos/public/{arg}
  2. Owning company: scan companies/manifest.yaml for a company whose repos: list contains this path, then bind it before repository commands
  3. Git state: git -C {repoPath} branch --show-current, git -C {repoPath} log --oneline -5, git -C {repoPath} status --short

3b. Edit target: bash core/scripts/startwork-context.sh edit-target --repo "{repoPath}". Show its lines in the orientation block. Write and Edit are blocked under repos/, so do not create a branch in the main checkout; run the printed worktree.sh command before the first edit.

  1. Related projects:

2.4 Persist Session Metadata

The orient call in §1.2 (or the fast path) already wrote company, mode and,

in Project mode, the project into the current session's metadata, so

per-company hooks and other context-aware skills can find them. Do not repeat

it. Only add what orient could not know, in one call when there is anything:

# A project or task found after orient ran (one call, both flags when known):
hq core work-mesh-bind-trusted \
  --company "{co}" --project "{project_name}" --task "{task_id}"
# Repo mode only:
bash core/scripts/hq-session.sh set repo "{repo_name}"

This file lives at workspace/sessions/<session_id>/meta.yaml. The current

session_id is bootstrapped by .claude/hooks/master-hook.sh on the first

hook event of every session and tracked in workspace/sessions/.current.

Important: until company_slug is set, the master hook runs no

per-company hooks (fail-closed for tenant isolation). Setting it from

startwork is what activates the per-company harness for the rest of the

session.

Skip if: no company resolved (resume mode with no company context).

2.5 Report Applicable Policies (display-only — no policy re-reads)

Policy loading is NOT this skill's job. Two mechanisms already inject policies before this step runs:

  1. Company policies: surfaced automatically when orient (§1.2 or the fast path) binds the company — the bind emits the company's hard-enforcement rules (deduped and budgeted) directly into the tool result. Do NOT re-scan companies/{co}/policies/ frontmatter here; that duplicates the bind emission.
  2. Repo policies: if repo context resolved and {repoPath}/.claude/policies/ exists, collect its files except example-policy.md, preserve their order, and split the stable file order into consecutive chunks of at most 40 files. For each chunk, run hq core policy frontmatter {file1} {file2} ... once with each path as a separate argument. Keep each call under 30 KB of output. The first output block belongs to the chunk’s first file argument; each later block belongs to the path named by its preceding # --- policy-file: <path> --- separator. This is the one scan this step still owns; repo policies are not covered by the company bind.
  3. Global policies: injected by the SessionStart/PreToolUse trigger hook (inject-policy-on-trigger.sh). No action here.

Display in orientation block (counts only — ls | wc -l is enough for N/K):

Policies: {N} company, {M} repo, {K} global ({H} hard-enforcement)

Rules:

2.6 Worker Routing & Skill Readiness

After policies are known, build a compact Worker Packet for the resolved context.

  1. When a company is resolved, the capability block's Workers line is the candidate list; do not re-read core/workers/registry.yaml for it. Read the registry (auto-generated read-only index) only in task mode without a company, or to map an intent onto public workers, and keep only entries relevant to the current company, project, repo, or task intent. Skip any entry whose path is not a directory containing worker.yaml. If an active company worker is listed but missing, say so in the orientation block — do not invent a raw-script fallback.
  2. If company {co} is resolved, include any registry entries whose company: field is {co} (sourced from worker.company in each worker.yaml) or whose path starts with companies/{co}/workers/.
  3. If project mode and prd.json story metadata includes declared workers or worker hints, include those first.
  4. If task mode, map the classified intent to a worker route before offering direct execution:
  1. Do not read every worker.yaml. Read a worker.yaml only when:

Display in orientation block:

Worker route: {primary worker/skill or "none matched"} ({N} candidates)

Rules:

3. Present Options

Display a concise orientation block:

Session Start
--------------
{Mode: Resume | Company: {slug} | Project: {name}}
{<startwork-context> block, verbatim, whenever a company is resolved}

{If resume: "Last session: {summary}" + "Next steps: {next_steps with status: open}" + "Still open from earlier handoffs: {hq core handoff open-steps list --limit 10, excluding this thread}"; any delegation manifest under workspace/delegations/ still at status `sent` gets `hq core delegate pickup --manifest <m> --check` and its result shown as verified / waiting / FAILED}
{If project: "Goal: {description}" + "Branch: {branchName}"}
{If repo: "Repo: {repoPath}" + "Company: {slug}" + "Branch: {branch}"}
{If a repo was resolved (Repo mode, `via: repo`, or a project repoPath): the `edit-target` lines verbatim, so the worktree command is on screen before any work starts}
{If task: "Task: {description}" + "Intent: {classified_intent}" + "Pipeline: {worker count} workers"}

Git: {branch} @ {short-hash} {" (dirty)" if dirty}
Worker route: {primary worker/skill or "none matched"} ({N} candidates)

Active work:
  - {project} -- {done}/{total} stories ({remaining} left)
  ...

Board (work mesh):
  - {id} {title} — {status}
  ...
Work mesh threads:
  {active mesh owners/blockers for the selected company/project, or omit if none/unavailable}

Then present numbered options built from context:

Output the numbered list and wait for user input. When an option starts another skill, phrase it as the skill name for the user to send as its own message (for example "send /deep-plan {co} {description} as a new message"). Never suggest a message that chains two slash commands, such as /startwork {co} /deep-plan ...: the desktop app refuses to send it. If the user picks such an option by number, run the skill in this session instead of asking them to type it. After user picks, proceed directly into the work.

Rules

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.