cli-agent-runner 0.1.0__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.
@@ -0,0 +1,222 @@
1
+ """Git operations — ONLY module that calls git CLI.
2
+
3
+ Stash safety rules (R820 + §9 IMMUTABLE):
4
+ - API is SHA-locked: callers pass and store SHA only, never stash@{N} index.
5
+ Internal drop/pop translate SHA -> current selector immediately before each
6
+ git call. Safe against caller-side index drift; single-supervisor-per-repo
7
+ design means external concurrent ``git stash push`` is not a defended scenario.
8
+ - "Auto-tool change vs human change" detection uses set-based diff vs HEAD,
9
+ not unified-diff +/-line parsing (R2110 lesson).
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import subprocess # noqa: TID251 — vcs_state.py is the only sanctioned git CLI caller
15
+ import time
16
+ from dataclasses import dataclass
17
+ from pathlib import Path
18
+
19
+
20
+ @dataclass(frozen=True)
21
+ class StashRef:
22
+ sha: str # full commit SHA — IMMUTABLE under concurrent stash
23
+ message: str # human-readable label set at creation
24
+
25
+
26
+ def _git(repo: Path, *args: str, timeout: int = 10) -> subprocess.CompletedProcess[str]:
27
+ """Single sanctioned wrapper for git CLI invocations.
28
+
29
+ Centralises cwd / capture / text / timeout so individual call sites stay
30
+ one-liners and the noqa pragma lives in exactly one place.
31
+ """
32
+ return subprocess.run(
33
+ ["git", *args],
34
+ cwd=repo,
35
+ capture_output=True,
36
+ text=True,
37
+ timeout=timeout,
38
+ )
39
+
40
+
41
+ def is_git_repo(path: Path) -> bool:
42
+ if not path.is_dir():
43
+ return False
44
+ r = _git(path, "rev-parse", "--is-inside-work-tree")
45
+ return r.returncode == 0 and r.stdout.strip() == "true"
46
+
47
+
48
+ def detect_dirty_files(repo: Path) -> list[str]:
49
+ """Return list of files with any uncommitted change (modified / untracked / renamed).
50
+
51
+ Uses ``git status --porcelain -z`` (NUL-separated, rename pairs split into
52
+ two records). Returns the new-path side of any rename; old paths are skipped.
53
+ """
54
+ r = _git(repo, "status", "--porcelain", "-z")
55
+ if r.returncode != 0:
56
+ return []
57
+ out: list[str] = []
58
+ records = r.stdout.split("\x00")
59
+ i = 0
60
+ while i < len(records):
61
+ rec = records[i]
62
+ if not rec:
63
+ i += 1
64
+ continue
65
+ if len(rec) < 3:
66
+ i += 1
67
+ continue
68
+ status = rec[:2]
69
+ path = rec[3:]
70
+ # Renames in -z form emit two records: "R new_path" then "old_path".
71
+ if status[0] == "R" or status[1] == "R":
72
+ out.append(path)
73
+ i += 2 # skip the old_path follow-up record
74
+ else:
75
+ out.append(path)
76
+ i += 1
77
+ return out
78
+
79
+
80
+ def set_diff_vs_head(repo: Path, path: Path) -> set[str]:
81
+ """Lines present in working-tree path but absent from HEAD:path.
82
+
83
+ Uses set comparison, NOT unified-diff +/-line parsing. R2110 lesson:
84
+ git's diff aligner emits cosmetic +/- markers when sections move, so
85
+ +/-line scanning produces both false positives (mis-classifies real
86
+ edits as automated) and false negatives (mis-classifies repeated
87
+ headings as user edits). Set comparison ignores all alignment noise.
88
+
89
+ :param path: file path relative to ``repo`` root (joined as ``repo / path``).
90
+ """
91
+ head = _git(repo, "show", f"HEAD:{path}")
92
+ if head.returncode != 0:
93
+ return set()
94
+ try:
95
+ wt_text = (repo / path).read_text(encoding="utf-8")
96
+ except FileNotFoundError:
97
+ return set()
98
+ head_lines = set(head.stdout.splitlines())
99
+ wt_lines = set(wt_text.splitlines())
100
+ return wt_lines - head_lines
101
+
102
+
103
+ def _parse_stash_line(line: str) -> tuple[str, int, str] | None:
104
+ """Parse a ``git stash list --format=%H %ct %s`` line into (sha, ct, msg).
105
+
106
+ Strips the ``On <branch>: `` / ``WIP on <branch>: `` prefix from the
107
+ subject so msg is the original message supplied at stash time.
108
+ """
109
+ parts = line.split(" ", 2)
110
+ if len(parts) != 3:
111
+ return None
112
+ sha, ct_s, raw_subj = parts
113
+ try:
114
+ ct = int(ct_s)
115
+ except ValueError:
116
+ return None
117
+ msg = raw_subj.split(": ", 1)[1] if ": " in raw_subj else raw_subj
118
+ return sha, ct, msg
119
+
120
+
121
+ def list_recent_stashes(repo: Path, limit: int | None = None) -> list[StashRef]:
122
+ args = ["stash", "list", "--format=%H %ct %s"]
123
+ if limit is not None:
124
+ args.insert(2, f"-{limit}")
125
+ r = _git(repo, *args)
126
+ if r.returncode != 0:
127
+ return []
128
+ out: list[StashRef] = []
129
+ for line in r.stdout.strip().splitlines():
130
+ parsed = _parse_stash_line(line)
131
+ if parsed is None:
132
+ continue
133
+ sha, _ct, msg = parsed
134
+ out.append(StashRef(sha=sha, message=msg))
135
+ return out
136
+
137
+
138
+ def _recent_orphan_for_round(repo: Path, round_num: int, window_s: int) -> StashRef | None:
139
+ # Only the top stash matters for idempotency; -1 caps git's work as the
140
+ # reflog grows over the project's lifetime.
141
+ r = _git(repo, "stash", "list", "-1", "--format=%H %ct %s")
142
+ if r.returncode != 0 or not r.stdout.strip():
143
+ return None
144
+ parsed = _parse_stash_line(r.stdout.strip().splitlines()[0])
145
+ if parsed is None:
146
+ return None
147
+ sha, ct, msg = parsed
148
+ if not msg.startswith(f"ORPHAN R{round_num}"):
149
+ return None
150
+ if (time.time() - ct) > window_s:
151
+ return None
152
+ return StashRef(sha=sha, message=msg)
153
+
154
+
155
+ def stash_orphan(
156
+ repo: Path,
157
+ *,
158
+ round_num: int,
159
+ phase: str | None,
160
+ idempotency_s: int = 5,
161
+ ) -> StashRef | None:
162
+ """Stash dirty tree as ORPHAN entry, SHA-locked.
163
+
164
+ Returns existing ref if a matching ORPHAN was created within ``idempotency_s``
165
+ (R820 lesson — same-second multiple calls would otherwise pile up duplicate
166
+ stashes). Returns None if tree is clean.
167
+ """
168
+ if not detect_dirty_files(repo):
169
+ return None
170
+ existing = _recent_orphan_for_round(repo, round_num, idempotency_s)
171
+ if existing is not None:
172
+ return existing
173
+ ts = time.strftime("%Y-%m-%dT%H:%M:%S")
174
+ phase_part = f" phase={phase}" if phase else ""
175
+ msg = f"ORPHAN R{round_num}{phase_part} ts={ts}"
176
+ push = _git(repo, "stash", "push", "-u", "-m", msg, timeout=30)
177
+ if push.returncode != 0:
178
+ return None
179
+ listing = _git(repo, "stash", "list", "-1", "--format=%H %s")
180
+ if listing.returncode != 0 or not listing.stdout.strip():
181
+ return None
182
+ sha, _, raw_subj = listing.stdout.strip().partition(" ")
183
+ if msg not in raw_subj:
184
+ return None # tree was clean — nothing to stash
185
+ return StashRef(sha=sha, message=msg)
186
+
187
+
188
+ def _resolve_stash_selector(repo: Path, sha: str) -> str | None:
189
+ """Resolve a stash commit SHA to its current reflog selector.
190
+
191
+ Looked up immediately before each operation — callers never cache the
192
+ selector (that would defeat the SHA-lock invariant under concurrent
193
+ auto-stash).
194
+ """
195
+ r = _git(repo, "stash", "list", "--format=%gd %H")
196
+ if r.returncode != 0:
197
+ return None
198
+ for line in r.stdout.splitlines():
199
+ sel, _, line_sha = line.partition(" ")
200
+ if line_sha == sha:
201
+ return sel
202
+ return None
203
+
204
+
205
+ def drop_stash(repo: Path, sha: str) -> bool:
206
+ """Drop stash by SHA — IMMUTABLE under concurrent stash (§9 lesson).
207
+
208
+ SHA is resolved to its current reflog selector at call time; callers
209
+ never persist or pass index references.
210
+ """
211
+ sel = _resolve_stash_selector(repo, sha)
212
+ if sel is None:
213
+ return False
214
+ return _git(repo, "stash", "drop", sel).returncode == 0
215
+
216
+
217
+ def pop_stash(repo: Path, sha: str) -> bool:
218
+ """Pop stash by SHA. Same SHA-lock rule as drop_stash."""
219
+ sel = _resolve_stash_selector(repo, sha)
220
+ if sel is None:
221
+ return False
222
+ return _git(repo, "stash", "pop", sel).returncode == 0
@@ -0,0 +1,150 @@
1
+ Metadata-Version: 2.4
2
+ Name: cli-agent-runner
3
+ Version: 0.1.0
4
+ Summary: Restart-on-exit supervisor for autonomous CLI agents
5
+ Project-URL: Homepage, https://github.com/wan9yu/agent-runner
6
+ Project-URL: Documentation, https://github.com/wan9yu/agent-runner#readme
7
+ Project-URL: Repository, https://github.com/wan9yu/agent-runner
8
+ Project-URL: Issues, https://github.com/wan9yu/agent-runner/issues
9
+ Project-URL: Changelog, https://github.com/wan9yu/agent-runner/blob/main/CHANGELOG.md
10
+ Author-email: wangyu <wangyu@go2imagination.com>
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: agent,autonomous,claude,monitoring,restart,supervisor,systemd,watchdog
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: System Administrators
17
+ Classifier: Operating System :: MacOS
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Build Tools
24
+ Classifier: Topic :: System :: Monitoring
25
+ Classifier: Topic :: Utilities
26
+ Requires-Python: >=3.11
27
+ Requires-Dist: psutil>=5.9
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest-cov>=5; extra == 'dev'
30
+ Requires-Dist: pytest>=8; extra == 'dev'
31
+ Requires-Dist: ruff>=0.5; extra == 'dev'
32
+ Requires-Dist: vulture>=2.13; extra == 'dev'
33
+ Provides-Extra: e2e
34
+ Requires-Dist: fabric>=3; extra == 'e2e'
35
+ Requires-Dist: pytest>=8; extra == 'e2e'
36
+ Description-Content-Type: text/markdown
37
+
38
+ > **[中文](README.zh.md)** · English
39
+
40
+ [![CI](https://github.com/wan9yu/agent-runner/actions/workflows/ci.yml/badge.svg)](https://github.com/wan9yu/agent-runner/actions/workflows/ci.yml) [![PyPI](https://img.shields.io/pypi/v/cli-agent-runner.svg)](https://pypi.org/project/cli-agent-runner/) [![Python](https://img.shields.io/pypi/pyversions/cli-agent-runner.svg)](https://pypi.org/project/cli-agent-runner/) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![codecov](https://codecov.io/gh/wan9yu/agent-runner/branch/main/graph/badge.svg)](https://codecov.io/gh/wan9yu/agent-runner) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
41
+
42
+ # agent-runner
43
+
44
+ A restart-on-exit supervisor for autonomous CLI agents. Spawn an agent (Claude
45
+ Code, a custom CLI, anything) round-after-round under defenses that prevent
46
+ the failure modes that bite in production: stuck rounds, orphan commits,
47
+ OAuth burn loops, full disks, runaway memory.
48
+
49
+ ```
50
+ ┌──────────────────────────────────────────┐
51
+ │ Layer 3: The Witness (monitor) │ 9 detectors + auto-stop
52
+ ├──────────────────────────────────────────┤
53
+ │ Layer 2: The Loop (serve, ~60 LOC) │ signal-trapping restart loop
54
+ ├──────────────────────────────────────────┤
55
+ │ Layer 1: The Round (round) │ one agent invocation
56
+ └──────────────────────────────────────────┘
57
+ ```
58
+
59
+ ## Quick start
60
+
61
+ ```bash
62
+ git clone https://github.com/wan9yu/agent-runner.git
63
+ cd agent-runner
64
+ python3 -m venv .venv && source .venv/bin/activate
65
+ pip install -e ".[dev]"
66
+
67
+ # In your project directory:
68
+ agent-runner init # scaffold agent-runner.toml + prompts/main.md
69
+ $EDITOR agent-runner.toml # point agent.command at your CLI
70
+ agent-runner install --monitor # systemd user units for serve + monitor
71
+ agent-runner status # confirm running
72
+ agent-runner peek # snapshot of project state
73
+ agent-runner monitor # live anomaly detection
74
+ ```
75
+
76
+ Full walkthrough: [`docs/quickstart.md`](docs/quickstart.md).
77
+
78
+ ## 13 verbs
79
+
80
+ | Lifecycle | Observation |
81
+ |---|---|
82
+ | `init` / `install` / `uninstall` | `peek` — state snapshot |
83
+ | `start` / `stop` / `kill` / `cancel` | `watch` — peek in a refresh loop |
84
+ | `restart` / `status` | `monitor` — 9 detectors, alerts, auto-stop |
85
+ | `round` / `serve` | |
86
+
87
+ Verb reference: [`docs/commands.md`](docs/commands.md).
88
+
89
+ ## Defenses (built in)
90
+
91
+ 11 named defenses, structured as data — see `agent-runner peek --select defenses`.
92
+ Each carries the historical incident it codifies and the invariant test that
93
+ guards it. Highlights:
94
+
95
+ - **round_timeout_s** — hard wall, never the agent's word on when to stop
96
+ - **process_group_isolation** — kill the round, not just the parent
97
+ - **orphan_stash_idempotency_s** — no 3-stashes-per-second pile-ups
98
+ - **sha_locked_stash** — `stash@{N}` indices drift; SHAs don't
99
+ - **set_diff_classification** — line-set comparison, not unified-diff +/- scan
100
+ - **startup_smoke_check** — refuse to run with a clearly-truncated prompt
101
+
102
+ Full list and rationale: [`docs/architecture.md`](docs/architecture.md).
103
+
104
+ ## Monitor: 9 detectors
105
+
106
+ Notify only: `timeout_rate`, `hung`, `orphan_chain`, `disk_warning`,
107
+ `mem_pressure`, `smoke_fail_rate`, `network_fail`.
108
+
109
+ **Auto-stop the service** (continuing is harmful):
110
+ - `oauth_fail` — burning API quota on auth-rejected rounds
111
+ - `disk_critical` — writing to a near-full disk risks corruption
112
+
113
+ Runs locally or against a remote host via ssh:
114
+
115
+ ```bash
116
+ agent-runner monitor # local, 30s poll
117
+ agent-runner monitor --host pi # remote, 60s poll
118
+ agent-runner monitor --json | jq -c # pipe to downstream consumers
119
+ ```
120
+
121
+ ## Documentation
122
+
123
+ - [`docs/quickstart.md`](docs/quickstart.md) — 5-step install + first round
124
+ - [`docs/commands.md`](docs/commands.md) — verb reference
125
+ - [`docs/configuration.md`](docs/configuration.md) — `agent-runner.toml` schema
126
+ - [`docs/runbook.md`](docs/runbook.md) — operator troubleshooting (OAuth, disk, orphan)
127
+ - [`docs/architecture.md`](docs/architecture.md) — 3-layer model, defenses-as-data
128
+
129
+ ## Status
130
+
131
+ Phase 2 (operator surface) shipped. Phase 3 (LLM-augmented Critic) reserved —
132
+ `[llm]` config block and `agent_runner.critic` Protocol stubs are in place,
133
+ implementation TBD.
134
+
135
+ ## Development
136
+
137
+ ```bash
138
+ pytest -q --ignore=tests/e2e # 207 unit + integration tests
139
+ AGENT_RUNNER_E2E_PI=1 pytest tests/e2e/ # opt-in pi e2e (needs ssh alias `pi`)
140
+ ruff check . && ruff format --check .
141
+ ```
142
+
143
+ Some `docs/*.md` blocks are generated from code — `./build.sh docs` rewrites
144
+ the `<!-- gen:* -->` regions, and `./build.sh check` verifies they are fresh.
145
+
146
+ POSIX-only (Linux, macOS). Tested under Python 3.11+ on x86_64 and aarch64.
147
+
148
+ ## License
149
+
150
+ [Apache License 2.0](LICENSE).
@@ -0,0 +1,36 @@
1
+ agent_runner/__init__.py,sha256=Zu0E_xDKenEBWcXkqBcRbsL2jzZhxq7V6yJvmUum_Ck,100
2
+ agent_runner/_docgen.py,sha256=4oxlD9rnxIMP5jisTnPvTUNwGI9sknL7oK761xOF_kI,6620
3
+ agent_runner/_version.py,sha256=n_5vdJsPNu7wZ57LGuRL585uvll-hiuvZUBWzdG0RQU,520
4
+ agent_runner/agent_runtime.py,sha256=6D-i75vs5XgEJgA8vo2JHip5RmzOW9EotGuw7XZXaIY,3989
5
+ agent_runner/api.py,sha256=qZoLoJynoAft3QQWD2lKNYLtVkQgok6k7YvfgsErQPk,11404
6
+ agent_runner/api_types.py,sha256=BHQtZ5dUGuh3iMzzwm5E12BLfo5Mj32qpNmXa-OBfJU,2706
7
+ agent_runner/config.py,sha256=UXP7xYqD-Jd8GlP1IDUE-ZQBmvjLjA3BgTjGM5cbjSA,2669
8
+ agent_runner/context_store.py,sha256=XDmru8DDJnh4xdanI0QsMfX3RBhWI0BB1EDRAezfCn4,3290
9
+ agent_runner/critic.py,sha256=yQ1jPjhPwyGzDqPAQZWkKMfEIOnVMvsLuRG4KiiByOs,1060
10
+ agent_runner/defenses.py,sha256=v0KTwEfH9sKxpEqqzVxSkq36JpSB41VlS7gsdQwqDV8,4086
11
+ agent_runner/events.py,sha256=jAUblB9cl89os1ywgqqMmDEI5FnG5K9zXdJksShgkz4,1746
12
+ agent_runner/lifecycle.py,sha256=UWEWevWAa7NSqOmcs5Fah5AadjYtTQ7Qf8Ftvr7agm0,1966
13
+ agent_runner/metrics.py,sha256=bo-HXQlcP2FJNjmkU_NO3d9-8VkS7sgU9TduU72niYg,2075
14
+ agent_runner/monitor.py,sha256=EI0zflPA1XQoPUpcswkvgv8Ts16VIHij7dYh4D0Gjso,16534
15
+ agent_runner/prompt_loader.py,sha256=vWE9eHKDACKJ9zegZyqHqEpzihvAnyCCl0IzINm8Jbw,1274
16
+ agent_runner/round_view.py,sha256=6BNKCPltNSf5c-rur-QZdkYslREuc6eOGnUS44x_Pic,2650
17
+ agent_runner/runner.py,sha256=V5XXUrg_r5HFLf6lohZiB0hjDBkotJmv39MSIkKuHvs,7213
18
+ agent_runner/scaffold.py,sha256=Uh3SpXe0ubbzLcF9mpJFSCNEL-BczUZ5QK2Vw8crqO8,4086
19
+ agent_runner/service_unit.py,sha256=rex-le5UJ6Ocb_lxmOxXCs4Vas6PE49-UDMevBAEc1k,2280
20
+ agent_runner/startup_check.py,sha256=NRDgMRzt3llJrfxhEkOqiNptx1IowpKFfvbvljDty04,4463
21
+ agent_runner/vcs_state.py,sha256=20SUSMdHqaMbGc7yct0SMK3NJKXiHUsk7lR4Rd5sqRA,7629
22
+ agent_runner/cli/__init__.py,sha256=cG0pkToPTRsrHeZNi4eXm5t4EZs0ChSW3RdzIlhu_54,2387
23
+ agent_runner/cli/__main__.py,sha256=AF49Fl2Z40swQWYK1VLECBeUyr7LeIMiGjalPq5UZho,60
24
+ agent_runner/cli/common.py,sha256=oBNL5nxtS7NgKWLmP6QZ7CpCnvpDCr9PdM4OfX4CLXE,2416
25
+ agent_runner/cli/init_cmd.py,sha256=64iYxwREzqNBein52VqXMY1bLcoE5_lHOWczxdBaSKs,1022
26
+ agent_runner/cli/install_cmd.py,sha256=z76HsjkXvW0S7N143hEX_LmlNBEZTwMXpool2m9dfc0,1305
27
+ agent_runner/cli/monitor_cmd.py,sha256=Gh6N8jSvU9NdrVqVXz6EdSBLeZbdFkJodOZD7c9oEAw,1461
28
+ agent_runner/cli/peek_cmd.py,sha256=V7Vvyeb9KmE4epHOHaqVS9sxEXiytIgawLxmhgw2T2c,2267
29
+ agent_runner/cli/round_cmd.py,sha256=KthrZSSD0EkRkCy3Z710qXujA0WxtWYOhVxJ6ycUyPw,454
30
+ agent_runner/cli/serve_cmd.py,sha256=me4N2-5bYeTYJtc14bOgISBam6k-_b80VCBve1g_YKE,1830
31
+ agent_runner/cli/service_cmd.py,sha256=qC9Id_Sp_n3UpIWcOKPV9MrsKziUKuppmcacTNFp9e4,1705
32
+ cli_agent_runner-0.1.0.dist-info/METADATA,sha256=F8tQYKgGLLj1KPtMGCsQZ2pljEy1C4yuVFr8I5PKtKE,6868
33
+ cli_agent_runner-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
34
+ cli_agent_runner-0.1.0.dist-info/entry_points.txt,sha256=X9UcyfdMVqei65HVDSBYO1R-M650ZZnIxJllqxHUd-o,55
35
+ cli_agent_runner-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
36
+ cli_agent_runner-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ agent-runner = agent_runner.cli:main
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.