Skip to content

Commit 733e8e3

Browse files
authored
fix(routines): origin-only fallback for stagnation monitor deduplication (DLD-4090) (#9)
Adds a third fallback tier to both findLiveExecutionIssue() and listLiveIssueByRoutineIds() in server/src/services/routines.ts. When a Monitor-created stagnation issue has no active heartbeatRun attached, the two existing queries (execution-bound + context-snapshot-bound) both return null. The new origin-only query bridges the gap by matching on originKind=routine_execution + originId=routine.id alone, with no heartbeat run join. Fixes: DLD-4090 Closes: DLD-4099
1 parent 193a987 commit 733e8e3

950 files changed

Lines changed: 371031 additions & 7515 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
---
2+
name: company-creator
3+
description: >
4+
Create agent company packages conforming to the Agent Companies specification
5+
(agentcompanies/v1). Use when a user wants to create a new agent company from
6+
scratch, build a company around an existing git repo or skills collection, or
7+
scaffold a team/department of agents. Triggers on: "create a company", "make me
8+
a company", "build a company from this repo", "set up an agent company",
9+
"create a team of agents", "hire some agents", or when given a repo URL and
10+
asked to turn it into a company. Do NOT use for importing an existing company
11+
package (use the CLI import command instead) or for modifying a company that
12+
is already running in Paperclip.
13+
---
14+
15+
# Company Creator
16+
17+
Create agent company packages that conform to the Agent Companies specification.
18+
19+
Spec references:
20+
21+
- Normative spec: `docs/companies/companies-spec.md` (read this before generating files)
22+
- Web spec: https://agentcompanies.io/specification
23+
- Protocol site: https://agentcompanies.io/
24+
25+
## Two Modes
26+
27+
### Mode 1: Company From Scratch
28+
29+
The user describes what they want. Interview them to flesh out the vision, then generate the package.
30+
31+
### Mode 2: Company From a Repo
32+
33+
The user provides a git repo URL, local path, or tweet. Analyze the repo, then create a company that wraps it.
34+
35+
See [references/from-repo-guide.md](references/from-repo-guide.md) for detailed repo analysis steps.
36+
37+
## Process
38+
39+
### Step 1: Gather Context
40+
41+
Determine which mode applies:
42+
43+
- **From scratch**: What kind of company or team? What domain? What should the agents do?
44+
- **From repo**: Clone/read the repo. Scan for existing skills, agent configs, README, source structure.
45+
46+
### Step 2: Interview (Use AskUserQuestion)
47+
48+
Do not skip this step. Use AskUserQuestion to align with the user before writing any files.
49+
50+
**For from-scratch companies**, ask about:
51+
52+
- Company purpose and domain (1-2 sentences is fine)
53+
- What agents they need - propose a hiring plan based on what they described
54+
- Whether this is a full company (needs a CEO) or a team/department (no CEO required)
55+
- Any specific skills the agents should have
56+
- How work flows through the organization (see "Workflow" below)
57+
- Whether they want projects and starter tasks
58+
59+
**For from-repo companies**, present your analysis and ask:
60+
61+
- Confirm the agents you plan to create and their roles
62+
- Whether to reference or vendor any discovered skills (default: reference)
63+
- Any additional agents or skills beyond what the repo provides
64+
- Company name and any customization
65+
- Confirm the workflow you inferred from the repo (see "Workflow" below)
66+
67+
**Workflow — how does work move through this company?**
68+
69+
A company is not just a list of agents with skills. It's an organization that takes ideas and turns them into work products. You need to understand the workflow so each agent knows:
70+
71+
- Who gives them work and in what form (a task, a branch, a question, a review request)
72+
- What they do with it
73+
- Who they hand off to when they're done, and what that handoff looks like
74+
- What "done" means for their role
75+
76+
**Not every company is a pipeline.** Infer the right workflow pattern from context:
77+
78+
- **Pipeline** — sequential stages, each agent hands off to the next. Use when the repo/domain has a clear linear process (e.g. plan → build → review → ship → QA, or content ideation → draft → edit → publish).
79+
- **Hub-and-spoke** — a manager delegates to specialists who report back independently. Use when agents do different kinds of work that don't feed into each other (e.g. a CEO who dispatches to a researcher, a marketer, and an analyst).
80+
- **Collaborative** — agents work together on the same things as peers. Use for small teams where everyone contributes to the same output (e.g. a design studio, a brainstorming team).
81+
- **On-demand** — agents are summoned as needed with no fixed flow. Use when agents are more like a toolbox of specialists the user calls directly.
82+
83+
For from-scratch companies, propose a workflow pattern based on what they described and ask if it fits.
84+
85+
For from-repo companies, infer the pattern from the repo's structure. If skills have a clear sequential dependency (like `plan-ceo-review → plan-eng-review → review → ship → qa`), that's a pipeline. If skills are independent capabilities, it's more likely hub-and-spoke or on-demand. State your inference in the interview so the user can confirm or adjust.
86+
87+
**Key interviewing principles:**
88+
89+
- Propose a concrete hiring plan. Don't ask open-ended "what agents do you want?" - suggest specific agents based on context and let the user adjust.
90+
- Keep it lean. Most users are new to agent companies. A few agents (3-5) is typical for a startup. Don't suggest 10+ agents unless the scope demands it.
91+
- From-scratch companies should start with a CEO who manages everyone. Teams/departments don't need one.
92+
- Ask 2-3 focused questions per round, not 10.
93+
94+
### Step 3: Read the Spec
95+
96+
Before generating any files, read the normative spec:
97+
98+
```
99+
docs/companies/companies-spec.md
100+
```
101+
102+
Also read the quick reference: [references/companies-spec.md](references/companies-spec.md)
103+
104+
And the example: [references/example-company.md](references/example-company.md)
105+
106+
### Step 4: Generate the Package
107+
108+
Create the directory structure and all files. Follow the spec's conventions exactly.
109+
110+
**Directory structure:**
111+
112+
```
113+
<company-slug>/
114+
├── COMPANY.md
115+
├── agents/
116+
│ └── <slug>/AGENTS.md
117+
├── teams/
118+
│ └── <slug>/TEAM.md (if teams are needed)
119+
├── projects/
120+
│ └── <slug>/PROJECT.md (if projects are needed)
121+
├── tasks/
122+
│ └── <slug>/TASK.md (if tasks are needed)
123+
├── skills/
124+
│ └── <slug>/SKILL.md (if custom skills are needed)
125+
└── .paperclip.yaml (Paperclip vendor extension)
126+
```
127+
128+
**Rules:**
129+
130+
- Slugs must be URL-safe, lowercase, hyphenated
131+
- COMPANY.md gets `schema: agentcompanies/v1` - other files inherit it
132+
- Agent instructions go in the AGENTS.md body, not in .paperclip.yaml
133+
- Skills referenced by shortname in AGENTS.md resolve to `skills/<shortname>/SKILL.md`
134+
- For external skills, use `sources` with `usage: referenced` (see spec section 12)
135+
- Do not export secrets, machine-local paths, or database IDs
136+
- Omit empty/default fields
137+
- For companies generated from a repo, add a references footer at the bottom of COMPANY.md body:
138+
`Generated from [repo-name](repo-url) with the company-creator skill from [Paperclip](https://github.com/paperclipai/paperclip)`
139+
140+
**Reporting structure:**
141+
142+
- Every agent except the CEO should have `reportsTo` set to their manager's slug
143+
- The CEO has `reportsTo: null`
144+
- For teams without a CEO, the top-level agent has `reportsTo: null`
145+
146+
**Writing workflow-aware agent instructions:**
147+
148+
Each AGENTS.md body should include not just what the agent does, but how they fit into the organization's workflow. Include:
149+
150+
1. **Where work comes from** — "You receive feature ideas from the user" or "You pick up tasks assigned to you by the CTO"
151+
2. **What you produce** — "You produce a technical plan with architecture diagrams" or "You produce a reviewed, approved branch ready for shipping"
152+
3. **Who you hand off to** — "When your plan is locked, hand off to the Staff Engineer for implementation" or "When review passes, hand off to the Release Engineer to ship"
153+
4. **What triggers you** — "You are activated when a new feature idea needs product-level thinking" or "You are activated when a branch is ready for pre-landing review"
154+
155+
This turns a collection of agents into an organization that actually works together. Without workflow context, agents operate in isolation — they do their job but don't know what happens before or after them.
156+
157+
### Step 5: Confirm Output Location
158+
159+
Ask the user where to write the package. Common options:
160+
161+
- A subdirectory in the current repo
162+
- A new directory the user specifies
163+
- The current directory (if it's empty or they confirm)
164+
165+
### Step 6: Write README.md and LICENSE
166+
167+
**README.md** — every company package gets a README. It should be a nice, readable introduction that someone browsing GitHub would appreciate. Include:
168+
169+
- Company name and what it does
170+
- The workflow / how the company operates
171+
- Org chart as a markdown list or table showing agents, titles, reporting structure, and skills
172+
- Brief description of each agent's role
173+
- Citations and references: link to the source repo (if from-repo), link to the Agent Companies spec (https://agentcompanies.io/specification), and link to Paperclip (https://github.com/paperclipai/paperclip)
174+
- A "Getting Started" section explaining how to import: `paperclipai company import --from <path>`
175+
176+
**LICENSE** — include a LICENSE file. The copyright holder is the user creating the company, not the upstream repo author (they made the skills, the user is making the company). Use the same license type as the source repo (if from-repo) or ask the user (if from-scratch). Default to MIT if unclear.
177+
178+
### Step 7: Write Files and Summarize
179+
180+
Write all files, then give a brief summary:
181+
182+
- Company name and what it does
183+
- Agent roster with roles and reporting structure
184+
- Skills (custom + referenced)
185+
- Projects and tasks if any
186+
- The output path
187+
188+
## .paperclip.yaml Guidelines
189+
190+
The `.paperclip.yaml` file is the Paperclip vendor extension. It configures adapters and env inputs per agent.
191+
192+
### Adapter Rules
193+
194+
**Do not specify an adapter unless the repo or user context warrants it.** If you don't know what adapter the user wants, omit the adapter block entirely — Paperclip will use its default. Specifying an unknown adapter type causes an import error.
195+
196+
Paperclip's supported adapter types (these are the ONLY valid values):
197+
- `claude_local` — Claude Code CLI
198+
- `codex_local` — Codex CLI
199+
- `opencode_local` — OpenCode CLI
200+
- `pi_local` — Pi CLI
201+
- `cursor` — Cursor
202+
- `gemini_local` — Gemini CLI
203+
- `openclaw_gateway` — OpenClaw gateway
204+
205+
Only set an adapter when:
206+
- The repo or its skills clearly target a specific runtime (e.g. gstack is built for Claude Code, so `claude_local` is appropriate)
207+
- The user explicitly requests a specific adapter
208+
- The agent's role requires a specific runtime capability
209+
210+
### Env Inputs Rules
211+
212+
**Do not add boilerplate env variables.** Only add env inputs that the agent actually needs based on its skills or role:
213+
- `GH_TOKEN` for agents that push code, create PRs, or interact with GitHub
214+
- API keys only when a skill explicitly requires them
215+
- Never set `ANTHROPIC_API_KEY` as a default empty env variable — the runtime handles this
216+
217+
Example with adapter (only when warranted):
218+
```yaml
219+
schema: paperclip/v1
220+
agents:
221+
release-engineer:
222+
adapter:
223+
type: claude_local
224+
config:
225+
model: claude-sonnet-4-6
226+
inputs:
227+
env:
228+
GH_TOKEN:
229+
kind: secret
230+
requirement: optional
231+
```
232+
233+
Example — only agents with actual overrides appear:
234+
```yaml
235+
schema: paperclip/v1
236+
agents:
237+
release-engineer:
238+
inputs:
239+
env:
240+
GH_TOKEN:
241+
kind: secret
242+
requirement: optional
243+
```
244+
245+
In this example, only `release-engineer` appears because it needs `GH_TOKEN`. The other agents (ceo, cto, etc.) have no overrides, so they are omitted entirely from `.paperclip.yaml`.
246+
247+
## External Skill References
248+
249+
When referencing skills from a GitHub repo, always use the references pattern:
250+
251+
```yaml
252+
metadata:
253+
sources:
254+
- kind: github-file
255+
repo: owner/repo
256+
path: path/to/SKILL.md
257+
commit: <full SHA from git ls-remote or the repo>
258+
attribution: Owner or Org Name
259+
license: <from the repo's LICENSE>
260+
usage: referenced
261+
```
262+
263+
Get the commit SHA with:
264+
265+
```bash
266+
git ls-remote https://github.com/owner/repo HEAD
267+
```
268+
269+
Do NOT copy external skill content into the package unless the user explicitly asks.

0 commit comments

Comments
 (0)