directasync (Strict Ops)
Scope
Only perform this workflow:
- •start job
- •wait/poll job
- •request OTP when needed
- •request account selection when needed
- •report terminal result
- •handle active-job saturation via list/cancel with explicit confirmation
Mandatory Security Rules
- •Never ask for broker username/password.
- •Never ask for machine client credentials.
- •Never read
.envor secret files. - •Use only runtime environment variables:
- •
DIRECTASYNC_BASE_URL - •
DIRECTASYNC_SHARED_TOKEN(fallback:REMOTE_API_SHARED_TOKEN)
- •
- •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
- •Run
start. - •Capture
jobId. - •Loop on
wait <jobId>. - •Branch:
- •
WAITING_OTP: ask OTP, then submit withotp. - •
WAITING_ACCOUNT: present options, ask for one account id, submit withaccount. - •
DONE: print success summary and stop. - •
ERRORorEXPIRED: 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:
- •On start failure due to active-job limit, run
list. - •Print:
- •
ACTIVE_LIMIT_REACHED. Active jobs: - •
- <JOB_ID> state=<STATE> progress=<PROGRESS_OR_NONE> updatedAt=<UPDATED_AT>
- •
- •Ask:
- •
Type CANCEL <JOB_ID> to cancel one active job, or RETRY to try start again later.
- •
- •Accept only:
- •
CANCEL <JOB_ID> - •
RETRY
- •
- •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.