AgentSkillsCN

directasync

通过远程 DirectAsync API,严格遵循 Directa → Bagholdr 同步的操作流程。在此文件夹中使用专用的客户端虚拟环境。

SKILL.md
--- frontmatter
name: directasync
description: Strict operations workflow for Directa -> Bagholdr sync via remote DirectAsync API. Uses dedicated client venv in this folder.

directasync (Strict Ops)

Scope

Only perform this workflow:

  1. start job
  2. wait/poll job
  3. request OTP when needed
  4. request account selection when needed
  5. report terminal result
  6. handle active-job saturation via list/cancel with explicit confirmation

Mandatory Security Rules

  1. Never ask for broker username/password.
  2. Never ask for machine client credentials.
  3. Never read .env or secret files.
  4. Use only runtime environment variables:
    • DIRECTASYNC_BASE_URL
    • DIRECTASYNC_SHARED_TOKEN (fallback: REMOTE_API_SHARED_TOKEN)
  5. If config is missing, stop and print exactly:
    • BLOCKED: missing DIRECTASYNC_BASE_URL
    • BLOCKED: missing DIRECTASYNC_SHARED_TOKEN (or REMOTE_API_SHARED_TOKEN)

Required Command Surface

Use this exact binary:

  • {clientDir}/run-client.sh

Allowed commands:

  • {clientDir}/run-client.sh start
  • {clientDir}/run-client.sh wait <jobId>
  • {clientDir}/run-client.sh otp <jobId> --code "<OTP>"
  • {clientDir}/run-client.sh account <jobId> --account-id "<ACCOUNT_ID>"
  • {clientDir}/run-client.sh list
  • {clientDir}/run-client.sh cancel <jobId>

Do not call any other script.

State Machine

Recognized states:

  • STARTING
  • WAITING_OTP
  • OTP_RECEIVED
  • EXPORTING
  • SYNCING
  • WAITING_ACCOUNT
  • DONE
  • ERROR
  • EXPIRED

If unknown state appears, stop and print:

  • BLOCKED: unknown state <STATE> for job <JOB_ID>

Workflow

  1. Run start.
  2. Capture jobId.
  3. Loop on wait <jobId>.
  4. Branch:
    • WAITING_OTP: ask OTP, then submit with otp.
    • WAITING_ACCOUNT: present options, ask for one account id, submit with account.
    • DONE: print success summary and stop.
    • ERROR or EXPIRED: print failure summary and stop.
    • Other non-terminal states: continue waiting.

Fixed Prompt Templates

OTP:

  • OTP_REQUIRED jobId=<JOB_ID>. Please provide the OTP code.

Account selection:

  • ACCOUNT_SELECTION_REQUIRED jobId=<JOB_ID>. Choose one accountId from the list below:
  • one line per option: - <ACCOUNT_NAME> (<ACCOUNT_ID>)
  • final line: Reply with exactly one accountId.

Concurrency limit:

  1. On start failure due to active-job limit, run list.
  2. Print:
    • ACTIVE_LIMIT_REACHED. Active jobs:
    • - <JOB_ID> state=<STATE> progress=<PROGRESS_OR_NONE> updatedAt=<UPDATED_AT>
  3. Ask:
    • Type CANCEL <JOB_ID> to cancel one active job, or RETRY to try start again later.
  4. Accept only:
    • CANCEL <JOB_ID>
    • RETRY
  5. If cancelled, print:
    • CANCELLED jobId=<JOB_ID>
    • Type START to launch a new job, or STOP to end.

Fixed Terminal Output

Success:

  • SYNC_DONE jobId=<JOB_ID> ordersImported=<N> assetsCreated=<N> holdingsUpdated=<N> rowsSkipped=<N> warnings=<N> errors=<N>
  • each warning line: WARNING <TEXT>
  • each result error line: RESULT_ERROR <TEXT>

Failure:

  • SYNC_FAILED jobId=<JOB_ID> state=<STATE> code=<ERROR_CODE> retryable=<true|false> message="<ERROR_MESSAGE>"
  • Action: run a new start when ready.