1688-cli 0.1.41 → 0.1.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/AGENTS.md +112 -318
  2. package/ARCHITECTURE.md +107 -0
  3. package/CHANGELOG.md +79 -0
  4. package/README.md +186 -18
  5. package/dist/cli.js +131 -25
  6. package/dist/cli.js.map +1 -1
  7. package/dist/commands/cart-list.js +2 -1
  8. package/dist/commands/cart-list.js.map +1 -1
  9. package/dist/commands/checkout-confirm.js +8 -8
  10. package/dist/commands/checkout-confirm.js.map +1 -1
  11. package/dist/commands/compare.js +107 -0
  12. package/dist/commands/compare.js.map +1 -0
  13. package/dist/commands/doctor.js +64 -47
  14. package/dist/commands/doctor.js.map +1 -1
  15. package/dist/commands/inbox.js +1 -1
  16. package/dist/commands/inbox.js.map +1 -1
  17. package/dist/commands/login.js +14 -14
  18. package/dist/commands/login.js.map +1 -1
  19. package/dist/commands/logout.js +6 -4
  20. package/dist/commands/logout.js.map +1 -1
  21. package/dist/commands/offer.js +7 -5
  22. package/dist/commands/offer.js.map +1 -1
  23. package/dist/commands/order-list.js +4 -2
  24. package/dist/commands/order-list.js.map +1 -1
  25. package/dist/commands/order-logistics.js +4 -2
  26. package/dist/commands/order-logistics.js.map +1 -1
  27. package/dist/commands/profile.js +25 -9
  28. package/dist/commands/profile.js.map +1 -1
  29. package/dist/commands/research.js +142 -0
  30. package/dist/commands/research.js.map +1 -0
  31. package/dist/commands/search.js +59 -18
  32. package/dist/commands/search.js.map +1 -1
  33. package/dist/commands/seller-chat.js +1 -1
  34. package/dist/commands/seller-chat.js.map +1 -1
  35. package/dist/commands/seller-inquire.js +1 -1
  36. package/dist/commands/seller-inquire.js.map +1 -1
  37. package/dist/commands/seller-messages.js +8 -5
  38. package/dist/commands/seller-messages.js.map +1 -1
  39. package/dist/commands/sourcing-utils.js +438 -0
  40. package/dist/commands/sourcing-utils.js.map +1 -0
  41. package/dist/commands/supplier-inspect.js +559 -0
  42. package/dist/commands/supplier-inspect.js.map +1 -0
  43. package/dist/commands/supplier-search.js +522 -0
  44. package/dist/commands/supplier-search.js.map +1 -0
  45. package/dist/commands/whoami.js +6 -3
  46. package/dist/commands/whoami.js.map +1 -1
  47. package/dist/daemon/client.js +10 -6
  48. package/dist/daemon/client.js.map +1 -1
  49. package/dist/daemon/manager.js +53 -37
  50. package/dist/daemon/manager.js.map +1 -1
  51. package/dist/daemon/protocol.js +2 -1
  52. package/dist/daemon/protocol.js.map +1 -1
  53. package/dist/daemon/server.js +26 -22
  54. package/dist/daemon/server.js.map +1 -1
  55. package/dist/session/context.js +1 -1
  56. package/dist/session/context.js.map +1 -1
  57. package/dist/session/dispatch.js +25 -22
  58. package/dist/session/dispatch.js.map +1 -1
  59. package/dist/session/im-ws.js +8 -5
  60. package/dist/session/im-ws.js.map +1 -1
  61. package/dist/session/lock.js +14 -14
  62. package/dist/session/lock.js.map +1 -1
  63. package/dist/session/paths.js +50 -16
  64. package/dist/session/paths.js.map +1 -1
  65. package/dist/session/search-mtop.js +53 -0
  66. package/dist/session/search-mtop.js.map +1 -1
  67. package/dist/session/shared.js +17 -7
  68. package/dist/session/shared.js.map +1 -1
  69. package/dist/session/state.js +7 -7
  70. package/dist/session/state.js.map +1 -1
  71. package/dist/session/supplier-search.js +403 -0
  72. package/dist/session/supplier-search.js.map +1 -0
  73. package/dist/util/encoding.js +8 -0
  74. package/dist/util/encoding.js.map +1 -0
  75. package/dist/util/temp.js +6 -0
  76. package/dist/util/temp.js.map +1 -0
  77. package/docs/AGENT_MAPS_PLAN.md +171 -0
  78. package/docs/AGENT_WORKING_PRINCIPLES.md +143 -0
  79. package/docs/COMMANDS.md +205 -0
  80. package/docs/FEATURES.md +45 -0
  81. package/docs/JSON_CONTRACTS.md +476 -0
  82. package/docs/QUALITY_SCORE.md +61 -0
  83. package/docs/README.md +36 -0
  84. package/docs/RELIABILITY.md +69 -0
  85. package/docs/SAFETY.md +99 -0
  86. package/docs/WORKFLOW.md +82 -0
  87. package/docs/exec-plans/README.md +9 -0
  88. package/docs/exec-plans/active/README.md +4 -0
  89. package/docs/exec-plans/completed/2026-05-28-sourcing-research-v1.md +125 -0
  90. package/docs/exec-plans/completed/2026-05-31-supplier-inspect-v1.md +113 -0
  91. package/docs/exec-plans/completed/2026-06-04-supplier-search-v1.md +81 -0
  92. package/docs/exec-plans/completed/2026-06-07-windows-cli-compatibility.md +138 -0
  93. package/docs/exec-plans/completed/2026-06-16-profile-daemon.md +146 -0
  94. package/docs/exec-plans/completed/README.md +4 -0
  95. package/docs/exec-plans/tech-debt-tracker.md +5 -0
  96. package/docs/generated/command-index.md +54 -0
  97. package/docs/generated/json-shapes.md +111 -0
  98. package/docs/generated/module-map.md +13 -0
  99. package/docs/generated/test-index.md +34 -0
  100. package/docs/playbooks/add-command.md +15 -0
  101. package/docs/playbooks/add-mtop-capture.md +13 -0
  102. package/docs/playbooks/change-json-output.md +11 -0
  103. package/docs/playbooks/debug-risk-control.md +12 -0
  104. package/docs/playbooks/update-cli-release.md +61 -0
  105. package/docs/records/release-omissions.md +34 -0
  106. package/docs/specs/checkout-and-orders.md +30 -0
  107. package/docs/specs/index.md +9 -0
  108. package/docs/specs/profile-daemon.md +114 -0
  109. package/docs/specs/seller-im.md +28 -0
  110. package/docs/specs/sourcing-research.md +186 -0
  111. package/docs/specs/supplier-inspect.md +144 -0
  112. package/docs/specs/supplier-search.md +179 -0
  113. package/docs/specs/windows-cli-compatibility.md +123 -0
  114. package/package.json +21 -4
  115. package/scripts/check_agent_map.mjs +87 -0
  116. package/scripts/check_release.mjs +40 -0
  117. package/scripts/fix_bin_mode.mjs +18 -0
  118. package/scripts/generate_agent_context.mjs +253 -0
  119. package/scripts/postinstall.mjs +12 -4
package/docs/SAFETY.md ADDED
@@ -0,0 +1,99 @@
1
+ # Safety
2
+
3
+ This tool operates a real 1688 buyer account. Some commands read public or
4
+ account data; others contact sellers, mutate cart state, submit feedback, or
5
+ place orders. Treat write actions as explicit user-authorized operations.
6
+
7
+ ## Exit Codes
8
+
9
+ | Code | Meaning | Agent behavior |
10
+ |---:|---|---|
11
+ | 0 | Success | Continue. |
12
+ | 2 | Bad invocation | Fix arguments or report the bad input. |
13
+ | 3 | Not logged in / session expired | Tell the user to run `1688 login`; do not loop. |
14
+ | 4 | Risk control / slider verification | Tell the user to rerun once with `--headed`; do not silently retry. |
15
+ | 5 | Another 1688 command is running for the selected profile | Wait only if the task naturally allows it; otherwise report lock busy. |
16
+ | 6 | Chromium missing | Report dependency issue. |
17
+ | 7 | Login wait timeout | Report timeout. |
18
+ | 8 | Login finished but cookies missing | Report login cookie issue. |
19
+ | 9 | Network error | Report or retry only when safe and bounded. |
20
+ | 130 | User canceled | Stop. |
21
+
22
+ ## Login And Logout
23
+
24
+ - `1688 login` opens a user-interactive QR/browser flow. Only run it when the
25
+ user explicitly asks to log in.
26
+ - In non-interactive sessions, `1688 login` saves a QR PNG to
27
+ `~/.1688/login-qr.png` and prints `QR saved as PNG: <path>` on stderr.
28
+ Surface that file/path to the user and wait for the command to exit.
29
+ - Do not open the raw QR URL in a browser.
30
+ - `1688 logout --yes` destroys the cached session. Do not pass `--yes` without
31
+ explicit current-turn confirmation.
32
+
33
+ ## Risk Control
34
+
35
+ - If exit code `4` appears, tell the user to rerun the same command once with
36
+ `--headed`.
37
+ - The user must solve the slider manually.
38
+ - Do not silently retry the same blocked command.
39
+
40
+ ## Seller Contact
41
+
42
+ These commands contact real sellers:
43
+
44
+ ```bash
45
+ 1688 seller inquire <offerId> <message>
46
+ 1688 seller chat <orderId|loginId> <message>
47
+ ```
48
+
49
+ Before sending, show the message and target context unless the user has already
50
+ given an explicit current-turn send instruction.
51
+
52
+ ## Cart Mutations
53
+
54
+ These commands mutate buyer cart state:
55
+
56
+ ```bash
57
+ 1688 cart add <offerId> --sku <skuId> --qty N
58
+ 1688 cart remove <cartId>
59
+ ```
60
+
61
+ For agent use, show the offer/SKU/quantity or cart row being changed and run
62
+ only after the user approves that action.
63
+
64
+ ## Checkout Protocol
65
+
66
+ `1688 checkout confirm` places a real order. It does not pay automatically, but
67
+ it commits the buyer to the seller.
68
+
69
+ Agent protocol:
70
+
71
+ 1. Run `1688 checkout prepare <cartIds...>`.
72
+ 2. Show the full preview: total, items, address, seller, and cart IDs.
73
+ 3. Wait for explicit current-turn approval such as "yes, place it" or
74
+ "下单吧".
75
+ 4. Run `1688 checkout confirm <cartIds...> --agent`.
76
+ 5. Report the final order ID and URL.
77
+
78
+ Never run `--agent` without this prepare plus approval cycle. Never infer
79
+ authorization from older messages.
80
+
81
+ ## Feedback Submission
82
+
83
+ `1688 feedback "<message>"` prepares a GitHub issue URL. That is safe by
84
+ default.
85
+
86
+ `1688 feedback "<message>" --submit` posts publicly through `gh`. Do not add
87
+ `--submit` unless the user explicitly asks to submit/post the issue.
88
+
89
+ ## Update Awareness
90
+
91
+ `1688 doctor --no-launch --json` reports version information. Any JSON-mode
92
+ command may also emit an update notice on stderr.
93
+
94
+ Rules:
95
+
96
+ - In an interactive session, ask once before running the printed global install
97
+ command.
98
+ - In non-interactive loops, do not upgrade automatically.
99
+ - After an approved package update, run `1688 daemon reload`.
@@ -0,0 +1,82 @@
1
+ # Workflow
2
+
3
+ This is the default workflow for AI agents and humans working in this
4
+ repository. Keep it executable and linked to deeper docs.
5
+
6
+ ## Operating Model
7
+
8
+ - Humans set intent, constraints, priorities, and approval boundaries.
9
+ - Agents read the map, choose the smallest coherent slice, implement, verify,
10
+ and update durable docs.
11
+ - `AGENTS.md` is the fast entry point; this file is the default operating loop.
12
+ - Playbooks under `docs/playbooks/` hold repeatable task details.
13
+ - ExecPlans under `docs/exec-plans/` hold long-running state that should
14
+ survive chat history loss.
15
+
16
+ ## Standard Task Brief
17
+
18
+ Capture or infer these fields before changing code:
19
+
20
+ ```md
21
+ Goal:
22
+ Context:
23
+ Constraints:
24
+ Done when:
25
+ ```
26
+
27
+ Ask the human only when the missing choice changes product behavior, checkout
28
+ safety, data retention, account security, or external write actions.
29
+
30
+ ## New Feature Flow
31
+
32
+ 1. Read `AGENTS.md`, `ARCHITECTURE.md`, `docs/README.md`, and the relevant
33
+ product spec or playbook.
34
+ 2. Locate the owning command/session/daemon/io layer.
35
+ 3. For complex work, create or update an ExecPlan in
36
+ `docs/exec-plans/active/`.
37
+ 4. Implement one bounded slice that can be verified independently.
38
+ 5. Add or update deterministic tests near the changed code.
39
+ 6. Update durable docs when command behavior, JSON output, safety rules, or
40
+ recurring workflow guidance changes.
41
+ 7. Run the smallest verification ladder that proves the change, then climb if
42
+ risk increases.
43
+
44
+ ## Bugfix Flow
45
+
46
+ 1. Reproduce or narrow the failure with a test, probe, fixture, saved artifact,
47
+ or captured browser response.
48
+ 2. Locate the smallest owning layer: CLI, command, session, daemon, io, auth,
49
+ or util.
50
+ 3. Fix the root cause with minimal unrelated churn.
51
+ 4. Add a regression test or document why one is not practical.
52
+ 5. Run a focused test first, then `pnpm agent-verify` when the blast radius
53
+ warrants it.
54
+
55
+ ## Verification Ladder
56
+
57
+ 1. Focused checks: a single Vitest file, typecheck, or generated-context run.
58
+ 2. Deterministic test gate: `pnpm test:unit`.
59
+ 3. Agent gate: `pnpm agent-context`, then `pnpm agent-verify`.
60
+ 4. Browser/live checks: `pnpm test` or manual/probe-based verification only
61
+ when the task touches real 1688 browser behavior and the user/session state
62
+ allows it.
63
+
64
+ ## Human Approval Boundaries
65
+
66
+ Ask before doing any of these:
67
+
68
+ - Placing an order or using `checkout confirm --agent`.
69
+ - Logging out or forcing a login reset.
70
+ - Submitting a public GitHub issue with `feedback --submit`.
71
+ - Sending a real seller chat/inquiry unless the user asked for that specific
72
+ message to be sent.
73
+ - Running live/browser actions that can mutate cart, checkout, seller IM, or
74
+ account state.
75
+ - Making a breaking JSON contract change.
76
+
77
+ ## Definition Of Done
78
+
79
+ - The change is implemented in the owning layer.
80
+ - Tests cover the behavior or the reason for no test is recorded.
81
+ - Relevant docs/specs/playbooks/generated indexes are updated.
82
+ - `pnpm agent-verify` passes, or the exact blocker is recorded.
@@ -0,0 +1,9 @@
1
+ # ExecPlans
2
+
3
+ Use this directory for complex or long-running work that should survive chat
4
+ history loss.
5
+
6
+ - Active plans: `active/`
7
+ - Completed plans: `completed/`
8
+ - Non-blocking follow-up work: `tech-debt-tracker.md`
9
+
@@ -0,0 +1,4 @@
1
+ # Active ExecPlans
2
+
3
+ Place in-progress complex work here.
4
+
@@ -0,0 +1,125 @@
1
+ # Plan: Sourcing Research V1
2
+
3
+ ## Goal
4
+
5
+ Deliver a complete first version of sourcing research:
6
+
7
+ - `search` supports research sort/filter flags.
8
+ - `research` runs multi-keyword sourcing research with scoring, dedupe,
9
+ export, and optional top-N enrichment.
10
+ - `compare` compares offer detail pages by sourcing-relevant fields.
11
+ - Docs, JSON contracts, generated indexes, and tests are updated.
12
+
13
+ ## Context
14
+
15
+ - Spec: `docs/specs/sourcing-research.md`
16
+ - Backlog: `docs/FEATURES.md`
17
+ - Existing search command: `src/commands/search.ts`
18
+ - Search payload mapping: `src/session/search-mtop.ts`
19
+ - Offer detail command: `src/commands/offer.ts`
20
+ - CLI routing: `src/cli.ts`
21
+ - Output behavior: `src/io/output.ts`
22
+ - Agent rules: `docs/AGENT_WORKING_PRINCIPLES.md`
23
+
24
+ ## Non-Goals
25
+
26
+ - Do not implement `supplier inspect` until reliable supplier-level payloads
27
+ are identified.
28
+ - Do not scrape every search result detail page by default.
29
+ - Do not change checkout/cart/seller-message behavior.
30
+ - Do not introduce remote writes.
31
+
32
+ ## Design
33
+
34
+ 1. Extend `search` with:
35
+ - `--sort`
36
+ - `--price-min`
37
+ - `--price-max`
38
+ - `--province`
39
+ - `--city`
40
+ - `--verified`
41
+ - `--min-turnover`
42
+ - `--exclude-ads`
43
+
44
+ Search remains one fast read-only command. Filtering and deterministic sort
45
+ happen locally on the collected result set. The search URL may include known
46
+ remote sort values, but local sorting remains the contract.
47
+
48
+ 2. Add shared sourcing helpers:
49
+ - normalize sort/filter options
50
+ - parse turnover/order-count text
51
+ - score offers and offer details
52
+ - format JSONL/CSV exports
53
+
54
+ 3. Add `research`:
55
+ - runs searches sequentially through existing daemon dispatch
56
+ - dedupes by offerId
57
+ - computes score/breakdown
58
+ - optionally enriches top N items through `offer`
59
+ - emits normal JSON/human output or explicit JSONL/CSV
60
+
61
+ 4. Add `compare`:
62
+ - validates offer IDs
63
+ - fetches offer details sequentially
64
+ - returns item-level errors
65
+ - scores and sorts comparable summaries
66
+
67
+ 5. Update docs and generated context.
68
+
69
+ ## Self Review
70
+
71
+ - Risk: `sortType` URL behavior may vary by 1688 page version.
72
+ - Mitigation: keep local deterministic sorting as the public contract.
73
+ - Risk: supplier scores and repurchase rate may not exist in current payloads.
74
+ - Mitigation: include nullable fields and do not claim them as available.
75
+ - Risk: enrichment can trigger more browser/detail-page work.
76
+ - Mitigation: default enrichment to 0; require `--enrich top:N`.
77
+ - Risk: CSV/JSONL could bypass global output flags.
78
+ - Mitigation: explicit `--jsonl`/`--csv` modes only for `research`, with
79
+ validation against simultaneous use.
80
+ - Risk: item-level offer failures could abort useful research output.
81
+ - Mitigation: attach item errors and keep run output when at least one item
82
+ succeeds.
83
+
84
+ ## Milestones
85
+
86
+ - [x] Expand spec and plan.
87
+ - [x] Implement search sort/filter helpers and flags.
88
+ - [x] Implement sourcing helper/scoring/export module.
89
+ - [x] Implement `research`.
90
+ - [x] Implement `compare`.
91
+ - [x] Add focused tests.
92
+ - [x] Update docs/backlog.
93
+ - [x] Run `pnpm agent-verify`.
94
+
95
+ ## Verification
96
+
97
+ ```bash
98
+ pnpm test:unit
99
+ pnpm agent-context
100
+ pnpm agent-verify
101
+ ```
102
+
103
+ ## Decisions
104
+
105
+ - 2026-05-28: Keep `supplier inspect` out of V1 because reliable supplier-level
106
+ payloads are not yet mapped.
107
+ - 2026-05-28: Use local deterministic sorting/filtering as the contract even
108
+ when adding remote sort URL params.
109
+ - 2026-05-28: Enrichment defaults to off; top-N enrichment is explicit.
110
+
111
+ ## Progress Log
112
+
113
+ - 2026-05-28: Created spec and plan. Self-review identified remote sort,
114
+ supplier-score availability, enrichment cost, export-mode validation, and
115
+ item-level failure handling as the main risks.
116
+ - 2026-05-28: Implemented `search` sort/filter controls, shared sourcing
117
+ scoring/export helpers, `research`, `compare`, and focused unit tests.
118
+ - 2026-05-28: Verification passed: `pnpm test:unit` (22 files, 151 tests),
119
+ `pnpm agent-context`, `pnpm agent-verify`, and `pnpm build`.
120
+
121
+ ## Rollback
122
+
123
+ - Remove `research` and `compare` CLI entries and command files.
124
+ - Revert added `search` flags and helper usage.
125
+ - Regenerate agent context.
@@ -0,0 +1,113 @@
1
+ # Plan: Supplier Inspect V1
2
+
3
+ ## Goal
4
+
5
+ Deliver a read-only supplier inspection command backed by real 1688 payloads:
6
+
7
+ - `1688 supplier inspect <offerId|memberId|offerUrl|factoryCardUrl>`
8
+ - offerId path resolves supplier identity from offer detail and shopcard
9
+ - memberId path resolves factory-card data
10
+ - JSON contract and human output are documented
11
+ - loginId-only input is rejected until a deterministic resolver exists
12
+
13
+ ## Context
14
+
15
+ - Spec: `docs/specs/supplier-inspect.md`
16
+ - Existing offer detail extraction: `src/commands/offer.ts`
17
+ - CLI routing: `src/cli.ts`
18
+ - Session dispatch: `src/session/dispatch.ts`
19
+ - Response parsing: `src/session/mtop.ts`
20
+ - Recovery behavior: `src/session/recovery.ts`
21
+ - Sourcing helpers/tests: `src/commands/sourcing-utils.ts`,
22
+ `tests/sourcing-utils.test.ts`
23
+
24
+ ## Non-Goals
25
+
26
+ - Do not add write actions.
27
+ - Do not bulk crawl a supplier catalog.
28
+ - Do not silently resolve loginId by an unreliable URL.
29
+ - Do not change checkout/cart/seller-message behavior.
30
+
31
+ ## Design
32
+
33
+ 1. Add `src/commands/supplier-inspect.ts`.
34
+ - Normalize target into offerId or memberId.
35
+ - Reject loginId-only targets with `BAD_INPUT`.
36
+ - Use `withRecovery` for page-level failures.
37
+
38
+ 2. OfferId path:
39
+ - Open `https://detail.1688.com/offer/<offerId>.html`.
40
+ - Capture `mtop.1688.moga.pc.shopcard`.
41
+ - Read `sellerModel` from `window.context`.
42
+ - If a memberId is found, enrich with factory card.
43
+
44
+ 3. MemberId path:
45
+ - Open `https://sale.1688.com/factory/card.html?memberId=<memberId>`.
46
+ - Capture `mtop.com.alibaba.china.factory.card.common.fn.mtop.tpp.faas`.
47
+ - Parse visible factory-card text for available offer count.
48
+
49
+ 4. Output:
50
+ - Normal human summary lists supplier identity, factory/authentication tags,
51
+ service scores, location, and offer count.
52
+ - JSON output follows the spec and remains nullable/additive.
53
+
54
+ 5. Verification:
55
+ - Add focused unit tests for target normalization and data assembly.
56
+ - Run `pnpm typecheck`, `pnpm test:unit`, `pnpm agent-context`, and
57
+ `pnpm agent-map-check`.
58
+ - Run one live smoke command if session and risk-control state allow.
59
+
60
+ ## Self Review
61
+
62
+ - Risk: factory card endpoint can time out or not fire.
63
+ - Mitigation: return partial supplier identity with a warning when offerId
64
+ data exists but factory-card enrichment fails.
65
+ - Risk: service score key names are not self-explanatory.
66
+ - Mitigation: keep raw keys and add best-effort labels.
67
+ - Risk: loginId direct lookup may return the wrong supplier.
68
+ - Mitigation: reject loginId-only input and document the limitation.
69
+ - Risk: available offer count only appears in rendered text.
70
+ - Mitigation: mark source as `factory-card-dom` and keep nullable.
71
+
72
+ ## Milestones
73
+
74
+ - [x] Write spec and plan.
75
+ - [x] Implement command, parser, and CLI routing.
76
+ - [x] Add focused tests.
77
+ - [x] Update README, command catalog, JSON contracts, and feature backlog.
78
+ - [x] Regenerate agent context.
79
+ - [x] Run verification.
80
+
81
+ ## Verification
82
+
83
+ ```bash
84
+ pnpm typecheck
85
+ pnpm test:unit
86
+ pnpm agent-context
87
+ pnpm agent-map-check
88
+ pnpm dev supplier inspect 628196518518 --json --pretty
89
+ ```
90
+
91
+ Passed on 2026-05-31:
92
+
93
+ - `pnpm dev supplier inspect 628196518518 --json --pretty`
94
+ - `pnpm typecheck`
95
+ - `pnpm test:unit`
96
+ - `pnpm docs-check`
97
+ - `pnpm agent-map-check`
98
+ - `pnpm agent-verify`
99
+
100
+ ## Progress Log
101
+
102
+ - 2026-05-31: Live headed probe identified reliable offer `sellerModel`,
103
+ shopcard, and factory-card payloads. Direct loginId lookup was rejected after
104
+ probe showed it can resolve to the wrong factory.
105
+ - 2026-05-31: Implemented `supplier inspect`, CLI routing, dispatch registry,
106
+ parser helpers, focused tests, docs, generated agent context, and live smoke
107
+ verification.
108
+
109
+ ## Rollback
110
+
111
+ - Remove `supplier inspect` CLI entry and command file.
112
+ - Remove tests and docs sections.
113
+ - Regenerate agent context.
@@ -0,0 +1,81 @@
1
+ # Supplier Search V1
2
+
3
+ ## Goal
4
+
5
+ Deliver supplier discovery and research backed by real 1688 company search:
6
+
7
+ - `1688 supplier search <keyword...>`
8
+ - `1688 supplier research <keyword...>`
9
+ - source must be `companySearchBusinessService`
10
+ - source must not be offer-result supplier aggregation
11
+ - optional top-N enrichment through `supplier inspect`
12
+
13
+ ## Context Read
14
+
15
+ - Agent principles: `docs/AGENT_WORKING_PRINCIPLES.md`
16
+ - Sourcing spec: `docs/specs/sourcing-research.md`
17
+ - Supplier inspect spec: `docs/specs/supplier-inspect.md`
18
+ - New spec: `docs/specs/supplier-search.md`
19
+ - Existing search/capture patterns: `src/commands/search.ts`,
20
+ `src/session/search-capture.ts`
21
+
22
+ ## Live Probe Findings
23
+
24
+ - Company search page:
25
+ `https://s.1688.com/company/company_search.htm?keywords=<GBK>`
26
+ - `s.1688.com` keywords must be GBK percent-encoded. UTF-8 encoding produced
27
+ mojibake/zero-result behavior.
28
+ - Business endpoint:
29
+ `search.1688.com/service/companySearchBusinessService`
30
+ - Payload path:
31
+ `data.data.companyWithOfferLists`
32
+ - Sample async response returned 14 suppliers with `pageCount=50` and
33
+ `docsReturn=14`.
34
+ - The async URL used `startIndex=6&asyncCount=14`, so V1 records a known
35
+ completeness boundary: stable service parsing first, optional SSR/DOM card
36
+ parsing later if exact first-page completeness is needed.
37
+
38
+ ## Implementation
39
+
40
+ 1. Add shared GBK percent encoder in `src/util/encoding.ts`.
41
+ 2. Reuse the encoder in product search URL construction.
42
+ 3. Add `src/session/supplier-search.ts`:
43
+ - request meta reader for `companySearchBusinessService`
44
+ - service payload parser
45
+ - supplier/offer-preview mapper
46
+ - response capture with `keep: "largest"` and settle window
47
+ 4. Add `src/commands/supplier-search.ts`:
48
+ - `supplier search`
49
+ - `supplier research`
50
+ - scoring, filters, JSONL/CSV exports
51
+ - optional enrich through `supplier inspect`
52
+ 5. Add CLI and dispatch registry wiring.
53
+ 6. Add deterministic unit tests.
54
+ 7. Update README, command catalog, JSON contracts, feature backlog, and specs.
55
+ 8. Regenerate agent indexes.
56
+
57
+ ## Decisions
58
+
59
+ - Keep source provenance explicit in JSON:
60
+ `source.offerAggregation=false`.
61
+ - `supplier search` defaults to `--enrich 0`.
62
+ - `supplier research` defaults to `--enrich top:10`.
63
+ - Rate filters accept both fractions and percentages (`0.4` or `40`).
64
+ - Enrichment requires `memberId`; missing memberId is an item-level error.
65
+ - Do not use direct unauthenticated fetch for company service because it can
66
+ trigger `x5` interstitials; use browser-emitted responses.
67
+
68
+ ## Verification
69
+
70
+ - `pnpm typecheck`
71
+ - `pnpm test:unit`
72
+ - `pnpm agent-context`
73
+ - `pnpm agent-verify`
74
+
75
+ ## Rollback
76
+
77
+ - Remove supplier search/research CLI entries.
78
+ - Remove dispatch registry entry `supplier-search`.
79
+ - Remove `src/commands/supplier-search.ts`.
80
+ - Remove `src/session/supplier-search.ts`.
81
+ - Revert README/docs/spec/test/index updates.
@@ -0,0 +1,138 @@
1
+ # Plan: Windows CLI Compatibility
2
+
3
+ ## Goal
4
+
5
+ Deliver the Windows compatibility baseline from
6
+ `docs/specs/windows-cli-compatibility.md`: Windows-safe build/install scripts,
7
+ daemon named pipe isolation, platform-aware diagnostics, Windows-ready docs,
8
+ and deterministic verification.
9
+
10
+ ## Context
11
+
12
+ - Source spec: `docs/specs/windows-cli-compatibility.md`
13
+ - Agent map: `AGENTS.md`
14
+ - Workflow: `docs/WORKFLOW.md`
15
+ - CLI/package surfaces: `package.json`, `scripts/postinstall.mjs`, `src/cli.ts`
16
+ - Path/daemon surfaces: `src/session/paths.ts`, `src/daemon/*`
17
+ - Diagnostic surface: `src/commands/doctor.ts`
18
+ - User docs: `README.md`, `docs/COMMANDS.md`
19
+ - Generated indexes: `docs/generated/*`
20
+
21
+ Existing behavior already has partial Windows support: daemon IPC uses a
22
+ named pipe on `win32`, postinstall checks common Windows Chrome paths, and
23
+ most runtime paths use `path.join`. Known gaps are shell `chmod` in
24
+ `package.json`, a fixed global named pipe, Unix-only doctor hints, Unix-only
25
+ README examples, and no deterministic Windows-specific tests.
26
+
27
+ ## Non-goals
28
+
29
+ - Do not change 1688 login/risk-control behavior.
30
+ - Do not add a native Windows service, installer, or packaged executable.
31
+ - Do not add live Windows 1688 network checks to deterministic tests.
32
+ - Do not change existing command JSON shapes except additive diagnostics if
33
+ needed.
34
+
35
+ ## Design
36
+
37
+ - Replace shell `chmod` with a Node script that sets executable mode only on
38
+ Unix-like platforms.
39
+ - Make Windows named pipe paths stable per root by hashing `root()`.
40
+ - Keep Unix socket paths unchanged.
41
+ - Centralize platform-specific diagnostic hint strings in `doctor`.
42
+ - Make postinstall resolve its pid file through `BB1688_HOME` and run
43
+ `npx.cmd` on Windows.
44
+ - Use `os.tmpdir()` for production debug/probe output helpers that currently
45
+ write hard-coded `/tmp` paths.
46
+ - Update README and command docs with PowerShell-safe examples while keeping
47
+ Unix examples for shell users.
48
+ - Add deterministic tests that simulate Windows behavior without requiring a
49
+ Windows host by exposing pure helper functions.
50
+
51
+ ## Checklist
52
+
53
+ Spec and plan foundation:
54
+
55
+ - [x] Create Windows CLI compatibility spec.
56
+ - [x] Create active ExecPlan.
57
+
58
+ Implementation:
59
+
60
+ - [x] Add cross-platform bin-mode script and replace `chmod` build command.
61
+ - [x] Make Windows daemon named pipe unique per `BB1688_HOME` root.
62
+ - [x] Make postinstall daemon pid lookup, npx invocation, and retry hint
63
+ platform-aware.
64
+ - [x] Make doctor fix hints platform-aware.
65
+ - [x] Replace production hard-coded `/tmp` debug dump paths with `os.tmpdir()`.
66
+ - [x] Add deterministic tests for Windows path/doctor/build helpers.
67
+
68
+ Docs and maps:
69
+
70
+ - [x] Update README Windows command-line guidance.
71
+ - [x] Update `docs/COMMANDS.md` Windows examples.
72
+ - [x] Run `pnpm agent-context` after command/doc/test layout changes.
73
+
74
+ Verification:
75
+
76
+ - [x] Run focused Windows compatibility tests.
77
+ - [x] Run `pnpm build`.
78
+ - [x] Run `pnpm test:unit`.
79
+ - [x] Run `pnpm agent-verify`.
80
+ - [x] Run `npm pack --dry-run`.
81
+
82
+ ## Verification
83
+
84
+ Focused:
85
+
86
+ ```bash
87
+ pnpm exec vitest run tests/paths.test.ts tests/doctor.test.ts tests/fix-bin-mode.test.ts
88
+ ```
89
+
90
+ Package and project:
91
+
92
+ ```bash
93
+ pnpm build
94
+ pnpm test:unit
95
+ pnpm agent-context
96
+ pnpm agent-verify
97
+ npm pack --dry-run
98
+ ```
99
+
100
+ Manual Windows smoke when a Windows machine is available:
101
+
102
+ ```powershell
103
+ npm i -g 1688-cli
104
+ 1688 --version
105
+ 1688 doctor --no-launch --json
106
+ 1688 daemon start
107
+ 1688 daemon status --json
108
+ 1688 daemon stop
109
+ 1688 search 雨伞 --max 1 --json
110
+ 1688 supplier search 键盘 --max 1 --json
111
+ ```
112
+
113
+ ## Decisions
114
+
115
+ - 2026-06-07: Treat Windows support as a deterministic packaging/runtime
116
+ compatibility baseline, not a guarantee that live 1688 network calls pass in
117
+ CI without a logged-in account.
118
+ - 2026-06-07: Use `BB1688_HOME` root hashing for Windows named pipes so
119
+ tests and users with different homes do not collide.
120
+
121
+ ## Progress Log
122
+
123
+ - 2026-06-07: Created spec and active plan from user request.
124
+ - 2026-06-07: Implemented the Windows compatibility baseline: Node-based bin
125
+ mode fixing, root-hashed Windows daemon named pipes, platform-aware
126
+ postinstall and doctor hints, `os.tmpdir()` debug paths, PowerShell docs, and
127
+ deterministic helper tests.
128
+ - 2026-06-07: Verified with focused Windows compatibility tests, `pnpm build`,
129
+ `pnpm test:unit`, `pnpm agent-context`, `pnpm agent-verify`, and
130
+ `npm pack --dry-run`. Manual Windows smoke remains documented for a real
131
+ Windows session.
132
+
133
+ ## Rollback
134
+
135
+ - Restore `package.json` build script to its previous `chmod` form.
136
+ - Restore `socketPath()` to the fixed Windows pipe.
137
+ - Revert postinstall, doctor, docs, and tests added by this plan.
138
+ - Run `pnpm agent-context` after rollback if generated indexes changed.