{"version":3,"file":"task.cjs","names":["Type","InlineAgentSchema"],"sources":["../../../src/schemas/task.ts"],"sourcesContent":["export { COMMAND_NAME } from '../constants/task';\nimport { InlineAgentSchema } from '@agimon-ai/doompi-core/delegation';\nimport { type Static, Type } from 'typebox';\n\nimport type { TaskAction } from '../models/task';\nimport { MAX_BRIEF_FILES } from '../types/delegation';\n\nexport const TASK_ACTIONS = ['upsert', 'list', 'get', 'delete', 'clear', 'assign', 'cancel'] as const;\nexport const TASK_STATUSES = ['pending', 'in_progress', 'completed', 'failed', 'deleted'] as const;\nexport const TASK_CONTEXTS = ['fresh', 'fork'] as const;\n\nexport const TOOL_NAME = 'task';\nexport const TOOL_LABEL = 'Task';\n\nexport const ERR_REQUIRES_INTERACTIVE = '/tasks requires interactive mode';\nexport const MSG_NO_TASKS = 'No tasks yet. Ask the agent to add some!';\n\n/**\n * Which top-level fields each action accepts.\n *\n * The params object is flat and shared across every action, so the schema alone\n * cannot express \"upsert has no top-level id\". That gap matters: a call like\n * `{\"action\":\"upsert\",\"id\":3,\"tasks\":[{\"status\":\"completed\"}]}` would otherwise\n * silently create a duplicate task, because the entry itself carries no id.\n */\nexport const TASK_ACTION_FIELDS = {\n  upsert: ['action', 'tasks'],\n  list: ['action', 'status', 'includeDeleted'],\n  get: ['action', 'id'],\n  delete: ['action', 'id'],\n  clear: ['action'],\n  assign: ['action', 'assignments'],\n  cancel: ['action', 'id'],\n} as const satisfies Record<TaskAction, readonly string[]>;\n\nexport function taskActionAcceptsField(action: TaskAction, field: string): boolean {\n  return (TASK_ACTION_FIELDS[action] as readonly string[]).includes(field);\n}\n\n/** Correction hint appended when a per-task field lands at the top level. */\nexport const MSG_UPSERT_FIELD_MISPLACED =\n  'Per-task fields belong inside each tasks[] entry, not at the top level: {\"action\":\"upsert\",\"tasks\":[{\"id\":3,\"status\":\"completed\"}]}.';\n\n/**\n * A dependency target: an existing task id, or the `ref` of a task created\n * earlier in the same call.\n */\nconst DepTokenSchema = Type.Union([Type.Integer(), Type.String()]);\n\n/**\n * One entry of an upsert. `additionalProperties: false` is load-bearing: pi\n * validates tool arguments against this schema before `execute` runs, so a\n * stray `{\"action\":\"update\"}` inside an entry is rejected at the boundary.\n */\nexport const TaskItemSchema = Type.Object(\n  {\n    id: Type.Optional(\n      Type.Integer({\n        description:\n          'Existing task id to change. Omit to create. An unknown id fails only that entry; it never creates.',\n      }),\n    ),\n    ref: Type.Optional(\n      Type.String({\n        description:\n          'Temporary name for a task created by this entry, so a LATER entry in this array can list it in blockedBy. Must start with a letter; never stored.',\n      }),\n    ),\n    subject: Type.Optional(\n      Type.String({\n        description: 'Short imperative subject. Required when the entry has no id; on an entry with an id it renames.',\n      }),\n    ),\n    description: Type.Optional(\n      Type.String({ description: 'Long-form detail; becomes the brief handed to the subagent on assign.' }),\n    ),\n    activeForm: Type.Optional(\n      Type.String({ description: \"Present-continuous label shown while in_progress (e.g. 'writing tests')\" }),\n    ),\n    status: Type.Optional(\n      Type.String({\n        enum: [...TASK_STATUSES],\n        description:\n          'New entries default to pending and cannot start deleted; on an entry with an id the transition must be legal.',\n      }),\n    ),\n    blockedBy: Type.Optional(\n      Type.Array(DepTokenSchema, {\n        description:\n          'Dependencies for a NEW entry: task ids, or refs of tasks created EARLIER in this array. On an entry with an id use addBlockedBy / removeBlockedBy instead.',\n      }),\n    ),\n    addBlockedBy: Type.Optional(\n      Type.Array(DepTokenSchema, {\n        description: 'Dependencies to add (ids or earlier refs). Additive; do not resend the full array.',\n      }),\n    ),\n    removeBlockedBy: Type.Optional(\n      Type.Array(DepTokenSchema, {\n        description: 'Dependencies to remove. Additive; do not resend the full array.',\n      }),\n    ),\n    owner: Type.Optional(Type.String({ description: 'Owner label; assign sets it to the subagent name.' })),\n    metadata: Type.Optional(\n      Type.Record(Type.String(), Type.Unknown(), {\n        description: 'Merged into the task; a null value deletes that key.',\n      }),\n    ),\n  },\n  { additionalProperties: false },\n);\n\n/** One task-to-agent handoff in a native assignment batch. */\nexport const TaskAssignmentSchema = Type.Object(\n  {\n    id: Type.Integer({ description: 'Pending, unblocked task id to delegate' }),\n    agent: Type.String({ description: 'Exact discovered subagent name' }),\n    inlineAgent: Type.Optional(InlineAgentSchema),\n    instructions: Type.Optional(Type.String({ description: 'Extra instructions appended to this delegated brief' })),\n    relevantFiles: Type.Optional(\n      Type.Array(Type.String(), {\n        description: `Files already read or located, relative to the working directory; at most ${MAX_BRIEF_FILES} are used.`,\n      }),\n    ),\n    priorFindings: Type.Optional(\n      Type.String({ description: 'Established facts this child should consume rather than re-derive' }),\n    ),\n    model: Type.Optional(Type.String({ description: 'Model override for this delegated run' })),\n    context: Type.Optional(\n      Type.String({\n        enum: [...TASK_CONTEXTS],\n        description: \"Starting context for this child: 'fresh' or 'fork'\",\n      }),\n    ),\n  },\n  { additionalProperties: false },\n);\n\n/**\n * Tool parameters. Every `description` doubles as LLM-facing prompt copy, so\n * wording changes here change model behaviour.\n */\nexport const TaskParamsSchema = Type.Object({\n  action: Type.String({ enum: [...TASK_ACTIONS] }),\n  tasks: Type.Optional(\n    Type.Array(TaskItemSchema, {\n      minItems: 1,\n      description:\n        'upsert only. An entry with an id changes that task, an entry without an id creates one. Entries apply in array order, so a later entry can depend on an earlier one by ref.',\n    }),\n  ),\n  assignments: Type.Optional(\n    Type.Array(TaskAssignmentSchema, {\n      minItems: 1,\n      description: 'Required for assign, one entry per task, including when there is only one.',\n    }),\n  ),\n  id: Type.Optional(\n    Type.Integer({\n      description:\n        'Task id, for get, delete and cancel. Not accepted by upsert or assign: those carry ids inside tasks[] and assignments[] entries.',\n    }),\n  ),\n  status: Type.Optional(\n    Type.String({\n      enum: [...TASK_STATUSES],\n      description: 'list only: return just the tasks in this status. To SET a status, upsert the task by id.',\n    }),\n  ),\n  includeDeleted: Type.Optional(\n    Type.Boolean({ description: 'list only: also return deleted tombstones. Default false.' }),\n  ),\n});\n\nexport type TaskItemParams = Static<typeof TaskItemSchema>;\nexport type TaskAssignmentParams = Static<typeof TaskAssignmentSchema>;\nex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