mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-09 08:59:40 +02:00
docs: add JSDoc comments to task.ts
Documentation for Task model: - Module-level description - CreateTaskOptions interface - Class description with lifecycle - Key method documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+23
@@ -1,6 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* @fileoverview Task model for Claude prompt execution
|
||||||
|
*
|
||||||
|
* Represents a single task (prompt) to be executed by a Claude session.
|
||||||
|
* Tasks support priority ordering, dependencies, and completion detection.
|
||||||
|
*
|
||||||
|
* @module task
|
||||||
|
*/
|
||||||
|
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { TaskDefinition, TaskState, TaskStatus } from './types.js';
|
import { TaskDefinition, TaskState, TaskStatus } from './types.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for creating a new task.
|
||||||
|
*/
|
||||||
export interface CreateTaskOptions {
|
export interface CreateTaskOptions {
|
||||||
prompt: string;
|
prompt: string;
|
||||||
workingDir?: string;
|
workingDir?: string;
|
||||||
@@ -10,6 +22,13 @@ export interface CreateTaskOptions {
|
|||||||
timeoutMs?: number;
|
timeoutMs?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A task representing a prompt to be executed by a Claude session.
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
* Tasks have a lifecycle: pending → running → completed/failed
|
||||||
|
* They support priority ordering and dependency chains.
|
||||||
|
*/
|
||||||
export class Task {
|
export class Task {
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
readonly prompt: string;
|
readonly prompt: string;
|
||||||
@@ -107,6 +126,7 @@ export class Task {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Reconstructs a Task from persisted state. */
|
||||||
static fromState(state: TaskState): Task {
|
static fromState(state: TaskState): Task {
|
||||||
const task = new Task(
|
const task = new Task(
|
||||||
{
|
{
|
||||||
@@ -128,6 +148,7 @@ export class Task {
|
|||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Assigns this task to a session and marks it as running. */
|
||||||
assign(sessionId: string): void {
|
assign(sessionId: string): void {
|
||||||
if (this._status !== 'pending') {
|
if (this._status !== 'pending') {
|
||||||
throw new Error(`Cannot assign task ${this.id}: status is ${this._status}`);
|
throw new Error(`Cannot assign task ${this.id}: status is ${this._status}`);
|
||||||
@@ -167,6 +188,7 @@ export class Task {
|
|||||||
this._error = null;
|
this._error = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if output contains the completion phrase. */
|
||||||
checkCompletion(output: string): boolean {
|
checkCompletion(output: string): boolean {
|
||||||
if (this.completionPhrase) {
|
if (this.completionPhrase) {
|
||||||
// Check for exact completion phrase in promise tags
|
// Check for exact completion phrase in promise tags
|
||||||
@@ -177,6 +199,7 @@ export class Task {
|
|||||||
return /<promise>[^<]+<\/promise>/.test(output);
|
return /<promise>[^<]+<\/promise>/.test(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns true if the task has exceeded its timeout. */
|
||||||
isTimedOut(): boolean {
|
isTimedOut(): boolean {
|
||||||
if (!this.timeoutMs || !this._startedAt) {
|
if (!this.timeoutMs || !this._startedAt) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user