maxc-cli 0.4.5__tar.gz → 0.4.7__tar.gz

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 (95) hide show
  1. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/PKG-INFO +4 -6
  2. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/README.md +3 -5
  3. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/setup.py +1 -1
  4. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/__init__.py +1 -1
  5. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/app.py +98 -30
  6. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/backend/catalog.py +4 -1
  7. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/backend/data.py +15 -6
  8. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/cli.py +2 -2
  9. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/output.py +50 -0
  10. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/SKILL.md +7 -6
  11. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/bootstrap-auth.md +36 -16
  12. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/bootstrap-flow.md +4 -2
  13. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/command-patterns.md +1 -1
  14. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli.egg-info/PKG-INFO +4 -6
  15. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_agent_hints_and_cli.py +7 -1
  16. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_backend_data_serialization.py +1 -1
  17. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_cli_mock.py +296 -0
  18. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_integration_real.py +1 -1
  19. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_phase1_improvements.py +40 -0
  20. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/MANIFEST.in +0 -0
  21. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/pyproject.toml +0 -0
  22. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/scripts/pyinstaller_entry.py +0 -0
  23. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/scripts/regression_test.py +0 -0
  24. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/setup.cfg +0 -0
  25. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/__main__.py +0 -0
  26. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/_samples.py +0 -0
  27. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/agent_platforms.py +0 -0
  28. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/audit.py +0 -0
  29. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/auth_providers.py +0 -0
  30. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/backend/__init__.py +0 -0
  31. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/backend/auth.py +0 -0
  32. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/backend/job.py +0 -0
  33. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/backend/meta.py +0 -0
  34. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/backend/odps.py +0 -0
  35. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/backend/query.py +0 -0
  36. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/cache.py +0 -0
  37. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/catalog_bootstrap.py +0 -0
  38. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/config.py +0 -0
  39. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/exceptions.py +0 -0
  40. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/help_format.py +0 -0
  41. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/helpers.py +0 -0
  42. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/masking.py +0 -0
  43. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/models.py +0 -0
  44. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/setting_parser.py +0 -0
  45. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/agents/openai.yaml +0 -0
  46. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/json-output-format.md +0 -0
  47. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/maxcompute-select-guide.md +0 -0
  48. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/maxcompute-sql-notes.md +0 -0
  49. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/partition-guide.md +0 -0
  50. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/red-lines.md +0 -0
  51. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/setup-install.md +0 -0
  52. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/sql-common-errors.md +0 -0
  53. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/sql-query-patterns.md +0 -0
  54. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/skills/references/text2sql-principles.md +0 -0
  55. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/store.py +0 -0
  56. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli/utils.py +0 -0
  57. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli.egg-info/SOURCES.txt +0 -0
  58. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli.egg-info/dependency_links.txt +0 -0
  59. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli.egg-info/entry_points.txt +0 -0
  60. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli.egg-info/requires.txt +0 -0
  61. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/src/maxc_cli.egg-info/top_level.txt +0 -0
  62. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_agent_platforms.py +0 -0
  63. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_agent_skill_commands.py +0 -0
  64. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_agent_skill_commands_context.py +0 -0
  65. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_backend_data.py +0 -0
  66. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_backend_meta.py +0 -0
  67. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_build_release_script.py +0 -0
  68. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_cache.py +0 -0
  69. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_catalog.py +0 -0
  70. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_catalog_bootstrap.py +0 -0
  71. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_cli_arg_validation.py +0 -0
  72. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_cli_query_parse_and_sanitize.py +0 -0
  73. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_compat.py +0 -0
  74. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_e2e_smoke.py +0 -0
  75. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_envelope_shape.py +0 -0
  76. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_error_self_correction.py +0 -0
  77. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_error_translation.py +0 -0
  78. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_exit_codes.py +0 -0
  79. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_external_auth.py +0 -0
  80. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_flag_hoist.py +0 -0
  81. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_help_format.py +0 -0
  82. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_help_version_e2e.py +0 -0
  83. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_helpers.py +0 -0
  84. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_helpers_csv.py +0 -0
  85. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_integration.py +0 -0
  86. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_job_improvements.py +0 -0
  87. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_masking.py +0 -0
  88. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_meta_schema_and_partition_cols.py +0 -0
  89. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_pyinstaller_bundle.py +0 -0
  90. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_query_auto_promote.py +0 -0
  91. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_query_result_csv_fallback.py +0 -0
  92. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_setting_parser.py +0 -0
  93. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_skill_cli_consistency.py +0 -0
  94. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_skill_eval.py +0 -0
  95. {maxc_cli-0.4.5 → maxc_cli-0.4.7}/tests/test_skill_renderer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxc-cli
3
- Version: 0.4.5
3
+ Version: 0.4.7
4
4
  Summary: Agent-native MaxCompute CLI for external coding agents
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.9
@@ -61,7 +61,7 @@ maxc query "SELECT * FROM schema.table WHERE ds='20260415'" --json
61
61
  | **cache** | `build`, `build-status`, `status`, `clear` | 元数据缓存管理 |
62
62
  | **agent** | `context`, `skill install`, `skill list` | Agent 集成与 SKILL 安装 |
63
63
 
64
- 所有命令支持 `--json` 输出 Envelope v2.0 结构化响应。支持 `--format json|markdown|brief`(全局标志)。
64
+ 所有命令支持 `--json` 输出 Envelope v2.0 结构化响应。对 Agent 而言,应始终使用 `--json`。
65
65
 
66
66
  ## Agent 集成
67
67
 
@@ -128,12 +128,10 @@ maxc agent skill --json # SKILL.md 路径与 min_cli_version
128
128
 
129
129
  ### 输出格式
130
130
 
131
- `--format` 是全局标志,适用于所有命令:
131
+ 对 Agent,统一使用 `--json`:
132
132
 
133
133
  ```bash
134
- maxc --format json meta describe my_table # 结构化 JSON(默认,等价于 --json
135
- maxc --format markdown meta describe my_table # 人类可读 markdown
136
- maxc --format brief meta describe my_table # 最小化单行输出(低 token 场景)
134
+ maxc meta describe my_table --json
137
135
  ```
138
136
 
139
137
  ### safety 块
@@ -39,7 +39,7 @@ maxc query "SELECT * FROM schema.table WHERE ds='20260415'" --json
39
39
  | **cache** | `build`, `build-status`, `status`, `clear` | 元数据缓存管理 |
40
40
  | **agent** | `context`, `skill install`, `skill list` | Agent 集成与 SKILL 安装 |
41
41
 
42
- 所有命令支持 `--json` 输出 Envelope v2.0 结构化响应。支持 `--format json|markdown|brief`(全局标志)。
42
+ 所有命令支持 `--json` 输出 Envelope v2.0 结构化响应。对 Agent 而言,应始终使用 `--json`。
43
43
 
44
44
  ## Agent 集成
45
45
 
@@ -106,12 +106,10 @@ maxc agent skill --json # SKILL.md 路径与 min_cli_version
106
106
 
107
107
  ### 输出格式
108
108
 
109
- `--format` 是全局标志,适用于所有命令:
109
+ 对 Agent,统一使用 `--json`:
110
110
 
111
111
  ```bash
112
- maxc --format json meta describe my_table # 结构化 JSON(默认,等价于 --json
113
- maxc --format markdown meta describe my_table # 人类可读 markdown
114
- maxc --format brief meta describe my_table # 最小化单行输出(低 token 场景)
112
+ maxc meta describe my_table --json
115
113
  ```
116
114
 
117
115
  ### safety 块
@@ -9,7 +9,7 @@ README = ROOT / "README.md"
9
9
 
10
10
  setup(
11
11
  name="maxc-cli",
12
- version="0.4.5",
12
+ version="0.4.7",
13
13
  description="Agent-native MaxCompute CLI for external coding agents",
14
14
  long_description=README.read_text(encoding="utf-8"),
15
15
  long_description_content_type="text/markdown",
@@ -2,4 +2,4 @@
2
2
 
3
3
  __all__ = ["__version__"]
4
4
 
5
- __version__ = "0.4.5"
5
+ __version__ = "0.4.7"
@@ -126,6 +126,12 @@ class _PickerInputs:
126
126
  reselect: 'bool' = False
127
127
 
128
128
 
129
+ class ProjectPickerPending(Exception):
130
+ """Raised when non-TTY auth login can list projects but needs the caller to pick one."""
131
+ def __init__(self, projects: list):
132
+ self.projects = projects
133
+
134
+
129
135
  class MaxCApp:
130
136
  def __init__(
131
137
  self,
@@ -1262,7 +1268,7 @@ class MaxCApp:
1262
1268
 
1263
1269
  if use_catalog and self.backend is not None:
1264
1270
  catalog_matches = self.backend.catalog_search_tables(
1265
- keyword, schema=effective_schema,
1271
+ keyword, schema=effective_schema, project=project,
1266
1272
  )
1267
1273
  if catalog_matches is not None:
1268
1274
  matches = catalog_matches
@@ -1735,7 +1741,7 @@ class MaxCApp:
1735
1741
  }
1736
1742
  )
1737
1743
 
1738
- all_tables, _ = self.backend.list_tables(schema=schema_name)
1744
+ all_tables, _ = self.backend.list_tables(schema=schema_name, project=target_project)
1739
1745
  tables = all_tables
1740
1746
 
1741
1747
  if progress_callback is not None:
@@ -1830,13 +1836,16 @@ class MaxCApp:
1830
1836
  }
1831
1837
  )
1832
1838
 
1839
+ write_schema = schema_name or "default"
1840
+
1833
1841
  def fetch_and_cache(
1834
1842
  table_name: 'str',
1835
- table_schema: 'str' = "default",
1836
1843
  ) -> 'tuple[str, str | None]':
1837
1844
  try:
1838
- full_table = self.backend.describe_table(table_name)
1839
- existing = self.cache.get_cached_table(project, full_table.name, table_schema)
1845
+ full_table = self.backend.describe_table(
1846
+ table_name, project=project, schema=schema_name,
1847
+ )
1848
+ existing = self.cache.get_cached_table(project, full_table.name, write_schema)
1840
1849
  columns = [
1841
1850
  {"name": c.name, "type": c.type, "comment": c.comment}
1842
1851
  for c in full_table.columns
@@ -1847,7 +1856,7 @@ class MaxCApp:
1847
1856
  description=full_table.description,
1848
1857
  columns=columns,
1849
1858
  partitions=full_table.partitions,
1850
- schema_name=table_schema,
1859
+ schema_name=write_schema,
1851
1860
  )
1852
1861
  return ("updated" if existing else "created"), None
1853
1862
  except Exception as exc:
@@ -2615,29 +2624,63 @@ class MaxCApp:
2615
2624
 
2616
2625
  # Project / endpoint / region / tunnel — try the interactive Catalog
2617
2626
  # picker when the user did not pin a project explicitly.
2618
- (
2619
- picked_project,
2620
- derived_endpoint,
2621
- derived_region,
2622
- derived_tunnel,
2623
- picker_warnings,
2624
- ) = self._resolve_project_via_picker(
2625
- _PickerInputs(
2626
- provided_project=project,
2627
- provided_endpoint=endpoint,
2628
- provided_region=region_name,
2629
- provided_tunnel=tunnel_endpoint,
2630
- access_id=resolved_access_id,
2631
- secret=resolved_secret,
2632
- security_token=resolved_token,
2633
- catalog_endpoint=catalog_endpoint,
2634
- no_picker=no_picker,
2635
- from_env=from_env,
2636
- env_settings=env_settings,
2637
- existing_auth=existing_auth,
2638
- reselect=reselect,
2627
+ try:
2628
+ (
2629
+ picked_project,
2630
+ derived_endpoint,
2631
+ derived_region,
2632
+ derived_tunnel,
2633
+ picker_warnings,
2634
+ ) = self._resolve_project_via_picker(
2635
+ _PickerInputs(
2636
+ provided_project=project,
2637
+ provided_endpoint=endpoint,
2638
+ provided_region=region_name,
2639
+ provided_tunnel=tunnel_endpoint,
2640
+ access_id=resolved_access_id,
2641
+ secret=resolved_secret,
2642
+ security_token=resolved_token,
2643
+ catalog_endpoint=catalog_endpoint,
2644
+ no_picker=no_picker,
2645
+ from_env=from_env,
2646
+ env_settings=env_settings,
2647
+ existing_auth=existing_auth,
2648
+ reselect=reselect,
2649
+ )
2650
+ )
2651
+ except ProjectPickerPending as exc:
2652
+ projects_data = [
2653
+ {
2654
+ "project_id": p.project_id,
2655
+ "region": p.region,
2656
+ "endpoint": _catalog_bootstrap.region_to_endpoint(p.region),
2657
+ "owner": p.owner,
2658
+ "schema_enabled": p.schema_enabled,
2659
+ "description": p.description,
2660
+ }
2661
+ for p in exc.projects
2662
+ ]
2663
+ return Envelope(
2664
+ command="auth.login",
2665
+ status="pending",
2666
+ data={
2667
+ "reason": "project_selection_required",
2668
+ "projects": projects_data,
2669
+ "count": len(projects_data),
2670
+ },
2671
+ agent_hints=AgentHints(
2672
+ actions=[
2673
+ SuggestedAction(
2674
+ id="auth.login",
2675
+ title="Complete login with selected project",
2676
+ command="maxc auth login --project <project_id> --json",
2677
+ executable=False,
2678
+ placeholders={"project_id": "<project_id>"},
2679
+ ),
2680
+ ],
2681
+ warnings=[],
2682
+ ),
2639
2683
  )
2640
- )
2641
2684
 
2642
2685
  resolved_auth = AuthConfig(
2643
2686
  access_id=resolved_access_id,
@@ -3086,8 +3129,30 @@ class MaxCApp:
3086
3129
  [],
3087
3130
  )
3088
3131
 
3089
- # 2. Picker not viable → today's behavior (prompt or fail).
3132
+ # 2. Picker not viable (non-TTY or --no-picker).
3090
3133
  if inputs.no_picker or not sys.stdin.isatty():
3134
+ # Non-TTY + picker not disabled: list projects for structured output
3135
+ catalog_warning: str | None = None
3136
+ if not inputs.no_picker and not from_env:
3137
+ try:
3138
+ bootstrap_odps = _catalog_bootstrap.build_bootstrap_odps(
3139
+ access_id=inputs.access_id,
3140
+ secret_access_key=inputs.secret,
3141
+ security_token=inputs.security_token,
3142
+ endpoint=inputs.catalog_endpoint or provided_endpoint,
3143
+ )
3144
+ projects = _catalog_bootstrap.list_all_projects(bootstrap_odps)
3145
+ if projects:
3146
+ raise ProjectPickerPending(projects)
3147
+ except ProjectPickerPending:
3148
+ raise
3149
+ except Exception as exc:
3150
+ catalog_warning = (
3151
+ f"Could not list projects via Catalog API "
3152
+ f"({type(exc).__name__}: {exc}). "
3153
+ f"Falling back to saved/env config."
3154
+ )
3155
+
3091
3156
  prompted = self._resolve_login_value(
3092
3157
  provided=None,
3093
3158
  env_value=env_settings.get("project"),
@@ -3097,12 +3162,15 @@ class MaxCApp:
3097
3162
  secret=False,
3098
3163
  use_env=from_env,
3099
3164
  )
3165
+ warnings_out: list[str] = []
3166
+ if catalog_warning:
3167
+ warnings_out.append(catalog_warning)
3100
3168
  return (
3101
3169
  prompted,
3102
3170
  provided_endpoint,
3103
3171
  provided_region,
3104
3172
  provided_tunnel,
3105
- [],
3173
+ warnings_out,
3106
3174
  )
3107
3175
 
3108
3176
  # 3. Try the catalog picker.
@@ -192,6 +192,7 @@ class CatalogMixin:
192
192
  keyword: str,
193
193
  *,
194
194
  schema: 'str | None' = None,
195
+ project: 'str | None' = None,
195
196
  page_size: int = 50,
196
197
  ) -> 'list[dict[str, Any]] | None':
197
198
  """Search tables via Catalog API server-side full-text search.
@@ -199,6 +200,8 @@ class CatalogMixin:
199
200
  Args:
200
201
  keyword: Search term — matched against table name (substring).
201
202
  schema: Optional schema to scope the search.
203
+ project: Optional project to scope the search; default = config's
204
+ default_project.
202
205
  page_size: Results per page (max 100).
203
206
 
204
207
  Returns:
@@ -225,7 +228,7 @@ class CatalogMixin:
225
228
  # type=TABLE — required filter
226
229
  # project={proj} — scope to project
227
230
  parts = ["type=TABLE"]
228
- project = self.config.default_project
231
+ project = project or self.config.default_project
229
232
  if project:
230
233
  parts.append(f"project={project}")
231
234
  if keyword:
@@ -38,18 +38,27 @@ def _serialize_value(value: 'Any') -> 'Any':
38
38
  class DataMixin:
39
39
  """Mixin providing data sampling and profiling methods."""
40
40
 
41
- def _table_tunnel(self):
42
- """Return a TableTunnel for the current ODPS client.
41
+ def _table_tunnel(self, project: 'str | None' = None):
42
+ """Return a TableTunnel bound to ``project`` (or the client default).
43
43
 
44
44
  Real PyODPS `ODPS` instances do not expose a `.tunnel` attribute,
45
45
  so we construct `odps.tunnel.TableTunnel(odps=self.client)` lazily.
46
- Test doubles (FakeODPS) DO expose `.tunnel` directly honor that
47
- so existing FakeTunnel infrastructure keeps working.
46
+ The tunnel resolves tables against its own project, so a cross-project
47
+ download/upload (e.g. `--project other_proj`) MUST construct the tunnel
48
+ with that project — `create_*_session()` takes no project argument.
49
+
50
+ Test doubles (FakeODPS) DO expose `.tunnel` directly — honor that so
51
+ existing FakeTunnel infrastructure keeps working, and surface the
52
+ requested project on the instance for assertions.
48
53
  """
49
54
  existing = getattr(self.client, "tunnel", None)
50
55
  if existing is not None:
56
+ if project is not None:
57
+ existing.requested_project = project
51
58
  return existing
52
59
  from odps.tunnel import TableTunnel
60
+ if project:
61
+ return TableTunnel(odps=self.client, project=project)
53
62
  return TableTunnel(odps=self.client)
54
63
 
55
64
  def _resolve_partition_for_sample(
@@ -340,7 +349,7 @@ class DataMixin:
340
349
  create_session_kwargs["create_partition"] = True
341
350
  if schema:
342
351
  create_session_kwargs["schema"] = schema
343
- upload_session = self._table_tunnel().create_upload_session(
352
+ upload_session = self._table_tunnel(project=project or self.project).create_upload_session(
344
353
  definition.name, **create_session_kwargs,
345
354
  )
346
355
 
@@ -491,7 +500,7 @@ class DataMixin:
491
500
  download_kwargs: dict[str, Any] = {"partition_spec": partition}
492
501
  if schema:
493
502
  download_kwargs["schema"] = schema
494
- session = self._table_tunnel().create_download_session(
503
+ session = self._table_tunnel(project=project or self.project).create_download_session(
495
504
  definition.name, **download_kwargs,
496
505
  )
497
506
  total = session.count
@@ -1667,7 +1667,7 @@ def _handle_cache_build(app: MaxCApp, args: argparse.Namespace, stdout: TextIO)
1667
1667
  stdout.write("Fetching table list...\n")
1668
1668
  stdout.flush()
1669
1669
 
1670
- tables, _ = app.backend.list_tables()
1670
+ tables, _ = app.backend.list_tables(project=target_project, schema=schema_name)
1671
1671
  total = len(tables)
1672
1672
 
1673
1673
  if total == 0:
@@ -1698,7 +1698,7 @@ def _handle_cache_build(app: MaxCApp, args: argparse.Namespace, stdout: TextIO)
1698
1698
  def _do_fetch():
1699
1699
  # Use a simpler approach: only get table metadata without sample rows
1700
1700
  # to avoid potential hangs on table.head() or iterate_partitions()
1701
- table = app.backend._get_table(table_name)
1701
+ table = app.backend._get_table(table_name, project=target_project, schema=schema_name)
1702
1702
  # Force reload to get full schema info
1703
1703
  if hasattr(table, 'reload'):
1704
1704
  table.reload()
@@ -84,6 +84,42 @@ def _stringify(value: Any) -> str:
84
84
  # ---------------------------------------------------------------------------
85
85
 
86
86
 
87
+ def _render_pending_md(envelope: Envelope) -> str:
88
+ """Render a pending/async envelope so the user sees status and how to wait."""
89
+ parts: list[str] = ["## Pending", ""]
90
+ parts.append("The query has not finished yet — it is still running asynchronously.")
91
+ parts.append("")
92
+
93
+ data = envelope.data or {}
94
+ metadata = envelope.metadata or {}
95
+ kv: dict[str, Any] = {}
96
+ job_id = data.get("job_id") or metadata.get("job_id")
97
+ if job_id:
98
+ kv["Job ID"] = job_id
99
+ if metadata.get("project"):
100
+ kv["Project"] = metadata["project"]
101
+ if metadata.get("wait_seconds") is not None:
102
+ kv["Waited"] = f"{metadata['wait_seconds']}s"
103
+ if metadata.get("logview"):
104
+ kv["Logview"] = metadata["logview"]
105
+ if kv:
106
+ parts.append(render_key_values(kv))
107
+ parts.append("")
108
+
109
+ parts.append("Wait for it to complete with:")
110
+ parts.append("")
111
+ hints = envelope.agent_hints
112
+ if hints is None or not hints.actions:
113
+ if job_id:
114
+ parts.append(f"- `maxc job wait {job_id} --json`")
115
+ parts.append(f"- `maxc job status {job_id} --json`")
116
+ else:
117
+ parts.append("- `maxc job wait <job_id> --json`")
118
+ parts.append("")
119
+ return "\n".join(parts)
120
+ return _append_agent_hints_md(parts, envelope)
121
+
122
+
87
123
  def render_markdown(envelope: Envelope) -> str:
88
124
  """Render an Envelope as human-readable markdown."""
89
125
  parts: list[str] = []
@@ -100,6 +136,10 @@ def render_markdown(envelope: Envelope) -> str:
100
136
  parts.append("")
101
137
  return _append_agent_hints_md(parts, envelope)
102
138
 
139
+ # --- Pending / async envelopes --------------------------------------
140
+ if envelope.status == "pending":
141
+ return _render_pending_md(envelope)
142
+
103
143
  command = envelope.command
104
144
  data = envelope.data
105
145
  metadata = envelope.metadata or {}
@@ -249,6 +289,16 @@ def render_brief(envelope: Envelope) -> str:
249
289
 
250
290
  data = envelope.data
251
291
 
292
+ # --- pending / async ------------------------------------------------
293
+ if envelope.status == "pending":
294
+ job_id = data.get("job_id") or (envelope.metadata or {}).get("job_id") or "?"
295
+ line = f"{command} | pending | job {job_id}"
296
+ if next_cmd:
297
+ line += f" | next: {next_cmd}"
298
+ elif job_id != "?":
299
+ line += f" | next: maxc job wait {job_id} --json"
300
+ return line
301
+
252
302
  # --- query ----------------------------------------------------------
253
303
  if envelope.command in {"query", "job.wait", "job.result"}:
254
304
  total = data.get("total_rows", "?")
@@ -40,7 +40,7 @@ in SKILL.md alone.
40
40
 
41
41
  These are non-negotiable. See [references/red-lines.md](references/red-lines.md) for the full list including common mistakes, anti-patterns, and error recovery.
42
42
 
43
- 1. **Always use `--json`** for machine work. Use `--format markdown` for user-facing output, `--format brief` in token-tight contexts. `--json` is shorthand for `--format json`. **`--format` is a top-level flag — it must come before the subcommand**: `{{cli}} --format markdown query "SELECT 1"` (✓), not `{{cli}} query "SELECT 1" --format markdown` (✗). `--json` may appear anywhere because each subcommand also accepts it.
43
+ 1. **Always use `--json`**. Agents should use JSON output consistently.
44
44
  2. **Never invent names** — table, schema, project, or endpoint. Verify with `meta` commands and `auth whoami`.
45
45
  3. **Default to `--project` for the user's target project.** The configured project (in `~/.maxc/config.yaml`) is the user's **dev project** — the data they actually want to query usually lives in a *different* project (often the corresponding production one). When the user mentions a table/project without specifying which environment, **ask first**, then pass `--project <name>` on every meta/data command and use `project.table` in SQL.
46
46
  4. **Project naming convention is a fixed pair:** `<name>_dev` is the dev project; the same `<name>` **without** the `_dev` suffix is its corresponding **production** project. Together they form one DataWorks workspace. They share metadata structure but hold different data and different permissions. See Dev vs Production Projects below.
@@ -52,10 +52,11 @@ These are non-negotiable. See [references/red-lines.md](references/red-lines.md)
52
52
 
53
53
  ## Bootstrap Flow
54
54
 
55
- When `auth whoami --json` returns `configured=false` (no auth set up), follow [references/bootstrap-flow.md](references/bootstrap-flow.md) step by step. Three principles:
55
+ When `auth whoami --json` returns `configured=false` (no auth set up), follow [references/bootstrap-flow.md](references/bootstrap-flow.md) step by step. Key principles:
56
56
 
57
57
  1. **Never pick the auth method yourself** — always ask the user to choose between AK/SK and environment variables.
58
58
  2. **If `auth whoami` shows `auth_type=external`, the user is on an externally-managed credential provider — do NOT modify the auth config.** Treat the bootstrap as already done. Only `project`/`endpoint`/`schema` are safe to change (via `session set` or by re-running `auth login-external` with the same `--process-command`).
59
+ 3. **For AK/SK login, omit `--project` to discover available projects** — the CLI returns a `status="pending"` envelope listing all projects visible to the AK/SK (with endpoint/region pre-computed). Pick a project from the list (ask the user if ambiguous), then re-run with `--project <id>`. Skip this when the user already knows the target project.
59
60
 
60
61
  ## First Pass
61
62
 
@@ -124,11 +125,10 @@ Use `--project` to read metadata from the production project without switching s
124
125
  {{cli}} data sample my_table --project my_project --json
125
126
  ```
126
127
 
127
- When writing SQL, use `project.table` format to reference tables in another project:
128
+ When querying production data from a dev project, use a fully qualified table name in SQL and pass the dev project explicitly:
128
129
 
129
- ```sql
130
- -- From dev project, query a production table
131
- SELECT * FROM my_project.my_table WHERE ds = '20260418' LIMIT 100
130
+ ```bash
131
+ {{cli}} query "SELECT * FROM my_production_project.my_table WHERE ds = '20260418' LIMIT 100" --project my_dev_project
132
132
  ```
133
133
 
134
134
  Do NOT use bare table names (`FROM my_table`) when the target table lives in a different project — the query will fail with `TABLE_NOT_FOUND`.
@@ -209,6 +209,7 @@ For full command syntax and options, see [references/command-patterns.md](refere
209
209
  | Check who I am and where I'm pointed | `{{cli}} auth whoami --json` |
210
210
  | Set up auth from scratch | See Bootstrap Flow above |
211
211
  | Switch project/schema for this session | `{{cli}} session set --project P --schema S --json` |
212
+ | Re-select project (list available projects) | `{{cli}} auth login --reselect --json` → pick from `data.projects` → re-run with `--project` |
212
213
  | List tables | `{{cli}} meta list-tables --schema S --json` |
213
214
  | Get full schema of a table | `{{cli}} meta describe T --json` |
214
215
  | Find tables by keyword | `{{cli}} meta search KW --json` |
@@ -76,16 +76,13 @@ Then follow the matching section below.
76
76
 
77
77
  If `auth whoami` shows `auth_type=external` (or the saved config has `provider: external`), the user is on an externally-managed credential provider set up by another tool. **Do not run Step 2 or write a new auth block.** Treat the auth as already valid. Only `project`/`endpoint`/`schema` may be changed — via `{{cli}} session set ...` or by re-running `auth login-external` with the *same* `--process-command` and the new project/endpoint values.
78
78
 
79
- ### Always ask for project and endpoint
79
+ ### Project and endpoint selection
80
80
 
81
- **Regardless of auth method, always ask the user for `project` and `endpoint` explicitly.** Do not silently reuse values from an existing config file or environment variables.
81
+ **Path A (AK/SK):** omit `--project` the CLI queries the Catalog API and returns a `status="pending"` envelope listing all projects visible to the AK/SK, with endpoint/region pre-computed per project. Pick one from the list (ask the user if ambiguous), then re-run with `--project <id>` to complete login.
82
82
 
83
- If a current value is visible in the config or env, present it as a default optionbut the user must confirm or change it:
83
+ **Path B (env vars):** `--from-env` reads `MAXCOMPUTE_PROJECT` and `MAXCOMPUTE_ENDPOINT` from the shell environment. If either is missing, the command fails with a clear errorask the user to set them.
84
84
 
85
- > "Which MaxCompute project would you like to use? (current config shows: `<existing_project>`)"
86
- > "Which endpoint? (current config shows: `<existing_endpoint>`)"
87
-
88
- Never assume the existing project/endpoint is still correct.
85
+ **Explicit override:** if the user already knows the target project, pass `--project` and `--endpoint` directly to skip project discovery.
89
86
 
90
87
  ---
91
88
 
@@ -97,23 +94,33 @@ Use when the user has a long-lived AK/SK pair.
97
94
 
98
95
  - `access_key_id`
99
96
  - `access_key_secret`
100
- - `project` (MaxCompute project name)
101
- - `endpoint` (e.g. `http://service.cn-shanghai.maxcompute.aliyun.com/api`)
102
- - `region` (optional, e.g. `cn-shanghai`)
103
97
 
104
- ### Login command
98
+ The Catalog API provides `project`, `endpoint`, `region`, and `tunnel_endpoint` automatically. Only ask the user for these if they pass `--no-picker` or already know the target project.
99
+
100
+ ### Login command — Step 1: discover projects (recommended)
105
101
 
106
102
  ```bash
107
103
  {{cli}} auth login \
108
104
  --access-id "<access_key_id>" \
109
105
  --secret-access-key "<access_key_secret>" \
110
- --project "<project>" \
111
- --endpoint "<endpoint>" \
112
- --region "<region>" \
113
106
  --json
114
107
  ```
115
108
 
116
- Add `--no-validate` to save config without a remote identity check:
109
+ Returns `status="pending"` with `data.projects` a list of `{project_id, region, endpoint, owner, schema_enabled, description}`. Pick a project from the list and proceed to Step 2.
110
+
111
+ ### Login command — Step 2: complete login
112
+
113
+ ```bash
114
+ {{cli}} auth login \
115
+ --access-id "<access_key_id>" \
116
+ --secret-access-key "<access_key_secret>" \
117
+ --project "<project_id>" \
118
+ --json
119
+ ```
120
+
121
+ Returns `status="success"` with the configured identity. Endpoint/region are auto-derived from the project when omitted.
122
+
123
+ ### Login command (explicit — when user knows the target)
117
124
 
118
125
  ```bash
119
126
  {{cli}} auth login \
@@ -121,10 +128,23 @@ Add `--no-validate` to save config without a remote identity check:
121
128
  --secret-access-key "<access_key_secret>" \
122
129
  --project "<project>" \
123
130
  --endpoint "<endpoint>" \
124
- --no-validate \
131
+ --region "<region>" \
125
132
  --json
126
133
  ```
127
134
 
135
+ Add `--no-validate` to either form to save config without a remote identity check.
136
+
137
+ ### Picker flags
138
+
139
+ | Flag | Effect |
140
+ |------|--------|
141
+ | (omit `--project`) | Return pending envelope with project list from Catalog API (non-TTY) or interactive picker (TTY) |
142
+ | `--no-picker` | Disable project discovery; fall back to manual prompt for project/endpoint (CI escape hatch) |
143
+ | `--reselect` | Force project discovery even when a project is already saved in config (no effect with `--project` or `--no-picker`) |
144
+ | `--catalog-endpoint <url>` | Override the Catalog API URL (for non-China regions where auto-routing is unavailable) |
145
+
146
+ Fallback: if the Catalog API call fails (network, permissions, etc.), the CLI falls back to a manual prompt (TTY) or returns project=None (non-TTY).
147
+
128
148
  ### What it saves
129
149
 
130
150
  ```yaml
@@ -51,9 +51,11 @@ Then jump to the matching path in [bootstrap-auth.md](bootstrap-auth.md):
51
51
 
52
52
  If `auth whoami --json` shows `auth_type=external` (or `provider: external` in the saved config), the user is on an externally-managed credential provider. **Do not run Phase 2.** The auth is already set up — only `project`/`endpoint`/`schema` are safe to change via `session set` or by re-running the original `auth login-external` with updated `--project`/`--endpoint`. Treat bootstrap as complete and move to Phase 3.
53
53
 
54
- ### Always confirm project and endpoint
54
+ ### Project and endpoint
55
55
 
56
- Regardless of method, ask the user explicitly for `project` and `endpoint`. If a value is already in the config or env, present it as a default but require confirmation. See [bootstrap-auth.md](bootstrap-auth.md) §"Always ask for project and endpoint".
56
+ **Path A (AK/SK):** do NOT ask for project or endpoint upfront. Omit `--project` from `auth login` — the CLI returns a `pending` envelope listing available projects with pre-computed endpoints. Pick one (ask the user if ambiguous), then re-run with `--project <id>`. See [bootstrap-auth.md](bootstrap-auth.md) §"Project and endpoint selection".
57
+
58
+ **Path B (env vars):** `--from-env` reads project and endpoint from the shell. If either is missing, ask the user to export them before re-running.
57
59
 
58
60
  ### Dev vs production project check
59
61
 
@@ -140,7 +140,7 @@ Async pattern for long queries:
140
140
 
141
141
  ```bash
142
142
  # Step 1: submit
143
- {{cli}} query "SELECT * FROM my_schema.big_table WHERE ds = '20260418'" --wait 0 --json
143
+ {{cli}} query "SELECT * FROM my_production_project.my_table WHERE ds = '20260418'" --project my_dev_project --wait 0 --json
144
144
  # Returns: { "status": "pending", "metadata": { "job_id": "<job_id>" } }
145
145
 
146
146
  # Step 2: extract metadata.job_id (e.g. 2026042011_abc123) and wait
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxc-cli
3
- Version: 0.4.5
3
+ Version: 0.4.7
4
4
  Summary: Agent-native MaxCompute CLI for external coding agents
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.9
@@ -61,7 +61,7 @@ maxc query "SELECT * FROM schema.table WHERE ds='20260415'" --json
61
61
  | **cache** | `build`, `build-status`, `status`, `clear` | 元数据缓存管理 |
62
62
  | **agent** | `context`, `skill install`, `skill list` | Agent 集成与 SKILL 安装 |
63
63
 
64
- 所有命令支持 `--json` 输出 Envelope v2.0 结构化响应。支持 `--format json|markdown|brief`(全局标志)。
64
+ 所有命令支持 `--json` 输出 Envelope v2.0 结构化响应。对 Agent 而言,应始终使用 `--json`。
65
65
 
66
66
  ## Agent 集成
67
67
 
@@ -128,12 +128,10 @@ maxc agent skill --json # SKILL.md 路径与 min_cli_version
128
128
 
129
129
  ### 输出格式
130
130
 
131
- `--format` 是全局标志,适用于所有命令:
131
+ 对 Agent,统一使用 `--json`:
132
132
 
133
133
  ```bash
134
- maxc --format json meta describe my_table # 结构化 JSON(默认,等价于 --json
135
- maxc --format markdown meta describe my_table # 人类可读 markdown
136
- maxc --format brief meta describe my_table # 最小化单行输出(低 token 场景)
134
+ maxc meta describe my_table --json
137
135
  ```
138
136
 
139
137
  ### safety 块
@@ -194,7 +194,13 @@ class _StubMetaBackend:
194
194
  return tables[:limit], len(tables) > limit
195
195
  return tables, False
196
196
 
197
- def describe_table(self, table_name: 'str', *, project: 'str | None' = None) -> 'TableDefinition':
197
+ def describe_table(
198
+ self,
199
+ table_name: 'str',
200
+ *,
201
+ project: 'str | None' = None,
202
+ schema: 'str | None' = None,
203
+ ) -> 'TableDefinition':
198
204
  time.sleep(0.01)
199
205
  return _table(table_name)
200
206
 
@@ -134,7 +134,7 @@ class _UploadHarness:
134
134
  def describe_table(self, *args, **kwargs) -> TableDefinition:
135
135
  return self._definition
136
136
 
137
- def _table_tunnel(self) -> _FakeTunnel:
137
+ def _table_tunnel(self, project: 'str | None' = None) -> _FakeTunnel:
138
138
  return self._tunnel
139
139
 
140
140
  def upload(self, *args, **kwargs):