Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

2.9 KB
Raw Blame
import type { MacroClient } from '../../utils/client';
import type { Initiative } from '../initiatives/initiative';
import type { Project } from '../projects/project';
import type { SearchOpts } from '../search/options';
import type { Team } from '../teams/team';
import type { User } from '../users/user';
import { type SimilarTask, Task, type TaskSummary } from './task';

/**
 * Tasks: one `create` call sets initiative, assignees and due date; one
 * `summaries` call reads many names (`name()` loads each whole document).
 * Creating a task needs only what the request states; don't research what it
 * describes unless asked.
 *
 * @routing Use when creating, assigning or updating tasks, or reporting on tasks such as open or overdue ones; not reminders, which are routines.
 *
 * @agent
 * Never edit, merge or delete the tasks `findSimilar` matches unless the user asks.
 */
export class TaskNamespace {
  constructor(private readonly client: MacroClient) {}

  /** A handle to a task by document id. Details load on first access. */
  byId(id: string): Task {
    return Task.byId(this.client, id);
  }

  /**
   * Create a task, with its initiative, assignees and due date in the same
   * request. The task starts Not started.
   */
  create(opts: {
    name: string;
    markdown?: string;
    /** Folder the task document is filed in; unrelated to `initiative`. */
    project?: Project;
    /** The initiative (shown as the task's Project in the app) it belongs to. */
    initiative?: Initiative;
    /** Assignees; defaults to the creator. Pass `[]` to leave it unassigned. */
    assignees?: User[];
    dueDate?: Date;
    /** Scopes the team task number; may be omitted when the creator belongs to exactly one team. */
    team?: Team;
    /** Defaults to true. */
    shareWithTeam?: boolean;
  }): Promise<Task> {
    return Task.create(this.client, opts);
  }

  /**
   * Names and state of many tasks in one request, in the order given. Tasks
   * that no longer exist are left out.
   */
  summaries(tasks: Task[]): Promise<TaskSummary[]> {
    return Task.summaries(this.client, tasks);
  }

  /**
   * Existing tasks of yours or your team's that look like the same work as a
   * task with this title and body, most similar first. Call it in the same
   * program as `create`: create only when nothing is a likely duplicate, and
   * otherwise return the matches and ask the user instead of creating.
   */
  findSimilar(opts: { title: string; body?: string }): Promise<SimilarTask[]> {
    return Task.findSimilar(this.client, opts);
  }

  /**
   * The tasks the GitHub pull request at `url` references, oldest link first.
   */
  forPullRequest(url: string): Promise<Task[]> {
    return Task.forPullRequest(this.client, url);
  }

  /** Search tasks by name and content, most relevant first, auto-paginated. */
  search(query: string, opts?: SearchOpts): AsyncGenerator<Task> {
    return Task.search(this.client, query, opts);
  }
}