Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
"type": "git",
"url": "https://github.com/AgentWorkforce/trajectories"
},
"files": [
"dist"
],
"files": ["dist"],
"engines": {
"node": ">=20.0.0"
},
Expand Down
5 changes: 4 additions & 1 deletion src/core/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export function generateChapterId(): string {
* @returns True if valid format
*/
export function isValidTrajectoryId(id: string): boolean {
return /^traj_[a-z0-9]{12}$/.test(id);
// Accept the canonical 12-char form generated by this library AND the
// legacy `traj_<timestamp>_<hex>` form produced by external writers
// like the workforce workflow runner.
return /^traj_[a-z0-9_]+$/.test(id);
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/core/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const DecisionSchema = z.object({
*/
export const AgentParticipationSchema = z.object({
name: z.string().min(1, "Agent name is required"),
role: z.enum(["lead", "contributor", "reviewer"]),
role: z.string().min(1, "Agent role is required"),
joinedAt: z.string().datetime(),
leftAt: z.string().datetime().optional(),
});
Expand Down Expand Up @@ -231,7 +231,7 @@ export const TrajectoryTraceRefSchema = z.object({
* Full trajectory schema
*/
export const TrajectorySchema = z.object({
id: z.string().regex(/^traj_[a-z0-9]+$/, "Invalid trajectory ID format"),
id: z.string().regex(/^traj_[a-z0-9_]+$/, "Invalid trajectory ID format"),
version: z.literal(1),
task: TaskReferenceSchema,
status: TrajectoryStatusSchema,
Expand All @@ -240,11 +240,11 @@ export const TrajectorySchema = z.object({
agents: z.array(AgentParticipationSchema),
chapters: z.array(ChapterSchema),
retrospective: RetrospectiveSchema.optional(),
commits: z.array(z.string()),
filesChanged: z.array(z.string()),
projectId: z.string(),
commits: z.array(z.string()).default([]),
filesChanged: z.array(z.string()).default([]),
projectId: z.string().optional(),
workflowId: z.string().optional(),
tags: z.array(z.string()),
tags: z.array(z.string()).default([]),
_trace: TrajectoryTraceRefSchema.optional(),
});

Expand Down
13 changes: 10 additions & 3 deletions src/core/trailers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ export function parseTrajectoryFromMessage(
): string | null {
const lines = commitMessage.split("\n");
for (const line of lines) {
// Character class must include `_` to match legacy
// `traj_<timestamp>_<hex>` ids produced by the workforce workflow runner
// in addition to the canonical `traj_<12hex>` shape. This must stay in
// sync with the regex in src/core/schema.ts and src/core/id.ts.
const match = line.match(
new RegExp(`^${TRAJECTORY_TRAILER_KEY}:\\s*(traj_[a-z0-9]+)$`),
new RegExp(`^${TRAJECTORY_TRAILER_KEY}:\\s*(traj_[a-z0-9_]+)$`),
);
if (match) {
return match[1];
Expand Down Expand Up @@ -196,8 +200,11 @@ if [ -z "$ACTIVE_FILE" ]; then
exit 0
fi

# Extract trajectory ID (grep for the "id" field)
TRAJ_ID=$(grep -o '"id"[[:space:]]*:[[:space:]]*"traj_[a-z0-9]*"' "$ACTIVE_FILE" | head -1 | grep -o 'traj_[a-z0-9]*')
# Extract trajectory ID (grep for the "id" field). Character class must
# include underscore to match legacy traj_<timestamp>_<hex> ids -- without
# it, grep -o silently truncates at the first internal underscore and
# emits a wrong (shorter) id into the commit trailer.
TRAJ_ID=$(grep -o '"id"[[:space:]]*:[[:space:]]*"traj_[a-z0-9_]*"' "$ACTIVE_FILE" | head -1 | grep -o 'traj_[a-z0-9_]*')
if [ -z "$TRAJ_ID" ]; then
exit 0
fi
Expand Down
20 changes: 15 additions & 5 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ export type TrajectoryEventType =
| "finding"
| "reflection"
| "note"
| "error";
| "error"
// Permissive fallback for event types produced by other tools
// (e.g. agent-relay's "completion-evidence"). The zod schema already
// accepts these via z.union([...literals, z.string()]); this keeps
// the TS type aligned so readers can assign freely.
| (string & {});

/**
* Significance level for events
Expand Down Expand Up @@ -149,8 +154,13 @@ export interface Finding {
export interface AgentParticipation {
/** Agent identifier */
name: string;
/** Role in the trajectory */
role: "lead" | "contributor" | "reviewer";
/**
* Role in the trajectory. Common values are "lead", "contributor",
* "reviewer", but this is intentionally open-ended — the workforce
* workflow runner emits domain-specific roles like "workflow-runner"
* and "specialist" that we want to read without rejecting.
*/
role: string;
/** When the agent joined */
joinedAt: string;
/** When the agent left (if applicable) */
Expand Down Expand Up @@ -223,8 +233,8 @@ export interface Trajectory {
commits: string[];
/** Files that were modified */
filesChanged: string[];
/** Project identifier */
projectId: string;
/** Project identifier. Optional — legacy trajectories may omit it. */
projectId?: string;
/** Opaque id set by the workflow runner via TRAJECTORIES_WORKFLOW_ID env var. Lets trail compact --workflow <id> collate all trajectories from a single workflow run. */
workflowId?: string;
/** User-defined tags */
Expand Down
Loading
Loading