uni-diff-patch 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl

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.
uni_diff_patch/cli.py CHANGED
@@ -46,11 +46,17 @@ def main() -> None:
46
46
  is_flag=True,
47
47
  help="Overwrite existing output file.",
48
48
  )
49
+ @click.option(
50
+ "--no-append",
51
+ is_flag=True,
52
+ help="Disable append mode (default appends to existing file).",
53
+ )
49
54
  def generate(
50
55
  spec_source: str,
51
56
  output_override: str | None,
52
57
  work_dir: str | None,
53
58
  overwrite: bool,
59
+ no_append: bool,
54
60
  ) -> None:
55
61
  """Generate a unified diff patch from a JSON spec.
56
62
 
@@ -91,6 +97,7 @@ def generate(
91
97
  output_path=final_output,
92
98
  work_dir=work_dir,
93
99
  overwrite=overwrite,
100
+ append=not no_append,
94
101
  )
95
102
  except (DiffGenerationError, SearchReplaceError) as e:
96
103
  raise click.ClickException(str(e))
@@ -315,6 +315,7 @@ def generate_patch(
315
315
  work_dir: str | None = None,
316
316
  self_validate: bool = True,
317
317
  overwrite: bool = False,
318
+ append: bool = True,
318
319
  ) -> GenerateResult:
319
320
  """Generate a unified diff patch from one or more file changes.
320
321
 
@@ -325,6 +326,8 @@ def generate_patch(
325
326
  Defaults to current working directory.
326
327
  self_validate: If True, validate the generated patch with mpatch.parse_auto.
327
328
  overwrite: If True, overwrite existing output files. Default False.
329
+ append: If True, append to existing output file instead of overwriting.
330
+ Useful for incremental patch generation (e.g. Codex workflow).
328
331
 
329
332
  Returns:
330
333
  GenerateResult with the patch string and metadata.
@@ -391,12 +394,18 @@ def generate_patch(
391
394
 
392
395
  if output_path is not None:
393
396
  out = Path(output_path)
394
- if out.exists() and not overwrite:
397
+ out.parent.mkdir(parents=True, exist_ok=True)
398
+ if append and out.exists():
399
+ # 追加模式:在已有 diff 后追加新内容
400
+ existing = out.read_text(encoding="utf-8")
401
+ separator = "\n" if existing and not existing.endswith("\n") else ""
402
+ out.write_text(existing + separator + combined, encoding="utf-8")
403
+ elif out.exists() and not overwrite:
395
404
  raise DiffGenerationError(
396
405
  f"Output file already exists: {output_path}. "
397
- f"Use overwrite=True to replace."
406
+ f"Use overwrite=True to replace, or append=True to append."
398
407
  )
399
- out.parent.mkdir(parents=True, exist_ok=True)
400
- out.write_text(combined, encoding="utf-8")
408
+ else:
409
+ out.write_text(combined, encoding="utf-8")
401
410
 
402
411
  return result
uni_diff_patch/server.py CHANGED
@@ -62,6 +62,7 @@ def generate_patch_tool(
62
62
  output_path: str | None = None,
63
63
  work_dir: str | None = None,
64
64
  overwrite: bool = False,
65
+ append: bool = True,
65
66
  ) -> dict:
66
67
  """Generate a valid unified diff patch from structured file changes.
67
68
 
@@ -73,6 +74,8 @@ def generate_patch_tool(
73
74
  output_path: Optional file path to write the patch to.
74
75
  work_dir: Base directory for relativizing absolute paths in diff headers.
75
76
  overwrite: If true, overwrite existing output file. Default false.
77
+ append: If true (default), append to existing output file.
78
+ Set to false to require a fresh file.
76
79
 
77
80
  Returns:
78
81
  Dict with patch, files_changed, self_valid, skipped_files, or error.
@@ -83,6 +86,7 @@ def generate_patch_tool(
83
86
  output_path=output_path,
84
87
  work_dir=work_dir,
85
88
  overwrite=overwrite,
89
+ append=append,
86
90
  )
87
91
  return {
88
92
  "patch": result.patch,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: uni-diff-patch
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: MCP server and CLI tool for generating valid unified diff patches deterministically
5
5
  Author: LimLLL
6
6
  Author-email: LimLLL <github@awebapp.useforall.com>
@@ -1,13 +1,13 @@
1
1
  uni_diff_patch/__init__.py,sha256=QZHH9fShZy0Uae-0TF-6HN35C_3nCbGHcYE56eNy83E,1066
2
- uni_diff_patch/cli.py,sha256=XyqjzIUHsli_SGBkbFxxOL7Y02NY_Wz7x54fGgZDE9I,5109
2
+ uni_diff_patch/cli.py,sha256=IgqlrUySgehRRNbY1h-vgkXt0jiKU8zKJRyJWVWRREI,5286
3
3
  uni_diff_patch/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- uni_diff_patch/core/diff_engine.py,sha256=lARXSa8iacdLRRZlxI_H21hgwf2q9HC1PR1Ob0oddjI,13358
4
+ uni_diff_patch/core/diff_engine.py,sha256=VHSk80sqiSciWaZe8BRWkokOM8Z9Gldy2sXe69Ve5C0,13897
5
5
  uni_diff_patch/core/search_replace.py,sha256=kwUfr-SqB9oZJwXK0A3LOEmccXi_fx5SGQD_MPN83Rk,4592
6
6
  uni_diff_patch/core/validator.py,sha256=qf66MXYT3zvHsqQ3l6PlvyK5Go6_DXu89QcIIxlE5cg,6639
7
7
  uni_diff_patch/models.py,sha256=M7PcWRcUWUz0CO8MK7z5CDwYxpoN-MCmihvAq7zH9x0,6154
8
8
  uni_diff_patch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- uni_diff_patch/server.py,sha256=NAjVofdUUqL3VI3AgtCT7ky7Csf9atSenF6d3-734cM,4845
10
- uni_diff_patch-0.0.1.dist-info/WHEEL,sha256=YR4QUxGCbsyoOnWBVTv-p1I4yc3seKGPev46mvmc8Cg,81
11
- uni_diff_patch-0.0.1.dist-info/entry_points.txt,sha256=SMaBpCbADshKmWiXYPpy_PSVvKWf0KQcwNJXi_FIsoM,60
12
- uni_diff_patch-0.0.1.dist-info/METADATA,sha256=mK4hc0wOlTpdUdyfNvtxTvZJf4cRY3uQ73_7vYX-sM4,4870
13
- uni_diff_patch-0.0.1.dist-info/RECORD,,
9
+ uni_diff_patch/server.py,sha256=9mswkL4i0zfMczEtHJFd3MQKkK-SPQln2H2KyUgJ1Hw,5014
10
+ uni_diff_patch-0.0.2.dist-info/WHEEL,sha256=YR4QUxGCbsyoOnWBVTv-p1I4yc3seKGPev46mvmc8Cg,81
11
+ uni_diff_patch-0.0.2.dist-info/entry_points.txt,sha256=SMaBpCbADshKmWiXYPpy_PSVvKWf0KQcwNJXi_FIsoM,60
12
+ uni_diff_patch-0.0.2.dist-info/METADATA,sha256=j_t4J2YYyIO0xlq-efZcbH3nqZoSiPAnCoftxJR1Uzc,4870
13
+ uni_diff_patch-0.0.2.dist-info/RECORD,,